use of common.datastore.OperationWithKey in project solution-finder by knewjade.
the class OperationWithKeyComparatorTest method compareDiffUsingKey.
@Test
void compareDiffUsingKey() 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();
OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, choose);
// assert is 0
OperationWithKeyComparator<OperationWithKey> comparator = new OperationWithKeyComparator<>();
int compare1 = comparator.compare(operationWithKey1, operationWithKey2);
assertThat(compare1).as(operationWithKey1.toString()).isEqualTo(0);
int compare2 = comparator.compare(operationWithKey2, operationWithKey1);
assertThat(compare2).as(operationWithKey2.toString()).isEqualTo(0);
}
use of common.datastore.OperationWithKey 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.OperationWithKey in project solution-finder by knewjade.
the class OneFumenParser method parse.
@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
// BlockField を生成
BlockField blockField = createBlockField(operations, maxClearLine);
// パターンを表す名前 を生成
String blocksName = operations.stream().map(OperationWithKey::getPiece).map(Piece::getName).collect(Collectors.joining());
// テト譜1ページを作成
TetfuElement tetfuElement = createTetfuElement(field, blockField, blocksName, maxClearLine);
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
return tetfu.encode(Collections.singletonList(tetfuElement));
}
use of common.datastore.OperationWithKey in project solution-finder by knewjade.
the class EasyPath method buildUp.
public Set<LongPieces> buildUp(String goalFieldMarks, Field initField, int width, int height) throws ExecutionException, InterruptedException {
assert !initField.existsAbove(height);
SizedBit sizedBit = new SizedBit(width, height);
Field goalField = FieldFactory.createInverseField(goalFieldMarks);
List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, goalField);
// Create
BasicSolutions basicSolutions = createMappedBasicSolutions(sizedBit);
TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
// Assert
SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
// パフェ手順の列挙
PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
LockedReachableThreadLocal reachableThreadLocal = easyPool.getLockedReachableThreadLocal(height);
List<Result> results = searcher.toList();
return results.stream().map(Result::getMemento).map(memento -> {
return memento.getSeparableMinoStream(width).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
}).map(operations -> new BuildUpStream(reachableThreadLocal.get(), height).existsValidBuildPattern(initField, operations)).flatMap(listStream -> {
return listStream.map(operationWithKeys -> {
Stream<Piece> blocks = operationWithKeys.stream().map(OperationWithKey::getPiece);
return new LongPieces(blocks);
});
}).collect(Collectors.toSet());
}
use of common.datastore.OperationWithKey in project solution-finder by knewjade.
the class PathPairComparator method compare.
@Override
public int compare(PathPair o1, PathPair o2) {
int compareDeletedLine = Boolean.compare(o1.isDeletedLine(), o2.isDeletedLine());
if (compareDeletedLine != 0)
return compareDeletedLine;
List<OperationWithKey> operations1 = o1.getSampleOperations();
List<OperationWithKey> operations2 = o2.getSampleOperations();
int compareSize = Integer.compare(operations1.size(), operations2.size());
if (compareSize != 0)
return compareSize;
for (int index = 0; index < operations1.size(); index++) {
OperationWithKey operation1 = operations1.get(index);
OperationWithKey operation2 = operations2.get(index);
int compareBlock = operation1.getPiece().compareTo(operation2.getPiece());
if (compareBlock != 0)
return compareBlock;
int compareRotate = operation1.getRotate().compareTo(operation2.getRotate());
if (compareRotate != 0)
return compareRotate;
}
return 0;
}
Aggregations