Search in sources :

Example 81 with Mino

use of core.mino.Mino 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 82 with Mino

use of core.mino.Mino 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 83 with Mino

use of core.mino.Mino 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 84 with Mino

use of core.mino.Mino 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 85 with Mino

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

Mino (core.mino.Mino)103 Test (org.junit.jupiter.api.Test)46 Rotate (core.srs.Rotate)27 Field (core.field.Field)24 Piece (core.mino.Piece)20 Randoms (lib.Randoms)16 MinoFactory (core.mino.MinoFactory)14 ColorType (common.tetfu.common.ColorType)12 ColoredField (common.tetfu.field.ColoredField)12 ArrayList (java.util.ArrayList)12 FullOperationWithKey (common.datastore.FullOperationWithKey)9 HashSet (java.util.HashSet)9 ColorConverter (common.tetfu.common.ColorConverter)8 OriginalPiece (core.neighbor.OriginalPiece)8 List (java.util.List)8 MinoOperationWithKey (common.datastore.MinoOperationWithKey)7 OperationWithKey (common.datastore.OperationWithKey)7 TetfuPage (common.tetfu.TetfuPage)7 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7