use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class CheckmateNoHoldTest method testLong9.
@Test
void testLong9() throws Exception {
List<Pair<List<Piece>, Integer>> testCases = new ArrayList<Pair<List<Piece>, Integer>>() {
{
add(new Pair<>(Arrays.asList(I, S, Z, T, J, I, S, Z, S, Z), 0));
add(new Pair<>(Arrays.asList(T, S, L, I, Z, J, L, O, O, S), 5));
add(new Pair<>(Arrays.asList(L, Z, S, J, Z, Z, Z, I, T, T), 0));
add(new Pair<>(Arrays.asList(T, T, S, S, Z, Z, L, L, J, J), 5));
add(new Pair<>(Arrays.asList(O, S, O, S, Z, L, Z, L, I, I), 0));
add(new Pair<>(Arrays.asList(J, I, T, O, L, S, I, T, Z, O), 7));
add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L, L), 6));
add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L), 6));
add(new Pair<>(Arrays.asList(Z, S, T, I, O, J, L, Z, S), 1));
add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L), 6));
}
};
// Field
String marks = "" + "__________" + "X_________" + "X_________" + "XX________" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 4;
int maxDepth = 9;
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
for (Pair<List<Piece>, Integer> testCase : testCases) {
// Set test case
List<Piece> pieces = testCase.getKey();
int expectedCount = testCase.getValue();
// Execute
List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(results).as(pieces.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class CheckmateNoHoldTest method testLong10.
@Test
@LongTest
void testLong10() throws Exception {
List<Pair<List<Piece>, Integer>> testCases = new ArrayList<Pair<List<Piece>, Integer>>() {
{
add(new Pair<>(Arrays.asList(I, S, Z, T, J, I, S, Z, S, Z, T), 3));
add(new Pair<>(Arrays.asList(S, Z, T, L, J, I, O, S, Z, T, L), 6));
add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L, I), 21));
add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L, T), 21));
add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L), 21));
add(new Pair<>(Arrays.asList(I, S, Z, T, J, I, S, Z, S, Z), 3));
add(new Pair<>(Arrays.asList(T, S, L, I, Z, J, L, O, O, S), 2));
add(new Pair<>(Arrays.asList(L, Z, S, J, Z, Z, Z, I, T, T), 7));
add(new Pair<>(Arrays.asList(T, T, S, S, Z, Z, L, L, J, J), 18));
add(new Pair<>(Arrays.asList(O, S, O, S, Z, L, Z, L, I, I), 4));
add(new Pair<>(Arrays.asList(J, I, T, O, L, S, I, T, Z, O), 9));
add(new Pair<>(Arrays.asList(S, T, J, L, O, O, T, S, L, L), 16));
}
};
// Field
int maxClearLine = 4;
int maxDepth = 10;
Field field = FieldFactory.createField(maxClearLine);
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
for (Pair<List<Piece>, Integer> testCase : testCases) {
// Set test case
List<Piece> pieces = testCase.getKey();
int expectedCount = testCase.getValue();
// Execute
List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(results).as(pieces.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class PackSearcherTest method assertHeight5.
void assertHeight5(SizedBit sizedBit, int maxCount, BiFunction<Field, SolutionFilter, BasicSolutions> basicSolutionSupplier) throws ExecutionException, InterruptedException, SyntaxException {
assert sizedBit.getWidth() == 2;
assert sizedBit.getHeight() == 5;
int width = sizedBit.getWidth();
int height = sizedBit.getHeight();
Randoms randoms = new Randoms();
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
TaskResultHelper taskResultHelper = new BasicMinoPackingHelper();
for (int count = 0; count < maxCount; count++) {
// Field
int maxDepth = randoms.nextIntClosed(3, 6);
Field initField = randoms.field(height, maxDepth);
List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, initField);
SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
// Pack
BasicSolutions basicSolutions = basicSolutionSupplier.apply(initField, solutionFilter);
PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
List<Result> results = searcher.toList();
// Possible
HashSet<Pieces> possiblePieces = new HashSet<>();
for (Result result : results) {
// result to possible pieces
List<MinoOperationWithKey> operationWithKeys = result.getMemento().getSeparableMinoStream(width).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
Set<LongPieces> sets = new BuildUpStream(reachable, height).existsValidBuildPattern(initField, operationWithKeys).map(keys -> keys.stream().map(OperationWithKey::getPiece)).map(LongPieces::new).collect(Collectors.toSet());
possiblePieces.addAll(sets);
}
// Checker
PerfectValidator validator = new PerfectValidator();
CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
// Assert generator
PatternGenerator generator = createPiecesGenerator(maxDepth);
generator.blocksStream().forEach(blocks -> {
List<Piece> pieceList = blocks.getPieces();
boolean check = checker.check(initField, pieceList, candidate, height, maxDepth);
assertThat(possiblePieces.contains(blocks)).as(pieceList.toString()).isEqualTo(check);
});
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class PackSearcherTest method assertHeight4.
private void assertHeight4(SizedBit sizedBit, int maxCount, BiFunction<Field, SolutionFilter, BasicSolutions> basicSolutionSupplier) throws ExecutionException, InterruptedException, SyntaxException {
assert sizedBit.getWidth() == 3;
assert sizedBit.getHeight() == 4;
int width = sizedBit.getWidth();
int height = sizedBit.getHeight();
Randoms randoms = new Randoms();
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
TaskResultHelper taskResultHelper = new Field4x10MinoPackingHelper();
for (int count = 0; count < maxCount; count++) {
// Field
int maxDepth = randoms.nextIntClosed(3, 6);
Field initField = randoms.field(height, maxDepth);
List<InOutPairField> inOutPairFields = InOutPairField.createInOutPairFields(sizedBit, initField);
SolutionFilter solutionFilter = createSRSSolutionFilter(sizedBit, initField);
// Pack
BasicSolutions basicSolutions = basicSolutionSupplier.apply(initField, solutionFilter);
PerfectPackSearcher searcher = new PerfectPackSearcher(inOutPairFields, basicSolutions, sizedBit, solutionFilter, taskResultHelper);
List<Result> results = searcher.toList();
// Possible
HashSet<Pieces> possiblePieces = new HashSet<>();
for (Result result : results) {
// result to possible pieces
List<MinoOperationWithKey> operationWithKeys = result.getMemento().getSeparableMinoStream(width).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toList());
Set<LongPieces> sets = new BuildUpStream(reachable, height).existsValidBuildPattern(initField, operationWithKeys).map(keys -> keys.stream().map(OperationWithKey::getPiece)).map(LongPieces::new).collect(Collectors.toSet());
possiblePieces.addAll(sets);
}
// Checker
PerfectValidator validator = new PerfectValidator();
CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
// Assert generator
PatternGenerator generator = createPiecesGenerator(maxDepth);
generator.blocksStream().forEach(blocks -> {
List<Piece> pieceList = blocks.getPieces();
boolean check = checker.check(initField, pieceList, candidate, height, maxDepth);
assertThat(possiblePieces.contains(blocks)).as(pieceList.toString()).isEqualTo(check);
});
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class CheckmateUsingHoldTest method testMultiPath1.
@Test
void testMultiPath1() throws Exception {
// Field
String marks = "" + "X________X" + "XX__XX__XX" + "XX__XX__XX" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 3;
int maxDepth = 4;
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
// Set test case
List<Piece> pieces = Arrays.asList(J, L, S, Z);
int expectedCount = 4;
// Execute
List<Result> results = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(results).as(pieces.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, pieces);
}
Aggregations