use of core.mino.MinoShifter in project solution-finder by knewjade.
the class LimitIterationCandidateTest method testSearch1.
@Test
void testSearch1() throws Exception {
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 3);
String marks = "" + "__________" + "__________" + "____X_____";
Field field = FieldFactory.createField(marks);
Set<Action> actions = candidate.search(field, Piece.T, 4);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Spawn)).hasSize(8);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Right)).hasSize(9);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Reverse)).hasSize(8);
assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Left)).hasSize(9);
}
use of core.mino.MinoShifter in project solution-finder by knewjade.
the class LimitIterationCandidateTest method testSearch4.
@Test
void testSearch4() throws Exception {
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 4);
String marks = "" + "XXXXX__XXX" + "XXXXX___XX" + "XXXX___XXX" + "";
Field field = FieldFactory.createField(marks);
Set<Action> actions = candidate.search(field, Piece.T, 3);
assertThat(actions).hasSize(5).contains(MinimalAction.create(6, 1, Rotate.Spawn)).contains(MinimalAction.create(5, 1, Rotate.Right)).contains(MinimalAction.create(6, 1, Rotate.Right)).contains(MinimalAction.create(6, 1, Rotate.Left)).contains(MinimalAction.create(6, 1, Rotate.Reverse));
}
use of core.mino.MinoShifter in project solution-finder by knewjade.
the class LimitIterationCandidateTest method testRandomHarddrop.
@Test
void testRandomHarddrop() {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
HarddropCandidate harddropCandidate = new HarddropCandidate(minoFactory, minoShifter);
LimitIterationCandidate limitIterationCandidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 0);
for (int count = 0; count < 10000; count++) {
int randomHeight = randoms.nextIntClosed(2, 12);
int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
Field field = randoms.field(randomHeight, numOfMinos);
int clearLine = field.clearLine();
int height = randomHeight - clearLine;
Piece piece = randoms.block();
Set<Action> actions1 = harddropCandidate.search(field, piece, height);
Set<Action> actions2 = limitIterationCandidate.search(field, piece, height);
assertThat(actions2).isEqualTo(actions1);
}
}
use of core.mino.MinoShifter in project solution-finder by knewjade.
the class LockedNeighborReachableTest method createLockedNeighborReachable.
private LockedNeighborReachable createLockedNeighborReachable(Injector injector, int maxClearLine) {
MinoShifter minoShifter = injector.getInstance(MinoShifter.class);
Neighbors neighbors = injector.getInstance(Neighbors.class);
return new LockedNeighborReachable(minoShifter, neighbors, maxClearLine);
}
use of core.mino.MinoShifter 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);
}
});
});
}
}
Aggregations