use of core.action.candidate.LockedCandidate 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.candidate.LockedCandidate 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.candidate.LockedCandidate 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.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateNoHoldReuseTest method randomCheckmateOverBlock.
@Test
@LongTest
void randomCheckmateOverBlock() {
Randoms randoms = new Randoms();
for (int count = 0; count < 100; count++) {
int maxClearLine = randoms.nextInt(3, 8);
int maxDepth = randoms.nextIntClosed(5, 7);
List<Piece> pieces = randoms.blocks(maxDepth + 1);
Field field = randoms.field(maxClearLine, maxDepth);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
Stopwatch stopwatchReuse = Stopwatch.createStoppedStopwatch();
for (int swap = 0; swap < 250; swap++) {
int index = randoms.nextInt(3, pieces.size());
Piece pop = pieces.remove(index);
pieces.add(pop);
stopwatchNoUse.start();
List<Result> result1 = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchNoUse.stop();
stopwatchReuse.start();
List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchReuse.stop();
assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
}
// assertThat(stopwatchReuse.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
}
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateNoHoldReuseTest method randomCheckmateOverMoreBlock.
@Test
@LongTest
void randomCheckmateOverMoreBlock() {
Randoms randoms = new Randoms();
for (int count = 0; count < 100; count++) {
int maxClearLine = randoms.nextInt(3, 8);
int maxDepth = randoms.nextIntClosed(5, 7);
List<Piece> pieces = randoms.blocks(maxDepth + 10);
Field field = randoms.field(maxClearLine, maxDepth);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
Stopwatch stopwatchReuse = Stopwatch.createStoppedStopwatch();
for (int swap = 0; swap < 250; swap++) {
int index = randoms.nextInt(3, pieces.size());
Piece pop = pieces.remove(index);
pieces.add(pop);
stopwatchNoUse.start();
List<Result> result1 = checkmate.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchNoUse.stop();
stopwatchReuse.start();
List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchReuse.stop();
assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
}
assertThat(stopwatchReuse.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
}
}
Aggregations