Search in sources :

Example 1 with BlockInterpreter

use of common.parser.BlockInterpreter 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);
    }
}
Also used : Action(common.datastore.action.Action) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) LongPieces(common.datastore.blocks.LongPieces) BlockInterpreter(common.parser.BlockInterpreter) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) LongTest(module.LongTest)

Aggregations

Action (common.datastore.action.Action)1 LongPieces (common.datastore.blocks.LongPieces)1 BlockInterpreter (common.parser.BlockInterpreter)1 LockedCandidate (core.action.candidate.LockedCandidate)1 LockedReachable (core.action.reachable.LockedReachable)1 Field (core.field.Field)1 Piece (core.mino.Piece)1 Randoms (lib.Randoms)1 LongTest (module.LongTest)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1