Search in sources :

Example 6 with MinoRotation

use of core.srs.MinoRotation 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 MinoRotation

use of core.srs.MinoRotation 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 MinoRotation

use of core.srs.MinoRotation 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 MinoRotation

use of core.srs.MinoRotation 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 MinoRotation

use of core.srs.MinoRotation in project solution-finder by knewjade.

the class LimitIterationCandidateTest method testSearch2.

@Test
void testSearch2() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 3);
    String marks = "" + "XXXX______" + "XXXXX_____" + "X___X_____" + "XX_XX_____";
    Field field = FieldFactory.createField(marks);
    Set<Action> actions = candidate.search(field, Piece.T, 4);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Spawn)).hasSize(3);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Right)).hasSize(4);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Reverse)).hasSize(4);
    assertThat(actions.stream().filter((e) -> e.getRotate() == Rotate.Left)).hasSize(4);
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

MinoRotation (core.srs.MinoRotation)44 MinoFactory (core.mino.MinoFactory)38 Field (core.field.Field)37 MinoShifter (core.mino.MinoShifter)37 Test (org.junit.jupiter.api.Test)32 LongTest (module.LongTest)29 Action (common.datastore.action.Action)25 Piece (core.mino.Piece)17 LockedReachable (core.action.reachable.LockedReachable)16 ColumnField (core.column_field.ColumnField)16 InOutPairField (searcher.pack.InOutPairField)16 Randoms (lib.Randoms)15 LockedCandidate (core.action.candidate.LockedCandidate)14 MinimalAction (common.datastore.action.MinimalAction)12 PermutationIterable (common.iterable.PermutationIterable)12 List (java.util.List)10 PerfectValidator (searcher.common.validator.PerfectValidator)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)8 FieldFactory (core.field.FieldFactory)8