Search in sources :

Example 1 with Action

use of common.datastore.action.Action in project solution-finder by knewjade.

the class ResultHelper method createOperationStream.

public static Stream<Operation> createOperationStream(Result result) {
    Order order = result.getOrder();
    OperationHistory history = order.getHistory();
    Stream<Operation> operationStream = history.getOperationStream();
    Piece lastPiece = result.getLastPiece();
    Action lastAction = result.getLastAction();
    SimpleOperation lastOperation = new SimpleOperation(lastPiece, lastAction.getRotate(), lastAction.getX(), lastAction.getY());
    return Stream.concat(operationStream, Stream.of(lastOperation));
}
Also used : Order(common.datastore.order.Order) Action(common.datastore.action.Action) Piece(core.mino.Piece) SimpleOperation(common.datastore.SimpleOperation) SimpleOperation(common.datastore.SimpleOperation) Operation(common.datastore.Operation)

Example 2 with Action

use of common.datastore.action.Action 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 3 with Action

use of common.datastore.action.Action 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 4 with Action

use of common.datastore.action.Action 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 5 with Action

use of common.datastore.action.Action 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)

Aggregations

Action (common.datastore.action.Action)82 Field (core.field.Field)66 Test (org.junit.jupiter.api.Test)57 Piece (core.mino.Piece)52 LongTest (module.LongTest)45 LockedCandidate (core.action.candidate.LockedCandidate)43 LockedReachable (core.action.reachable.LockedReachable)27 MinimalAction (common.datastore.action.MinimalAction)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 MinoRotation (core.srs.MinoRotation)25 Randoms (lib.Randoms)24 MinoFactory (core.mino.MinoFactory)20 MinoShifter (core.mino.MinoShifter)20 Rotate (core.srs.Rotate)13 PerfectValidator (searcher.common.validator.PerfectValidator)13 List (java.util.List)11 Stopwatch (lib.Stopwatch)10 Result (common.datastore.Result)9 ArrayList (java.util.ArrayList)9 AnalyzeTree (common.tree.AnalyzeTree)8