Search in sources :

Example 1 with FullOperationWithKey

use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.

the class OperationWithKeyComparatorTest method compareDiffX.

@Test
void compareDiffX() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    int x = randoms.nextInt(10);
    int y = randoms.nextInt(20);
    long deleteKey = 0L;
    long usingKey = 1049600L;
    OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
    int newX = randoms.nextInt(10);
    if (newX == x)
        newX += 1;
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, newX, y, deleteKey, usingKey);
    // assert is not 0 & sign reversed
    OperationWithKeyComparator comparator = new OperationWithKeyComparator();
    assertThat(comparator.compare(operationWithKey1, operationWithKey2) * comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isLessThan(0);
}
Also used : Randoms(lib.Randoms) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) Mino(core.mino.Mino) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 2 with FullOperationWithKey

use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.

the class SlideXOperationWithKeyTest method get.

@Test
void get() {
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        Piece piece = randoms.block();
        Rotate rotate = randoms.rotate();
        Mino mino = new Mino(piece, rotate);
        int x = randoms.nextInt(0, 10);
        int y = randoms.nextInt(0, 10);
        long usingKey = randoms.key();
        long deleteKey = randoms.key();
        FullOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
        int slide = randoms.nextInt(4);
        SlideXOperationWithKey key = new SlideXOperationWithKey(operationWithKey, slide);
        assertThat(key).returns(x + slide, SlideXOperationWithKey::getX).returns(y, SlideXOperationWithKey::getY).returns(deleteKey, SlideXOperationWithKey::getNeedDeletedKey).returns(usingKey, SlideXOperationWithKey::getUsingKey);
    }
}
Also used : Randoms(lib.Randoms) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 3 with FullOperationWithKey

use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.

the class AbstractAllOperationFactory method generatePiecesEachMino.

private ArrayList<T> generatePiecesEachMino(Mino mino, ArrayList<Integer> lineIndexes, int minoHeight) {
    ArrayList<T> pieces = new ArrayList<>();
    // ブロックが置かれる行を選択する
    CombinationIterable<Integer> combinationIterable = new CombinationIterable<>(lineIndexes, minoHeight);
    for (List<Integer> indexes : combinationIterable) {
        // ソートする
        indexes.sort(Integer::compare);
        // 一番下の行と一番上の行を取得
        int lowerY = indexes.get(0);
        int upperY = indexes.get(indexes.size() - 1);
        // ミノに挟まれる全ての行を含むdeleteKey
        long deleteKey = KeyOperators.getMaskForKeyAboveY(lowerY) & KeyOperators.getMaskForKeyBelowY(upperY + 1);
        long usingKey = 0L;
        assert Long.bitCount(deleteKey) == upperY - lowerY + 1;
        for (Integer index : indexes) {
            long bitKey = KeyOperators.getDeleteBitKey(index);
            // ブロックのある行のフラグを取り消す
            deleteKey &= ~bitKey;
            // ブロックのある行にフラグをたてる
            usingKey |= bitKey;
        }
        assert Long.bitCount(deleteKey) + indexes.size() == upperY - lowerY + 1;
        if ((deleteKeyMask & deleteKey) == deleteKey) {
            for (int x = -mino.getMinX(); x < fieldWidth - mino.getMinX(); x++) {
                FullOperationWithKey operationWithKey = new FullOperationWithKey(mino, x, lowerY - mino.getMinY(), deleteKey, usingKey);
                pieces.add(parseOperation(operationWithKey, upperY, fieldHeight));
            }
        }
    }
    return pieces;
}
Also used : CombinationIterable(common.iterable.CombinationIterable) ArrayList(java.util.ArrayList) FullOperationWithKey(common.datastore.FullOperationWithKey)

Example 4 with FullOperationWithKey

use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.

the class OperationWithKeyInterpreter method parseToStream.

public static Stream<MinoOperationWithKey> parseToStream(String operations, MinoFactory minoFactory) {
    return Arrays.stream(operations.split(";")).map(s -> s.split(",")).map(strings -> {
        Piece piece = StringEnumTransform.toPiece(strings[0]);
        Rotate rotate = StringEnumTransform.toRotate(strings[1]);
        Mino mino = minoFactory.create(piece, rotate);
        int x = Integer.valueOf(strings[2]);
        int y = Integer.valueOf(strings[3]);
        long deleteKey = Long.valueOf(strings[4]);
        long usingKey = Long.valueOf(strings[5]);
        return new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
    });
}
Also used : OperationWithKey(common.datastore.OperationWithKey) Piece(core.mino.Piece) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) Mino(core.mino.Mino) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey)

Example 5 with FullOperationWithKey

use of common.datastore.FullOperationWithKey in project solution-finder by knewjade.

the class OperationWithKeyInterpreterTest method parseRandom.

@Test
void parseRandom() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    for (int size = 1; size < 20; size++) {
        List<OperationWithKey> operations = Stream.generate(() -> {
            Piece piece = randoms.block();
            Rotate rotate = randoms.rotate();
            int x = randoms.nextInt(10);
            int y = randoms.nextInt(4);
            long deleteKey = randoms.key();
            long usingKey = randoms.key();
            return new FullOperationWithKey(minoFactory.create(piece, rotate), x, y, deleteKey, usingKey);
        }).limit(size).collect(Collectors.toList());
        String str = OperationWithKeyInterpreter.parseToString(operations);
        List<MinoOperationWithKey> actual = OperationWithKeyInterpreter.parseToList(str, minoFactory);
        assertThat(actual).isEqualTo(operations);
    }
}
Also used : Randoms(lib.Randoms) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Rotate(core.srs.Rotate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Aggregations

FullOperationWithKey (common.datastore.FullOperationWithKey)13 Mino (core.mino.Mino)9 OperationWithKey (common.datastore.OperationWithKey)8 MinoFactory (core.mino.MinoFactory)7 Randoms (lib.Randoms)7 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)5 MinoOperationWithKey (common.datastore.MinoOperationWithKey)3 CombinationIterable (common.iterable.CombinationIterable)3 Piece (core.mino.Piece)3 Rotate (core.srs.Rotate)3 FullLimitedMino (_implements.parity_based_pack.step2.FullLimitedMino)2 Field (core.field.Field)2 MinoMask (searcher.pack.separable_mino.mask.MinoMask)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1