Search in sources :

Example 6 with MinoShifter

use of core.mino.MinoShifter 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 MinoShifter

use of core.mino.MinoShifter 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 MinoShifter

use of core.mino.MinoShifter 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 MinoShifter

use of core.mino.MinoShifter 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 MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class FullOperationSeparableMinoComparatorTest method createSeparableMinos.

private SeparableMinos createSeparableMinos() {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    SizedBit sizedBit = new SizedBit(3, 4);
    return SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
}
Also used : MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter)

Aggregations

MinoShifter (core.mino.MinoShifter)60 MinoFactory (core.mino.MinoFactory)59 MinoRotation (core.srs.MinoRotation)39 Field (core.field.Field)36 Test (org.junit.jupiter.api.Test)35 LongTest (module.LongTest)29 Action (common.datastore.action.Action)22 ColumnField (core.column_field.ColumnField)19 Piece (core.mino.Piece)19 InOutPairField (searcher.pack.InOutPairField)18 Randoms (lib.Randoms)17 LockedReachable (core.action.reachable.LockedReachable)15 LockedCandidate (core.action.candidate.LockedCandidate)14 PermutationIterable (common.iterable.PermutationIterable)12 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 PerfectValidator (searcher.common.validator.PerfectValidator)10 SizedBit (searcher.pack.SizedBit)10 SolutionFilter (searcher.pack.memento.SolutionFilter)10