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