use of common.datastore.OperationWithKey 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);
}
}
use of common.datastore.OperationWithKey in project solution-finder by knewjade.
the class Search method search.
private void search(Field field, int depth) {
if (depth == sets.getDepth()) {
List<OperationWithKey> result = new ArrayList<>();
for (int index = 0, length = fullLimitedMinos.length; index < length; index++) {
FullLimitedMino limitedMino = fullLimitedMinos[index];
int x = xs[index];
Mino mino = limitedMino.getMino();
long deleteKey = limitedMino.getDeleteKey();
long usingKey = limitedMino.getUsingKey();
int lowerY = limitedMino.getLowerY();
OperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
result.add(withKey);
}
results.add(result);
} else {
FullLimitedMino limitedMino = sets.get(depth);
fullLimitedMinos[depth] = limitedMino;
MinoMask minoMask = limitedMino.getMinoMask();
for (int x : limitedMino.getXs()) {
xs[depth] = x;
Field mask = minoMask.getMinoMask(x);
if (field.canMerge(mask)) {
field.merge(mask);
if (perfectValidator.validate(field, maxClearLine))
search(field, depth + 1);
field.reduce(mask);
}
}
}
}
use of common.datastore.OperationWithKey in project solution-finder by knewjade.
the class BuildUpStreamTest method buildUp2.
@Test
void buildUp2() {
// Create LockedReachable
int height = 4;
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
// Create OperationWithKey List
Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
Operations operations = OperationInterpreter.parseToOperations("J,R,0,1;O,0,1,0;L,L,3,1;I,0,1,0");
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
// Create Pieces
Set<String> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).map(op -> op.stream().map(OperationWithKey::getPiece).map(Piece::name).collect(Collectors.joining())).collect(Collectors.toSet());
// Assertion
assertThat(valid).hasSize(16).doesNotContain("IJOL", "IJLO", "IOJL", "IOLJ", "ILOJ", // starts I
"ILJO").doesNotContain("OIJL", // starts OI
"OILJ").contains("OJLI", "OJIL", "JOIL", "JLIO", "LOJI", "LIOJ");
}
use of common.datastore.OperationWithKey in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compareDiffDeleteKey.
@Test
void compareDiffDeleteKey() 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);
Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
Long choose = randoms.key();
while (choose == deleteKey) choose = randoms.key();
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, choose, 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.OperationWithKey in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compare.
@Test
void compare() 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);
Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, usingKey);
OperationWithKeyComparator comparator = new OperationWithKeyComparator();
assertThat(comparator.compare(operationWithKey1, operationWithKey2)).as(operationWithKey1.toString()).isEqualTo(0);
assertThat(comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isEqualTo(0);
}
Aggregations