Search in sources :

Example 21 with LockedCandidate

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

the class CheckerNoHoldCountTest method runTestCase.

private AnalyzeTree runTestCase(PatternGenerator blocksGenerator, int maxClearLine, int maxDepth, String marks) {
    Field field = FieldFactory.createField(marks);
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
    // Measure
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    AnalyzeTree tree = new AnalyzeTree();
    blocksGenerator.blocksStream().forEach(blocks -> {
        List<Piece> pieceList = blocks.getPieces();
        boolean result = checker.check(field, pieceList, candidate, maxClearLine, maxDepth);
        tree.set(result, pieceList);
    });
    return tree;
}
Also used : Action(common.datastore.action.Action) AnalyzeTree(common.tree.AnalyzeTree) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) PerfectValidator(searcher.common.validator.PerfectValidator)

Example 22 with LockedCandidate

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

the class CheckerNoHoldTest method testCase3.

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

        {
            add(new Pair<>(Arrays.asList(T, I, L, S, O, Z, J), false));
            add(new Pair<>(Arrays.asList(O, J, I, L, T, S, Z), false));
            add(new Pair<>(Arrays.asList(O, J, L, T, I, S, Z), true));
        }
    };
    // Field
    String marks = "" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "XXXXXX____" + "XXXXXXXX__" + "XXXXXXXX__" + "";
    Field field = FieldFactory.createField(marks);
    int maxClearLine = 8;
    int maxDepth = 7;
    // 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 expectedCount = testCase.getValue();
        // Execute
        boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(isSucceed).isEqualTo(expectedCount);
        // Check result
        if (isSucceed)
            assertResult(field, maxClearLine, reachable, pieces);
    }
}
Also used : Action(common.datastore.action.Action) ArrayList(java.util.ArrayList) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) List(java.util.List) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest)

Example 23 with LockedCandidate

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

the class CheckerNoHoldTest 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), false));
            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), false));
            add(new Pair<>(Arrays.asList(L, S, Z, T), false));
        }
    };
    // 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 expectedCount = testCase.getValue();
        // Execute
        boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(isSucceed).isEqualTo(expectedCount);
        // Check result
        if (isSucceed)
            assertResult(field, maxClearLine, reachable, pieces);
    }
}
Also used : Action(common.datastore.action.Action) ArrayList(java.util.ArrayList) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) List(java.util.List) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest)

Example 24 with LockedCandidate

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

the class CheckerNoHoldTest 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 expectedCount = testCase.getValue();
        // Execute
        boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(isSucceed).isEqualTo(expectedCount);
        // Check result
        if (isSucceed)
            assertResult(field, maxClearLine, reachable, pieces);
    }
}
Also used : Action(common.datastore.action.Action) ArrayList(java.util.ArrayList) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) List(java.util.List) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest)

Example 25 with LockedCandidate

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

the class CheckerNoHoldTest method testCase1.

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

        {
            add(new Pair<>(Arrays.asList(J, I, O, L, S, Z, T), true));
            add(new Pair<>(Arrays.asList(J, O, I, L, Z, S, T), true));
            add(new Pair<>(Arrays.asList(O, J, I, L, Z, S, T), true));
        }
    };
    // Field
    String marks = "" + "X________X" + "X________X" + "XX______XX" + "XXXXXX__XX" + "";
    Field field = FieldFactory.createField(marks);
    int maxClearLine = 4;
    int maxDepth = 6;
    // 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 expectedCount = testCase.getValue();
        // Execute
        boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
        assertThat(isSucceed).isEqualTo(expectedCount);
        // Check result
        if (isSucceed)
            assertResult(field, maxClearLine, reachable, pieces);
    }
}
Also used : Action(common.datastore.action.Action) ArrayList(java.util.ArrayList) Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) ArrayList(java.util.ArrayList) List(java.util.List) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) 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