use of core.mino.MinoFactory in project solution-finder by knewjade.
the class OperationTransformTest method parseToOperations.
@Test
void parseToOperations() throws Exception {
Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "");
String base = "J,2,2,1;I,0,1,2;J,R,0,1;S,0,2,0";
Operations operations = OperationInterpreter.parseToOperations(base);
MinoFactory minoFactory = new MinoFactory();
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, 4);
Operations restoreOperations = OperationTransform.parseToOperations(field, operationWithKeys, 4);
assertThat(restoreOperations).isEqualTo(operations);
}
use of core.mino.MinoFactory in project solution-finder by knewjade.
the class OperationTransformTest method randomParse.
@Test
@LongTest
void randomParse() throws Exception {
// Initialize
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
// Define size
int height = 4;
int basicWidth = 3;
SizedBit sizedBit = new SizedBit(basicWidth, height);
SeparableMinos separableMinos = SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
// Create basic solutions
TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
LockedReachableThreadLocal lockedReachableThreadLocal = new LockedReachableThreadLocal(minoFactory, minoShifter, minoRotation, height);
Predicate<ColumnField> memorizedPredicate = (columnField) -> true;
OnDemandBasicSolutions basicSolutions = new OnDemandBasicSolutions(separableMinos, sizedBit, memorizedPredicate);
for (int count = 0; count < 100; count++) {
// Create field
int numOfMinos = randoms.nextInt(6, 10);
Field field = randoms.field(height, numOfMinos);
// Search
List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(basicWidth, height, field);
SolutionFilter solutionFilter = new SRSValidSolutionFilter(field, lockedReachableThreadLocal, sizedBit);
PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
Optional<Result> resultOptional = searcher.findAny();
OperationWithKeyComparator<MinoOperationWithKey> operationWithKeyComparator = new OperationWithKeyComparator<>();
ListComparator<MinoOperationWithKey> comparator = new ListComparator<>(operationWithKeyComparator);
BuildUpStream buildUpStream = new BuildUpStream(lockedReachableThreadLocal.get(), height);
// If found solution
resultOptional.ifPresent(result -> {
List<MinoOperationWithKey> list = result.getMemento().getSeparableMinoStream(basicWidth).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
Optional<List<MinoOperationWithKey>> validOption = buildUpStream.existsValidBuildPattern(field, list).findAny();
validOption.ifPresent(operationWithKeys -> {
Operations operations = OperationTransform.parseToOperations(field, operationWithKeys, height);
List<MinoOperationWithKey> actual = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
assertThat(comparator.compare(operationWithKeys, actual)).as("%s%n%s%n %s", FieldView.toString(field, height), OperationWithKeyInterpreter.parseToString(operationWithKeys), OperationWithKeyInterpreter.parseToString(actual)).isEqualTo(0);
});
});
}
}
use of core.mino.MinoFactory 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 core.mino.MinoFactory in project solution-finder by knewjade.
the class OperationWithKeyInterpreterTest method parseToOperationWithKey.
@Test
void parseToOperationWithKey() throws Exception {
String base = "J,0,1,0,0,1025;I,0,1,2,0,1048576;L,L,3,1,1048576,1073742849;J,0,1,3,0,1100585369600";
MinoFactory minoFactory = new MinoFactory();
List<MinoOperationWithKey> operationWithKeys = OperationWithKeyInterpreter.parseToList(base, minoFactory);
String line = OperationWithKeyInterpreter.parseToString(operationWithKeys);
assertThat(line).isEqualTo(base);
}
use of core.mino.MinoFactory in project solution-finder by knewjade.
the class Main3 method viewTetfu.
private static void viewTetfu(List<TetfuElement> elements) {
if (elements.isEmpty()) {
System.out.printf("<p>該当なし</p>%n");
} else {
MinoFactory minoFactory = new MinoFactory();
ColorConverter colorConverter = new ColorConverter();
int sizePerOne = 40;
int split = ((elements.size() - 1) / sizePerOne) + 1;
for (int index = 0; index < split; index++) {
int startIndex = index * sizePerOne;
int toIndex = index == split - 1 ? elements.size() : startIndex + sizePerOne;
List<TetfuElement> subList = elements.subList(startIndex, toIndex);
Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
String encode = tetfu.encode(subList);
if (split == 1)
System.out.printf("<p><a href='http://fumen.zui.jp/?v115@%s' target='_blank'>全 %d パターン</a></p>%n", encode, elements.size());
else
System.out.printf("<p><a href='http://fumen.zui.jp/?v115@%s' target='_blank'>全 %d パターン (%d/%d)</a></p>%n", encode, elements.size(), index + 1, split);
}
}
}
Aggregations