Search in sources :

Example 6 with OperationWithKey

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

the class OperationWithKeyInterpreterTest method parseRandom.

@Test
void parseRandom() throws Exception {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    for (int size = 1; size < 20; size++) {
        List<OperationWithKey> operations = Stream.generate(() -> {
            Piece piece = randoms.block();
            Rotate rotate = randoms.rotate();
            int x = randoms.nextInt(10);
            int y = randoms.nextInt(4);
            long deleteKey = randoms.key();
            long usingKey = randoms.key();
            return new FullOperationWithKey(minoFactory.create(piece, rotate), x, y, deleteKey, usingKey);
        }).limit(size).collect(Collectors.toList());
        String str = OperationWithKeyInterpreter.parseToString(operations);
        List<MinoOperationWithKey> actual = OperationWithKeyInterpreter.parseToList(str, minoFactory);
        assertThat(actual).isEqualTo(operations);
    }
}
Also used : Randoms(lib.Randoms) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Rotate(core.srs.Rotate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) Test(org.junit.jupiter.api.Test)

Example 7 with OperationWithKey

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

the class Search method search.

private void search(Field field, int depth) {
    if (depth == sets.getDepth()) {
        List<OperationWithKey> result = new ArrayList<>();
        for (int index = 0, length = fullLimitedMinos.length; index < length; index++) {
            FullLimitedMino limitedMino = fullLimitedMinos[index];
            int x = xs[index];
            Mino mino = limitedMino.getMino();
            long deleteKey = limitedMino.getDeleteKey();
            long usingKey = limitedMino.getUsingKey();
            int lowerY = limitedMino.getLowerY();
            OperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
            result.add(withKey);
        }
        results.add(result);
    } else {
        FullLimitedMino limitedMino = sets.get(depth);
        fullLimitedMinos[depth] = limitedMino;
        MinoMask minoMask = limitedMino.getMinoMask();
        for (int x : limitedMino.getXs()) {
            xs[depth] = x;
            Field mask = minoMask.getMinoMask(x);
            if (field.canMerge(mask)) {
                field.merge(mask);
                if (perfectValidator.validate(field, maxClearLine))
                    search(field, depth + 1);
                field.reduce(mask);
            }
        }
    }
}
Also used : FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) Field(core.field.Field) OperationWithKey(common.datastore.OperationWithKey) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoMask(searcher.pack.separable_mino.mask.MinoMask) ArrayList(java.util.ArrayList) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey)

Example 8 with OperationWithKey

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

the class BuildUpStreamTest method buildUp2.

@Test
void buildUp2() {
    // Create LockedReachable
    int height = 4;
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    // Create OperationWithKey List
    Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
    Operations operations = OperationInterpreter.parseToOperations("J,R,0,1;O,0,1,0;L,L,3,1;I,0,1,0");
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
    // Create Pieces
    Set<String> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).map(op -> op.stream().map(OperationWithKey::getPiece).map(Piece::name).collect(Collectors.joining())).collect(Collectors.toSet());
    // Assertion
    assertThat(valid).hasSize(16).doesNotContain("IJOL", "IJLO", "IOJL", "IOLJ", "ILOJ", // starts I
    "ILJO").doesNotContain("OIJL", // starts OI
    "OILJ").contains("OJLI", "OJIL", "JOIL", "JLIO", "LOJI", "LIOJ");
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) Randoms(lib.Randoms) OperationTransform(common.parser.OperationTransform) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationInterpreter(common.parser.OperationInterpreter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) FieldView(core.field.FieldView) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) LinkedList(java.util.LinkedList) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) PermutationIterable(common.iterable.PermutationIterable) Predicate(java.util.function.Predicate) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Operations(common.datastore.Operations) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) Optional(java.util.Optional) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationWithKey(common.datastore.OperationWithKey) MinoRotation(core.srs.MinoRotation) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 9 with OperationWithKey

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

the class OperationWithKeyComparatorTest method compareDiffDeleteKey.

@Test
void compareDiffDeleteKey() 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);
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    Long choose = randoms.key();
    while (choose == deleteKey) choose = randoms.key();
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, choose, 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)

Example 10 with OperationWithKey

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

the class OperationWithKeyComparatorTest method compare.

@Test
void compare() 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);
    Mino newMino = new MinoFactory().create(Piece.I, Rotate.Spawn);
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, usingKey);
    OperationWithKeyComparator comparator = new OperationWithKeyComparator();
    assertThat(comparator.compare(operationWithKey1, operationWithKey2)).as(operationWithKey1.toString()).isEqualTo(0);
    assertThat(comparator.compare(operationWithKey2, operationWithKey1)).as(operationWithKey2.toString()).isEqualTo(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

OperationWithKey (common.datastore.OperationWithKey)16 MinoFactory (core.mino.MinoFactory)9 Field (core.field.Field)8 Mino (core.mino.Mino)8 Randoms (lib.Randoms)8 Test (org.junit.jupiter.api.Test)8 FullOperationWithKey (common.datastore.FullOperationWithKey)7 Piece (core.mino.Piece)7 MinoOperationWithKey (common.datastore.MinoOperationWithKey)6 Collectors (java.util.stream.Collectors)6 SizedBit (searcher.pack.SizedBit)6 SeparableMino (searcher.pack.separable_mino.SeparableMino)6 FieldFactory (core.field.FieldFactory)5 ExecutionException (java.util.concurrent.ExecutionException)5 PerfectPackSearcher (searcher.pack.task.PerfectPackSearcher)5 Result (searcher.pack.task.Result)5 LongPieces (common.datastore.blocks.LongPieces)4 ColumnField (core.column_field.ColumnField)4 List (java.util.List)4 Stream (java.util.stream.Stream)4