use of core.action.candidate.LockedCandidate 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.candidate.LockedCandidate 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);
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateNoHoldTest method testCaseList.
@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, int expectedCount) {
// 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
// Set test case
List<Piece> piecesList = pieces.getPieces();
System.out.println(piecesList);
// Execute
List<Result> results = checkmate.search(field, piecesList, candidate, maxClearLine, maxDepth);
assertThat(results).as(piecesList.toString()).hasSize(expectedCount);
// Check result
for (Result result : results) assertResult(result, field, maxClearLine, reachable, piecesList);
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldReuseTest method randomCheckmateOverMoreBlock.
@Test
@LongTest
void randomCheckmateOverMoreBlock() {
Randoms randoms = new Randoms();
for (int count = 0; count < 25; 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());
}
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldReuseTest method randomCheckmateOverBlock.
@Test
@LongTest
void randomCheckmateOverBlock() {
Randoms randoms = new Randoms();
for (int count = 0; count < 25; 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());
}
}
Aggregations