Search in sources :

Example 6 with MinoFactory

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

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

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

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

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

the class OperationWithKeyComparatorTest method compareDiffX.

@Test
void compareDiffX() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    int x = randoms.nextInt(10);
    int y = randoms.nextInt(20);
    long deleteKey = 0L;
    long usingKey = 1049600L;
    OperationWithKey operationWithKey1 = new FullOperationWithKey(minoFactory.create(Piece.I, Rotate.Spawn), x, y, deleteKey, usingKey);
    int newX = randoms.nextInt(10);
    if (newX == x)
        newX += 1;
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, newX, y, deleteKey, usingKey);
    // assert is not 0 & sign reversed
    OperationWithKeyComparator comparator = new OperationWithKeyComparator();
    assertThat(comparator.compare(operationWithKey1, operationWithKey2) * comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isLessThan(0);
}
Also used : Randoms(lib.Randoms) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) Mino(core.mino.Mino) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Aggregations

MinoFactory (core.mino.MinoFactory)113 Test (org.junit.jupiter.api.Test)70 MinoShifter (core.mino.MinoShifter)59 LongTest (module.LongTest)51 Field (core.field.Field)45 MinoRotation (core.srs.MinoRotation)40 ColorConverter (common.tetfu.common.ColorConverter)33 Piece (core.mino.Piece)28 Action (common.datastore.action.Action)22 ColumnField (core.column_field.ColumnField)22 Randoms (lib.Randoms)22 InOutPairField (searcher.pack.InOutPairField)21 LockedReachable (core.action.reachable.LockedReachable)17 PerfectValidator (searcher.common.validator.PerfectValidator)17 LockedCandidate (core.action.candidate.LockedCandidate)16 MinoOperationWithKey (common.datastore.MinoOperationWithKey)15 List (java.util.List)15 Collectors (java.util.stream.Collectors)15 PermutationIterable (common.iterable.PermutationIterable)12 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)12