use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckerUsingHoldCountTest method testTemplateWithHoldI.
@Test
void testTemplateWithHoldI() throws Exception {
// Invoker
String pattern = "I, *p4";
int maxClearLine = 4;
int maxDepth = 4;
// Field
String marks = "" + "XXXXX_____" + "XXXXXX____" + "XXXXXXX___" + "XXXXXX____" + "";
Field field = FieldFactory.createField(marks);
// Initialize
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
// Measure
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
AnalyzeTree tree = new AnalyzeTree();
PatternGenerator generator = new LoadedPatternGenerator(pattern);
generator.blocksStream().forEach(blocks -> {
List<Piece> pieceList = blocks.getPieces();
boolean result = checker.check(field, pieceList, candidate, maxClearLine, maxDepth);
tree.set(result, pieceList);
});
// Source: Nilgiri: https://docs.google.com/spreadsheets/d/1bVY3t_X96xRmUL0qdgB9tViSIGenu6RMKX4RW7qWg8Y/edit#gid=0
assertThat(tree.getSuccessPercent()).isEqualTo(711 / 840.0);
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckerUsingHoldTest method testNoPossiblePerfect.
@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testNoPossiblePerfect(LongPieces pieces) throws Exception {
// Field
Field field = FieldFactory.createSmallField();
int maxClearLine = 4;
int maxDepth = 10;
// Initialize
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
// Assertion
// Set test case
List<Piece> blocks = pieces.getPieces();
// Execute
boolean isSucceed = checker.check(field, blocks, candidate, maxClearLine, maxDepth);
assertThat(isSucceed).isFalse();
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, blocks);
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateNoHoldReuseTest method randomCheckmateWithJustBlock.
@Test
@LongTest
void randomCheckmateWithJustBlock() {
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);
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);
}
// 実行時間の比較がうまくいかないためskipする(戻り値のチェックのみ)
// assertThat(stopwatchReuse.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
}
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateNoHoldReuseTest method randomCheckmateWithJustBlockTwice.
@Test
void randomCheckmateWithJustBlockTwice() {
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);
Field field = randoms.field(maxClearLine, maxDepth);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
Stopwatch stopwatchNoUse = Stopwatch.createStoppedStopwatch();
Stopwatch stopwatchReuse1 = Stopwatch.createStoppedStopwatch();
Stopwatch stopwatchReuse2 = 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();
stopwatchReuse1.start();
List<Result> result2 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchReuse1.stop();
assertThat(result2).hasSameSizeAs(result1).containsAll(result1);
stopwatchReuse2.start();
List<Result> result3 = checkmateReuse.search(field, pieces, candidate, maxClearLine, maxDepth);
stopwatchReuse2.stop();
assertThat(result3).hasSameSizeAs(result1).containsAll(result1);
}
// 実行時間の比較がうまくいかないためskipする(戻り値のチェックのみ)
// assertThat(stopwatchReuse1.getNanoAverageTime()).isLessThan(stopwatchNoUse.getNanoAverageTime());
// assertThat(stopwatchReuse2.getNanoAverageTime()).isLessThan(stopwatchReuse1.getNanoAverageTime());
}
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateNoHoldTest method testMultiPath2.
@Test
void testMultiPath2() throws Exception {
// Field
String marks = "" + "X____XXXXX" + "XX__XXXXXX" + "XX__XXXXXX" + "XXXXXX__XX" + "XXXXXX__XX" + "";
Field field = FieldFactory.createField(marks);
int maxClearLine = 5;
int maxDepth = 3;
// 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(S, Z, O);
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);
}
Aggregations