Search in sources :

Example 1 with LockedCandidate

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

the class BuildUpTest method cansBuildRandomShortByCheck.

@Test
void cansBuildRandomShortByCheck() {
    Randoms randoms = new Randoms();
    // Create field
    int height = 4;
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    AtomicInteger counter = new AtomicInteger();
    for (int count = 0; count < 10000; count++) {
        // Pickup solution from checker
        int numOfMinos = randoms.nextInt(1, 7);
        Field field = randoms.field(height, numOfMinos);
        List<Piece> pieces = randoms.blocks(numOfMinos);
        boolean check = checker.check(field, pieces, candidate, height, numOfMinos);
        if (check) {
            counter.incrementAndGet();
            Stream<Operation> operationStream = ResultHelper.createOperationStream(checker.getResult());
            Operations operations = new Operations(operationStream);
            List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
            assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).as(FieldView.toString(field) + pieces).isTrue();
        }
    }
    System.out.println(counter);
}
Also used : Action(common.datastore.action.Action) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) Randoms(lib.Randoms) CheckerUsingHold(searcher.checker.CheckerUsingHold) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) PerfectValidator(searcher.common.validator.PerfectValidator) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 2 with LockedCandidate

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

the class CheckmateUsingHoldTest 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)

Example 3 with LockedCandidate

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

the class CheckmateUsingHoldTest method testLong10.

@Test
void testLong10() throws Exception {
    // Invoker
    List<Pair<List<Piece>, Integer>> testCases = new ArrayList<Pair<List<Piece>, Integer>>() {

        {
            add(new Pair<>(Arrays.asList(T, L, J, Z, S, O, O, T, J, L), 81));
        }
    };
    // 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
    for (Pair<List<Piece>, Integer> testCase : testCases) {
        // Set test case
        List<Piece> pieces = testCase.getKey();
        int expectedCount = testCase.getValue();
        // 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 : 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 4 with LockedCandidate

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

the class CheckmateUsingHoldTest 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 = 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 5 with LockedCandidate

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

the class CheckerNoHoldTest method testCaseList.

@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, boolean expectedCount) throws Exception {
    int maxDepth = 10;
    int maxClearLine = 4;
    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();
    // Execute
    boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
    assertThat(isSucceed).isEqualTo(expectedCount);
    // Check result
    if (isSucceed)
        assertResult(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)

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