Search in sources :

Example 66 with Mino

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

the class OperationTransform method parseToBlockField.

public static <T extends OperationWithKey> BlockField parseToBlockField(List<T> operationWithKeys, MinoFactory minoFactory, int height) {
    BlockField blockField = new BlockField(height);
    operationWithKeys.forEach(key -> {
        Field test = FieldFactory.createField(height);
        Mino mino = minoFactory.create(key.getPiece(), key.getRotate());
        test.put(mino, key.getX(), key.getY());
        test.insertWhiteLineWithKey(key.getNeedDeletedKey());
        blockField.merge(test, mino.getPiece());
    });
    return blockField;
}
Also used : Field(core.field.Field) Mino(core.mino.Mino)

Example 67 with Mino

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

the class OperationWithKeyInterpreter method parseToStream.

public static Stream<MinoOperationWithKey> parseToStream(String operations, MinoFactory minoFactory) {
    return Arrays.stream(operations.split(";")).map(s -> s.split(",")).map(strings -> {
        Piece piece = StringEnumTransform.toPiece(strings[0]);
        Rotate rotate = StringEnumTransform.toRotate(strings[1]);
        Mino mino = minoFactory.create(piece, rotate);
        int x = Integer.valueOf(strings[2]);
        int y = Integer.valueOf(strings[3]);
        long deleteKey = Long.valueOf(strings[4]);
        long usingKey = Long.valueOf(strings[5]);
        return new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
    });
}
Also used : OperationWithKey(common.datastore.OperationWithKey) Piece(core.mino.Piece) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) Mino(core.mino.Mino) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey)

Example 68 with Mino

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

the class AbstractAllOperationFactory method create.

public Set<T> create() {
    HashSet<T> 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<T> 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 69 with Mino

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

the class BuildUp method existsValidByOrder.

private static boolean existsValidByOrder(Field field, EnumMap<Piece, LinkedList<MinoOperationWithKey>> eachBlocks, List<Piece> pieces, int height, Reachable reachable, int depth) {
    long deleteKey = field.clearLineReturnKey();
    Piece piece = pieces.get(depth);
    LinkedList<MinoOperationWithKey> operationWithKeys = eachBlocks.get(piece);
    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 (pieces.size() == depth + 1)
                return true;
            Field nextField = field.freeze(height);
            nextField.put(mino, x, y);
            nextField.insertBlackLineWithKey(deleteKey);
            boolean exists = existsValidByOrder(nextField, eachBlocks, pieces, height, reachable, depth + 1);
            if (exists)
                return true;
        }
        operationWithKeys.add(index, key);
    }
    field.insertBlackLineWithKey(deleteKey);
    return false;
}
Also used : Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Piece(core.mino.Piece) Mino(core.mino.Mino)

Example 70 with Mino

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

the class BuildUpStream method existsValidBuildPatternRecursive.

private void existsValidBuildPatternRecursive(Field field, LinkedList<MinoOperationWithKey> operationWithKeys) {
    long deleteKey = field.clearLineReturnKey();
    for (int index = 0; index < operationWithKeys.size(); index++) {
        MinoOperationWithKey key = operationWithKeys.remove(index);
        this.currentOperations.addLast(key);
        // 必要な列が消えているかチェック
        long needDeletedKey = key.getNeedDeletedKey();
        if ((deleteKey & needDeletedKey) == needDeletedKey) {
            // すでに下のラインが消えているときは、その分スライドさせる
            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)) {
                if (operationWithKeys.isEmpty()) {
                    // 解をみつけたとき
                    solutions.accept(new ArrayList<>(currentOperations));
                } else {
                    Field nextField = field.freeze(height);
                    nextField.put(mino, x, y);
                    nextField.insertBlackLineWithKey(deleteKey);
                    existsValidBuildPatternRecursive(nextField, operationWithKeys);
                }
            }
        }
        this.currentOperations.removeLast();
        operationWithKeys.add(index, key);
    }
    field.insertBlackLineWithKey(deleteKey);
}
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