use of core.mino.MinoFactory in project solution-finder by knewjade.
the class TetfuTest method random.
@Test
@LongTest
void random() throws Exception {
// Initialize
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
ColorConverter colorConverter = new ColorConverter();
// 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 < 20; count++) {
System.out.println(count);
// Create field
int numOfMinos = randoms.nextIntClosed(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();
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<TetfuElement> elements = operations.getOperations().stream().map(operation -> {
ColorType colorType = colorConverter.parseToColorType(operation.getPiece());
Rotate rotate = operation.getRotate();
int x = operation.getX();
int y = operation.getY();
String comment = randoms.string() + randoms.string() + randoms.string();
return new TetfuElement(colorType, rotate, x, y, comment);
}).collect(Collectors.toList());
String encode = new Tetfu(minoFactory, colorConverter).encode(elements);
List<TetfuPage> decode = decodeTetfu(minoFactory, colorConverter, encode);
assertThat(decode).hasSize(elements.size());
for (int index = 0; index < decode.size(); index++) {
TetfuElement element = elements.get(index);
assertThat(decode.get(index)).returns(element.getColorType(), TetfuPage::getColorType).returns(element.getRotate(), TetfuPage::getRotate).returns(element.getX(), TetfuPage::getX).returns(element.getY(), TetfuPage::getY).returns(element.getComment(), TetfuPage::getComment);
}
});
});
}
}
use of core.mino.MinoFactory in project solution-finder by knewjade.
the class TetfuTest method encodeQuiz2.
@Test
void encodeQuiz2() throws Exception {
List<Piece> orders = Arrays.asList(J, L);
String quiz = Tetfu.encodeForQuiz(orders, L);
List<TetfuElement> elements = Arrays.asList(new TetfuElement(ColorType.L, Rotate.Right, 0, 1, quiz), new TetfuElement(ColorType.J, Rotate.Left, 3, 1, quiz));
MinoFactory factory = new MinoFactory();
ColorConverter converter = new ColorConverter();
Tetfu tetfu = new Tetfu(factory, converter);
String encode = tetfu.encode(elements);
assertThat(encode).isEqualTo("vhBKJYVAFLDmClcJSAVTXSAVG88AYS88AZAAAA+qB");
}
use of core.mino.MinoFactory in project solution-finder by knewjade.
the class TetfuTest method encode6.
@Test
void encode6() throws Exception {
List<TetfuElement> elements = Collections.singletonList(new TetfuElement(ColorType.Empty, Rotate.Spawn, 6, 0));
MinoFactory factory = new MinoFactory();
ColorConverter converter = new ColorConverter();
Tetfu tetfu = new Tetfu(factory, converter);
String encode = tetfu.encode(elements);
assertThat(encode).isEqualTo("vhAAgH");
}
use of core.mino.MinoFactory in project solution-finder by knewjade.
the class TetfuTest method decode4.
@Test
void decode4() throws Exception {
List<TetfuElement> elements = Arrays.asList(new TetfuElement(ColorType.I, Rotate.Reverse, 5, 0, "a"), new TetfuElement(ColorType.S, Rotate.Reverse, 5, 2, "b"), new TetfuElement(ColorType.J, Rotate.Left, 9, 1, "c"), new TetfuElement(ColorType.O, Rotate.Right, 0, 1, "hello world!"), new TetfuElement(ColorType.Z, Rotate.Left, 3, 1, "こんにちは"), new TetfuElement(ColorType.L, Rotate.Right, 0, 3, "x ~= 1;"), new TetfuElement(ColorType.T, Rotate.Reverse, 7, 1));
MinoFactory factory = new MinoFactory();
ColorConverter converter = new ColorConverter();
Tetfu tetfu = new Tetfu(factory, converter);
String encode = tetfu.encode(elements);
List<TetfuPage> pages = tetfu.decode(encode);
assertThat(pages).hasSize(elements.size());
for (int index = 0; index < pages.size(); index++) {
TetfuElement element = elements.get(index);
assertThat(pages.get(index)).returns(element.getColorType(), TetfuPage::getColorType).returns(element.getRotate(), TetfuPage::getRotate).returns(element.getX(), TetfuPage::getX).returns(element.getY(), TetfuPage::getY).returns(element.getComment(), TetfuPage::getComment);
}
}
use of core.mino.MinoFactory in project solution-finder by knewjade.
the class CheckerNoHoldInvokerTest method random.
@LongTest
@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void random(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws FinderExecuteException, SyntaxException {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
for (int count = 0; count < 40; count++) {
int maxClearLine = randoms.nextInt(3, 6);
int maxDepth = randoms.nextIntClosed(3, 5);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
Field field = randoms.field(maxClearLine, maxDepth);
PatternGenerator blocksGenerator = createPiecesGenerator(maxDepth);
List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
AnalyzeTree tree = runTestCase(invoker, field, searchingPieces, maxClearLine, maxDepth);
for (Pieces pieces : searchingPieces) {
boolean check = checker.check(field, pieces.getPieces(), candidate, maxClearLine, maxDepth);
assertThat(tree.isSucceed(pieces)).isEqualTo(check);
}
}
}
Aggregations