Search in sources :

Example 1 with Mino

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

the class SimpleSearcherCore method step.

private void step(Candidate<T> candidate, Piece drawn, Piece nextHold, Order order, boolean isLast) {
    Field currentField = order.getField();
    int max = order.getMaxClearLine();
    Set<T> candidateList = candidate.search(currentField, drawn, max);
    OperationHistory history = order.getHistory();
    for (T action : candidateList) {
        Field field = currentField.freeze(max);
        Mino mino = minoFactory.create(drawn, action.getRotate());
        field.put(mino, action.getX(), action.getY());
        int clearLine = field.clearLine();
        int maxClearLine = max - clearLine;
        if (!validator.validate(field, maxClearLine))
            continue;
        if (validator.satisfies(field, maxClearLine)) {
            Result result = new Result(order, drawn, action, nextHold);
            dataPool.addResult(result);
            continue;
        }
        if (isLast)
            continue;
        OperationHistory nextHistory = history.recordAndReturnNew(drawn, action);
        Order nextOrder = new NormalOrder(field, nextHold, maxClearLine, nextHistory);
        dataPool.addOrder(nextOrder);
    }
}
Also used : Order(common.datastore.order.Order) NormalOrder(common.datastore.order.NormalOrder) Field(core.field.Field) NormalOrder(common.datastore.order.NormalOrder) Mino(core.mino.Mino) OperationHistory(common.OperationHistory) Result(common.datastore.Result)

Example 2 with Mino

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

the class AllSeparableMinoFactory method create.

public Set<SeparableMino> create() {
    HashSet<SeparableMino> pieces = new HashSet<>();
    HashSet<Mino> createdCheckSet = new HashSet<>();
    for (Piece piece : Piece.values()) {
        for (Rotate originRotate : Rotate.values()) {
            Rotate rotate = minoShifter.createTransformedRotate(piece, originRotate);
            Mino mino = minoFactory.create(piece, rotate);
            // 追加済みかチェック
            if (createdCheckSet.contains(mino))
                continue;
            createdCheckSet.add(mino);
            // ミノの高さを計算
            int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
            // フィールドの高さ以上にミノを使う場合はおけない
            if (fieldHeight < minoHeight)
                continue;
            // 行候補をリストにする
            ArrayList<Integer> lineIndexes = getLineIndexes(fieldHeight);
            // リストアップ
            ArrayList<SeparableMino> piecesEachMino = generatePiecesEachMino(mino, lineIndexes, minoHeight);
            // 追加
            pieces.addAll(piecesEachMino);
        }
    }
    return pieces;
}
Also used : Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Example 3 with Mino

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

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

the class BuildUp method cansBuild.

// 指定した手順で組み立てられるか確認
public static boolean cansBuild(Field fieldOrigin, List<MinoOperationWithKey> operationWithKeys, int height, Reachable reachable) {
    Field field = fieldOrigin.freeze(height);
    for (MinoOperationWithKey operationWithKey : operationWithKeys) {
        long deleteKey = field.clearLineReturnKey();
        long needDeletedKey = operationWithKey.getNeedDeletedKey();
        if ((deleteKey & needDeletedKey) != needDeletedKey) {
            // 必要な列が消えていない
            return false;
        }
        // すでに下のラインが消えているときは、その分スライドさせる
        int originalY = operationWithKey.getY();
        int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
        Mino mino = operationWithKey.getMino();
        int x = operationWithKey.getX();
        int y = originalY - deletedLines;
        if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height)) {
            field.put(mino, x, y);
            field.insertBlackLineWithKey(deleteKey);
        } else {
            return false;
        }
    }
    return true;
}
Also used : Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Mino(core.mino.Mino)

Example 5 with Mino

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

the class BuildUp method existsValidBuildPatternRecursive.

private static boolean existsValidBuildPatternRecursive(Field field, LinkedList<MinoOperationWithKey> operationWithKeys, int height, Reachable reachable) {
    long deleteKey = field.clearLineReturnKey();
    for (int index = 0; index < operationWithKeys.size(); index++) {
        MinoOperationWithKey key = operationWithKeys.remove(index);
        long needDeletedKey = key.getNeedDeletedKey();
        if ((deleteKey & needDeletedKey) != needDeletedKey) {
            // 必要な列が消えていない
            operationWithKeys.add(index, key);
            continue;
        }
        // すでに下のラインが消えているときは、その分スライドさせる
        int originalY = key.getY();
        int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
        Mino mino = key.getMino();
        int x = key.getX();
        int y = originalY - deletedLines;
        if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height - mino.getMinY())) {
            if (operationWithKeys.isEmpty())
                return true;
            Field nextField = field.freeze(height);
            nextField.put(mino, x, y);
            nextField.insertBlackLineWithKey(deleteKey);
            boolean exists = existsValidBuildPatternRecursive(nextField, operationWithKeys, height, reachable);
            if (exists)
                return true;
        }
        operationWithKeys.add(index, key);
    }
    field.insertBlackLineWithKey(deleteKey);
    return false;
}
Also used : Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Mino(core.mino.Mino)

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