Search in sources :

Example 6 with LockedReachable

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

the class BuildUpTest method existsValidBuildPattern1.

@Test
void existsValidBuildPattern1() throws Exception {
    Field field = FieldFactory.createField("" + "_________X" + "_________X");
    int maxY = 4;
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxY);
    List<MinoOperationWithKey> operationWithKeys = Arrays.asList(new FullOperationWithKey(minoFactory.create(Piece.J, Rotate.Right), 5, 0L, 0L, 0), new FullOperationWithKey(minoFactory.create(Piece.J, Rotate.Reverse), 8, 0L, 0L, 2), new FullOperationWithKey(minoFactory.create(Piece.L, Rotate.Spawn), 7, 0L, 0L, 0), new FullOperationWithKey(minoFactory.create(Piece.S, Rotate.Spawn), 7, 0L, 0L, 1));
    boolean exists = BuildUp.existsValidBuildPattern(field, operationWithKeys, maxY, reachable);
    assertThat(exists).isTrue();
}
Also used : ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 7 with LockedReachable

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

the class BuildUpTest method cansBuild.

@Test
void cansBuild() {
    Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
    int height = 4;
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    Operations operations = OperationInterpreter.parseToOperations("J,0,1,0;S,L,1,2;O,0,2,1;J,2,2,1");
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
    assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).isTrue();
    MinoOperationWithKey remove = operationWithKeys.remove(0);
    operationWithKeys.add(1, remove);
    assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).isFalse();
}
Also used : ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 8 with LockedReachable

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

the class BuildUpTest method checksAllPatterns2.

@Test
void checksAllPatterns2() throws Exception {
    int height = 4;
    Field field = FieldFactory.createField("" + "_____XXXXX" + "____XXXXXX" + "___XXXXXXX" + "____XXXXXX");
    Operations operations = new Operations(Arrays.asList(new SimpleOperation(Piece.I, Rotate.Left, 0, 1), new SimpleOperation(Piece.J, Rotate.Spawn, 2, 0), new SimpleOperation(Piece.S, Rotate.Right, 1, 1), new SimpleOperation(Piece.T, Rotate.Reverse, 3, 1)));
    // OperationWithKeyに変換
    MinoFactory minoFactory = new MinoFactory();
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
    // reachableの準備
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    // existsValidBuildPatternのチェック
    boolean exists = BuildUp.existsValidBuildPattern(field, operationWithKeys, height, reachable);
    assertThat(exists).isTrue();
    // 有効な手順を列挙する
    BuildUpStream buildUpStream = new BuildUpStream(reachable, height);
    Set<List<MinoOperationWithKey>> validPatterns = buildUpStream.existsValidBuildPattern(field, operationWithKeys).collect(Collectors.toSet());
    // すべての組み合わせでチェック
    Iterable<List<MinoOperationWithKey>> iterable = new PermutationIterable<>(operationWithKeys, operationWithKeys.size());
    for (List<MinoOperationWithKey> withKeys : iterable) {
        boolean canBuild = BuildUp.cansBuild(field, withKeys, height, reachable);
        assertThat(canBuild).isEqualTo(validPatterns.contains(withKeys));
        boolean checksKey = BuildUp.checksKey(withKeys, 0L, height);
        assertThat(checksKey).isTrue();
    }
}
Also used : PermutationIterable(common.iterable.PermutationIterable) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 9 with LockedReachable

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

the class BuildUpTest method existsValidByOrder.

@Test
void existsValidByOrder() throws Exception {
    Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "");
    String line = "L,L,3,1,0,1049601;L,R,1,1,0,1049601;I,L,0,1,0,1074791425;T,2,2,2,1048576,1073742848";
    MinoFactory minoFactory = new MinoFactory();
    Stream<MinoOperationWithKey> stream = OperationWithKeyInterpreter.parseToStream(line, minoFactory);
    List<MinoOperationWithKey> operations = stream.collect(Collectors.toList());
    System.out.println(operations);
    int height = 4;
    MinoRotation minoRotation = new MinoRotation();
    MinoShifter minoShifter = new MinoShifter();
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    // true
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, L, I, T), height, reachable)).isTrue();
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, I, L, T), height, reachable)).isTrue();
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(I, L, L, T), height, reachable)).isTrue();
    // false
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, L, T, I), height, reachable)).isFalse();
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, T, L, I), height, reachable)).isFalse();
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(L, T, I, L), height, reachable)).isFalse();
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(T, L, I, L), height, reachable)).isFalse();
    assertThat(BuildUp.existsValidByOrder(field, operations.stream(), Arrays.asList(T, I, L, L), height, reachable)).isFalse();
}
Also used : ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 10 with LockedReachable

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

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