Search in sources :

Example 6 with LockedCandidate

use of core.action.candidate.LockedCandidate 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)

Example 7 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class CheckerUsingHoldTest method testCaseFilledLine.

@Test
void testCaseFilledLine() throws Exception {
    List<Pair<List<Piece>, Boolean>> testCases = new ArrayList<Pair<List<Piece>, Boolean>>() {

        {
            add(new Pair<>(Arrays.asList(I, Z, L, I), true));
        }
    };
    // 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
    for (Pair<List<Piece>, Boolean> testCase : testCases) {
        // Set test case
        List<Piece> pieces = testCase.getKey();
        Boolean expectedCheckFlag = testCase.getValue();
        // Execute
        boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(isSucceed).isEqualTo(expectedCheckFlag);
        // 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) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest)

Example 8 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class CheckerUsingHoldTest method testGraceSystem.

@Test
void testGraceSystem() throws Exception {
    List<Pair<List<Piece>, Boolean>> testCases = new ArrayList<Pair<List<Piece>, Boolean>>() {

        {
            add(new Pair<>(Arrays.asList(T, S, O, J), false));
            add(new Pair<>(Arrays.asList(T, O, J, S), false));
            add(new Pair<>(Arrays.asList(T, T, L, J), true));
            add(new Pair<>(Arrays.asList(T, T, S, Z), true));
            add(new Pair<>(Arrays.asList(T, S, Z, T), true));
            add(new Pair<>(Arrays.asList(J, S, Z, L), false));
            add(new Pair<>(Arrays.asList(Z, I, O, T), false));
            add(new Pair<>(Arrays.asList(I, J, J, O), true));
            add(new Pair<>(Arrays.asList(T, S, Z, J), true));
            add(new Pair<>(Arrays.asList(L, S, Z, T), true));
        }
    };
    // Field
    String marks = "" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "";
    Field field = FieldFactory.createField(marks);
    int maxClearLine = 4;
    int maxDepth = 4;
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    for (Pair<List<Piece>, Boolean> testCase : testCases) {
        // Set test case
        List<Piece> pieces = testCase.getKey();
        Boolean expectedCheckFlag = testCase.getValue();
        // Execute
        boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(isSucceed).isEqualTo(expectedCheckFlag);
        // 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) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest)

Example 9 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class CheckmateNoHoldReuseTest method randomCheckmateOverBlock.

@Test
@LongTest
void randomCheckmateOverBlock() {
    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 + 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());
    }
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) Action(common.datastore.action.Action) Piece(core.mino.Piece) Stopwatch(lib.Stopwatch) Result(common.datastore.Result) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 10 with LockedCandidate

use of core.action.candidate.LockedCandidate in project solution-finder by knewjade.

the class CheckmateNoHoldReuseTest method randomCheckmateOverMoreBlock.

@Test
@LongTest
void randomCheckmateOverMoreBlock() {
    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 + 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());
    }
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Randoms(lib.Randoms) Action(common.datastore.action.Action) Piece(core.mino.Piece) Stopwatch(lib.Stopwatch) Result(common.datastore.Result) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Aggregations

LockedCandidate (core.action.candidate.LockedCandidate)44 Action (common.datastore.action.Action)43 Field (core.field.Field)43 Piece (core.mino.Piece)40 LongTest (module.LongTest)38 Test (org.junit.jupiter.api.Test)32 LockedReachable (core.action.reachable.LockedReachable)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Randoms (lib.Randoms)15 PerfectValidator (searcher.common.validator.PerfectValidator)13 MinoFactory (core.mino.MinoFactory)12 MinoShifter (core.mino.MinoShifter)12 MinoRotation (core.srs.MinoRotation)12 List (java.util.List)11 Result (common.datastore.Result)8 AnalyzeTree (common.tree.AnalyzeTree)8 Stopwatch (lib.Stopwatch)8 ArrayList (java.util.ArrayList)7 PatternGenerator (common.pattern.PatternGenerator)6 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)6