Search in sources :

Example 1 with MinoMask

use of searcher.pack.separable_mino.mask.MinoMask in project solution-finder by knewjade.

the class FullOperationSeparableMino method create.

public static SeparableMino create(FullOperationWithKey operationWithKey, int upperY, int fieldHeight) {
    assert upperY <= 10 : upperY;
    Mino mino = operationWithKey.getMino();
    long deleteKey = operationWithKey.getNeedDeletedKey();
    int y = operationWithKey.getY();
    MinoMask minoMask = MinoMaskFactory.create(fieldHeight, mino, y, deleteKey);
    int x = operationWithKey.getX();
    Field mask = minoMask.getMinoMask(x);
    int lowerY = operationWithKey.getY() + operationWithKey.getMino().getMinY();
    ColumnSmallField columnField = ColumnFieldFactory.createField();
    for (int ny = lowerY; ny <= upperY; ny++) {
        for (int nx = x + mino.getMinX(); nx <= x + mino.getMaxX(); nx++) {
            if (!mask.isEmpty(nx, ny))
                columnField.setBlock(nx, ny, fieldHeight);
        }
    }
    Field field = FieldFactory.createField(fieldHeight);
    field.put(operationWithKey.getMino(), operationWithKey.getX(), operationWithKey.getY());
    field.insertWhiteLineWithKey(operationWithKey.getNeedDeletedKey());
    return new FullOperationSeparableMino(operationWithKey, columnField, field);
}
Also used : Field(core.field.Field) ColumnField(core.column_field.ColumnField) ColumnSmallField(core.column_field.ColumnSmallField) ColumnSmallField(core.column_field.ColumnSmallField) MinoMask(searcher.pack.separable_mino.mask.MinoMask) Mino(core.mino.Mino)

Example 2 with MinoMask

use of searcher.pack.separable_mino.mask.MinoMask in project solution-finder by knewjade.

the class DeleteKey method create.

public static DeleteKey create(Mino mino, long deleteKey, long usingKey, int lowerY, int upperY) {
    int y = lowerY - mino.getMinY();
    int maxHeight = upperY + 1;
    MinoMask minoMask = MinoMaskFactory.create(maxHeight, mino, y, deleteKey);
    int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
    int[][] blockCountEachLines = new int[minoHeight][2];
    int index = 0;
    for (int newY = lowerY; newY <= upperY; newY++) {
        Field mask = minoMask.getMinoMask(-mino.getMinX());
        int block = mask.getBlockCountOnY(newY);
        if (block != 0) {
            blockCountEachLines[index][0] = newY;
            blockCountEachLines[index][1] = block;
            index++;
        }
    }
    assert index == minoHeight;
    return new DeleteKey(minoMask, blockCountEachLines, lowerY, deleteKey, usingKey);
}
Also used : Field(core.field.Field) MinoMask(searcher.pack.separable_mino.mask.MinoMask)

Example 3 with MinoMask

use of searcher.pack.separable_mino.mask.MinoMask 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 4 with MinoMask

use of searcher.pack.separable_mino.mask.MinoMask 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)

Aggregations

Field (core.field.Field)4 MinoMask (searcher.pack.separable_mino.mask.MinoMask)4 Mino (core.mino.Mino)3 FullLimitedMino (_implements.parity_based_pack.step2.FullLimitedMino)2 FullOperationWithKey (common.datastore.FullOperationWithKey)2 ArrayList (java.util.ArrayList)2 MinoOperationWithKey (common.datastore.MinoOperationWithKey)1 OperationWithKey (common.datastore.OperationWithKey)1 ColumnField (core.column_field.ColumnField)1 ColumnSmallField (core.column_field.ColumnSmallField)1