Search in sources :

Example 6 with FullOperationWithKey

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

the class CrossBuilder method recordResult.

private void recordResult() {
    boolean isReuse = true;
    for (int index = 0; index < prev.length; index++) {
        if (!isReuse || fullLimitedMinos[index] != prev[index]) {
            isReuse = false;
            List<XField> xFields = cache.get(index);
            List<XField> nextXFields = new ArrayList<>();
            for (XField xField : xFields) {
                Field field = xField.getField();
                XHistory xHistory = xField.getxHistory();
                FullLimitedMino current = fullLimitedMinos[index];
                MinoMask minoMask = current.getMinoMask();
                int[] xs = current.getXs();
                for (int x : xs) {
                    Field mask = minoMask.getMinoMask(x);
                    if (field.canMerge(mask)) {
                        Field newField = field.freeze(maxClearLine);
                        newField.merge(mask);
                        if (perfectValidator.validate(newField, maxClearLine)) {
                            XHistory newHistory = xHistory.recordAndReturnNew(x);
                            nextXFields.add(new XField(newField, newHistory));
                        }
                    }
                }
            }
            if (index < prev.length - 1) {
                cache.set(index + 1, nextXFields);
            } else {
                for (XField nextXField : nextXFields) {
                    int[] history = nextXField.getxHistory().getHistory();
                    assert fullLimitedMinos.length == history.length;
                    List<MinoOperationWithKey> result = new ArrayList<>();
                    for (int i = 0, length = history.length; i < length; i++) {
                        FullLimitedMino limitedMino = fullLimitedMinos[i];
                        int x = history[i];
                        Mino mino = limitedMino.getMino();
                        long deleteKey = limitedMino.getDeleteKey();
                        long usingKey = limitedMino.getUsingKey();
                        int lowerY = limitedMino.getLowerY();
                        MinoOperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
                        result.add(withKey);
                    }
                    results.add(result);
                }
            }
            prev[index] = fullLimitedMinos[index];
        }
    }
}
Also used : FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) ArrayList(java.util.ArrayList) FullOperationWithKey(common.datastore.FullOperationWithKey) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) MinoMask(searcher.pack.separable_mino.mask.MinoMask) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) Mino(core.mino.Mino)

Example 7 with FullOperationWithKey

use of common.datastore.FullOperationWithKey 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 FullOperationWithKey

use of common.datastore.FullOperationWithKey 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 9 with FullOperationWithKey

use of common.datastore.FullOperationWithKey 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)

Example 10 with FullOperationWithKey

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

the class OperationWithKeyComparatorTest method compareDiffUsingKey.

@Test
void compareDiffUsingKey() 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();
    OperationWithKey operationWithKey2 = createNewOperationWithKey(newMino, x, y, deleteKey, choose);
    // assert is 0
    OperationWithKeyComparator<OperationWithKey> comparator = new OperationWithKeyComparator<>();
    int compare1 = comparator.compare(operationWithKey1, operationWithKey2);
    assertThat(compare1).as(operationWithKey1.toString()).isEqualTo(0);
    int compare2 = comparator.compare(operationWithKey2, operationWithKey1);
    assertThat(compare2).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

FullOperationWithKey (common.datastore.FullOperationWithKey)13 Mino (core.mino.Mino)9 OperationWithKey (common.datastore.OperationWithKey)8 MinoFactory (core.mino.MinoFactory)7 Randoms (lib.Randoms)7 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)5 MinoOperationWithKey (common.datastore.MinoOperationWithKey)3 CombinationIterable (common.iterable.CombinationIterable)3 Piece (core.mino.Piece)3 Rotate (core.srs.Rotate)3 FullLimitedMino (_implements.parity_based_pack.step2.FullLimitedMino)2 Field (core.field.Field)2 MinoMask (searcher.pack.separable_mino.mask.MinoMask)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1