Search in sources :

Example 11 with LockedCandidate

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);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) 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 12 with LockedCandidate

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);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) 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 13 with LockedCandidate

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);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 14 with LockedCandidate

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());
    }
}
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 15 with LockedCandidate

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());
    }
}
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