use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class BuildUpTest method cansBuildRandomShortByCheck.
@Test
void cansBuildRandomShortByCheck() {
Randoms randoms = new Randoms();
// Create field
int height = 4;
// Initialize
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
PerfectValidator validator = new PerfectValidator();
CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
AtomicInteger counter = new AtomicInteger();
for (int count = 0; count < 10000; count++) {
// Pickup solution from checker
int numOfMinos = randoms.nextInt(1, 7);
Field field = randoms.field(height, numOfMinos);
List<Piece> pieces = randoms.blocks(numOfMinos);
boolean check = checker.check(field, pieces, candidate, height, numOfMinos);
if (check) {
counter.incrementAndGet();
Stream<Operation> operationStream = ResultHelper.createOperationStream(checker.getResult());
Operations operations = new Operations(operationStream);
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).as(FieldView.toString(field) + pieces).isTrue();
}
}
System.out.println(counter);
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldTest 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);
}
use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldTest method testLong10.
@Test
void testLong10() throws Exception {
// Invoker
List<Pair<List<Piece>, Integer>> testCases = new ArrayList<Pair<List<Piece>, Integer>>() {
{
add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L), 81));
}
};
// 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.candidate.LockedCandidate in project solution-finder by knewjade.
the class CheckmateUsingHoldTest 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 = 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 CheckerNoHoldTest method testCaseList.
@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, boolean expectedCount) throws Exception {
int maxDepth = 10;
int maxClearLine = 4;
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();
// Execute
boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
assertThat(isSucceed).isEqualTo(expectedCount);
// Check result
if (isSucceed)
assertResult(field, maxClearLine, reachable, piecesList);
}
Aggregations