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);
}
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;
}
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;
}
Aggregations