use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class CheckerUsingHoldTest method testPossiblePerfect.
@Test
@LongTest
void testPossiblePerfect() throws Exception {
// Field
Field field = FieldFactory.createSmallField();
int maxClearLine = 4;
int maxDepth = 10;
// Set to check No Possible Perfect
String noPerfectPath = ClassLoader.getSystemResource("orders/noperfect.txt").getPath();
HashSet<LongPieces> noPerfectSet = Files.lines(Paths.get(noPerfectPath)).map(BlockInterpreter::parse).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
Randoms randoms = new Randoms();
for (int count = 0; count < 100; count++) {
// Set test case
int cycle = randoms.nextIntClosed(0, 8);
List<Piece> pieces = randoms.block11InCycle(cycle);
// Execute
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
boolean expectedFlag = !noPerfectSet.contains(new LongPieces(pieces));
assertThat(isSucceed).isEqualTo(expectedFlag);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, pieces);
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class CheckerUsingHoldTest method testCaseFilledLine.
@Test
void testCaseFilledLine() throws Exception {
List<Pair<List<Piece>, Boolean>> testCases = new ArrayList<Pair<List<Piece>, Boolean>>() {
{
add(new Pair<>(Arrays.asList(I, Z, L, I), true));
}
};
// Field
String marks = "" + "XXXXX_____" + "XXXXXXXXXX" + "XXXXXX____" + "XXXXXXX___" + "XXXXXX____" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 5;
int maxDepth = 4;
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
for (Pair<List<Piece>, Boolean> testCase : testCases) {
// Set test case
List<Piece> pieces = testCase.getKey();
Boolean expectedCheckFlag = testCase.getValue();
// Execute
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(isSucceed).isEqualTo(expectedCheckFlag);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, pieces);
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class CheckerUsingHoldTest method testGraceSystem.
@Test
void testGraceSystem() throws Exception {
List<Pair<List<Piece>, Boolean>> testCases = new ArrayList<Pair<List<Piece>, Boolean>>() {
{
add(new Pair<>(Arrays.asList(T, S, O, J), false));
add(new Pair<>(Arrays.asList(T, O, J, S), false));
add(new Pair<>(Arrays.asList(T, T, L, J), true));
add(new Pair<>(Arrays.asList(T, T, S, Z), true));
add(new Pair<>(Arrays.asList(T, S, Z, T), true));
add(new Pair<>(Arrays.asList(J, S, Z, L), false));
add(new Pair<>(Arrays.asList(Z, I, O, T), false));
add(new Pair<>(Arrays.asList(I, J, J, O), true));
add(new Pair<>(Arrays.asList(T, S, Z, J), true));
add(new Pair<>(Arrays.asList(L, S, Z, T), true));
}
};
// Field
String marks = "" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 4;
int maxDepth = 4;
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
for (Pair<List<Piece>, Boolean> testCase : testCases) {
// Set test case
List<Piece> pieces = testCase.getKey();
Boolean expectedCheckFlag = testCase.getValue();
// Execute
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(isSucceed).isEqualTo(expectedCheckFlag);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, pieces);
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class CheckmateNoHoldTest method testFilledLine.
@Test
void testFilledLine() throws Exception {
// Field
String marks = "" + "XXXXX_____" + "XXXXXXXXXX" + "XXXXXX____" + "XXXXXXX___" + "XXXXXX____" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 5;
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(I, Z, L, I);
int expectedCount = 1;
// 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 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 = 2;
// 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