use of core.action.reachable.LockedReachable 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.reachable.LockedReachable in project solution-finder by knewjade.
the class LockedCandidateTest method testRandom.
@Test
void testRandom() throws Exception {
Randoms randoms = new Randoms();
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new PassedMinoShifter();
MinoRotation minoRotation = new MinoRotation();
for (int count = 0; count < 10000; count++) {
int randomHeight = randoms.nextIntClosed(2, 12);
int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
Field field = randoms.field(randomHeight, numOfMinos);
int height = randomHeight - field.clearLine();
Piece piece = randoms.block();
LockedCandidate candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
Set<Action> actions = candidate.search(field, piece, height);
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
for (Rotate rotate : Rotate.values()) {
Coordinates.walk(minoFactory.create(piece, rotate), height).map(coordinate -> MinimalAction.create(coordinate.x, coordinate.y, rotate)).forEach(action -> {
int x = action.getX();
int y = action.getY();
Mino mino = minoFactory.create(piece, action.getRotate());
if (actions.contains(action)) {
// おける
assertThat(field.canPut(mino, x, y)).isTrue();
assertThat(field.isOnGround(mino, x, y)).isTrue();
assertThat(reachable.checks(field, mino, x, y, height)).isTrue();
} else {
// おけない
boolean canPut = field.canPut(mino, x, y) && field.isOnGround(mino, x, y) && reachable.checks(field, mino, x, y, height);
assertThat(canPut).isFalse();
}
});
}
}
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class LockedBuildUpListUpThreadLocal method initialValue.
@Override
protected BuildUpStream initialValue() {
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
return new BuildUpStream(reachable, height);
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class BuildUpStreamTest method buildUp2.
@Test
void buildUp2() {
// Create LockedReachable
int height = 4;
MinoFactory minoFactory = new MinoFactory();
MinoShifter minoShifter = new MinoShifter();
MinoRotation minoRotation = new MinoRotation();
LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
// Create OperationWithKey List
Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
Operations operations = OperationInterpreter.parseToOperations("J,R,0,1;O,0,1,0;L,L,3,1;I,0,1,0");
List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
// Create Pieces
Set<String> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).map(op -> op.stream().map(OperationWithKey::getPiece).map(Piece::name).collect(Collectors.joining())).collect(Collectors.toSet());
// Assertion
assertThat(valid).hasSize(16).doesNotContain("IJOL", "IJLO", "IOJL", "IOLJ", "ILOJ", // starts I
"ILJO").doesNotContain("OIJL", // starts OI
"OILJ").contains("OJLI", "OJIL", "JOIL", "JLIO", "LOJI", "LIOJ");
}
use of core.action.reachable.LockedReachable in project solution-finder by knewjade.
the class BuildUpTest method cansBuildRandomLongByCheck.
@Test
@LongTest
void cansBuildRandomLongByCheck() {
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 < 100; count++) {
// Pickup solution from checker
int numOfMinos = randoms.nextIntClosed(7, 10);
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);
}
Aggregations