Search in sources :

Example 11 with FullOperationWithKey

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

the class OperationWithKeyComparatorTest method compareDiffY.

@Test
void compareDiffY() 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 newY = randoms.nextInt(20);
    if (newY == y)
        newY += 1;
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, newY, 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 12 with FullOperationWithKey

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

the class AllMinoFactory method generatePiecesEachMino.

private ArrayList<SeparableMino> generatePiecesEachMino(Mino mino, ArrayList<Integer> lineIndexes, int minoHeight) {
    ArrayList<SeparableMino> 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.getMaxX(); 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 13 with FullOperationWithKey

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

the class AllSeparableMinoFactory method generatePiecesEachMino.

private ArrayList<SeparableMino> generatePiecesEachMino(Mino mino, ArrayList<Integer> lineIndexes, int minoHeight) {
    ArrayList<SeparableMino> 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)

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