Search in sources :

Example 31 with LockedReachable

use of core.action.reachable.LockedReachable 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 32 with LockedReachable

use of core.action.reachable.LockedReachable 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)

Example 33 with LockedReachable

use of core.action.reachable.LockedReachable in project solution-finder by knewjade.

the class CheckerNoHoldTest method testCase2.

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

        {
            add(new Pair<>(Arrays.asList(I, L, T, S, Z), true));
        }
    };
    // Field
    String marks = "" + "XX______XX" + "X______XXX" + "X______XXX" + "XX_XXX_XXX" + "";
    Field field = FieldFactory.createField(marks);
    int maxClearLine = 4;
    int maxDepth = 5;
    // 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 34 with LockedReachable

use of core.action.reachable.LockedReachable in project solution-finder by knewjade.

the class CheckerUsingHoldTest method testNoPossiblePerfect.

@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testNoPossiblePerfect(LongPieces pieces) throws Exception {
    // Field
    Field field = FieldFactory.createSmallField();
    int maxClearLine = 4;
    int maxDepth = 10;
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    // Set test case
    List<Piece> blocks = pieces.getPieces();
    // Execute
    boolean isSucceed = checker.check(field, blocks, candidate, maxClearLine, maxDepth);
    assertThat(isSucceed).isFalse();
    // Check result
    if (isSucceed)
        assertResult(field, maxClearLine, reachable, blocks);
}
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 35 with LockedReachable

use of core.action.reachable.LockedReachable in project solution-finder by knewjade.

the class CheckmateNoHoldTest method testMultiPath2.

@Test
void testMultiPath2() throws Exception {
    // Field
    String marks = "" + "X____XXXXX" + "XX__XXXXXX" + "XX__XXXXXX" + "XXXXXX__XX" + "XXXXXX__XX" + "";
    Field field = FieldFactory.createField(marks);
    int maxClearLine = 5;
    int maxDepth = 3;
    // 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(S, Z, O);
    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)

Aggregations

LockedReachable (core.action.reachable.LockedReachable)42 Field (core.field.Field)41 LongTest (module.LongTest)38 Test (org.junit.jupiter.api.Test)35 Piece (core.mino.Piece)34 Action (common.datastore.action.Action)31 LockedCandidate (core.action.candidate.LockedCandidate)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 MinoRotation (core.srs.MinoRotation)18 MinoFactory (core.mino.MinoFactory)17 MinoShifter (core.mino.MinoShifter)17 ColumnField (core.column_field.ColumnField)16 InOutPairField (searcher.pack.InOutPairField)16 Randoms (lib.Randoms)13 List (java.util.List)11 FieldFactory (core.field.FieldFactory)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 PermutationIterable (common.iterable.PermutationIterable)8 OperationTransform (common.parser.OperationTransform)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8