Search in sources :

Example 76 with Mino

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

the class FieldOnlyFigGenerator method updateMino.

@Override
public void updateMino(ColorType colorType, Rotate rotate, int xIndex, int yIndex) {
    Piece piece = colorConverter.parseToBlock(colorType);
    Mino mino = minoFactory.create(piece, rotate);
    FigColor figColor = FigColor.parse(colorType);
    Color color = figColor.getStrongColor();
    graphics.setColor(color);
    for (int[] positions : mino.getPositions()) {
        Rectangle rectangle = positionDecider.getInField(xIndex + positions[0], yIndex + positions[1]);
        fillRect(rectangle);
    }
}
Also used : Piece(core.mino.Piece) FigColor(util.fig.FigColor) FigColor(util.fig.FigColor) Rectangle(util.fig.Rectangle) Mino(core.mino.Mino)

Example 77 with Mino

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

the class GifWriter method write.

@Override
public void write(List<TetfuPage> tetfuPages) throws IOException {
    boolean isLoop = isInfiniteLoop;
    try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(outputFile)) {
        // imageWriterの準備
        ImageWriter imageWriter = getGifImageWriter();
        imageWriter.setOutput(imageOutputStream);
        imageWriter.prepareWriteSequence(null);
        for (TetfuPage tetfuPage : tetfuPages) {
            // リセット
            figGenerator.reset();
            // 現在のミノを取得
            ColorType colorType = tetfuPage.getColorType();
            Rotate rotate = tetfuPage.getRotate();
            Mino mino = ColorType.isMinoBlock(colorType) ? minoFactory.create(colorConverter.parseToBlock(colorType), rotate) : null;
            int x = tetfuPage.getX();
            int y = tetfuPage.getY();
            // フィールドの更新
            ColoredField field = tetfuPage.getField();
            figGenerator.updateField(field, mino, x, y);
            // ミノを置くかチェック
            if (ColorType.isMinoBlock(colorType)) {
                // 現在のミノの更新
                figGenerator.updateMino(colorType, rotate, x, y);
                // bagの更新
                Piece piece = colorConverter.parseToBlock(colorType);
                bag.use(piece);
            }
            // ネクストの更新
            figGenerator.updateNext(bag.getNext(nextBoxCount));
            // ホールドの更新
            figGenerator.updateHold(bag.getHold());
            // 画像の生成
            BufferedImage image = figGenerator.fix();
            // メタデータの作成
            IIOMetadata metadata = createMetadata(imageWriter, image, delay, isLoop);
            IIOImage iioImage = new IIOImage(image, null, metadata);
            imageWriter.writeToSequence(iioImage, null);
            // 無限ループの設定は最大1度までで十分
            isLoop = false;
        }
        // imageWriterの終了処理
        imageWriter.endWriteSequence();
    }
}
Also used : TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) BufferedImage(java.awt.image.BufferedImage) IIOMetadata(javax.imageio.metadata.IIOMetadata) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino) ImageOutputStream(javax.imageio.stream.ImageOutputStream)

Example 78 with Mino

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

the class DeleteKeyParser method initializeMaps.

private EnumMap<Piece, EnumMap<Rotate, List<DeleteKey>>> initializeMaps(MinoFactory minoFactory, int maxClearLine) {
    EnumMap<Piece, EnumMap<Rotate, List<DeleteKey>>> maps = new EnumMap<>(Piece.class);
    for (Piece piece : Piece.values()) {
        EnumMap<Rotate, List<DeleteKey>> rotateMaps = maps.computeIfAbsent(piece, blk -> new EnumMap<>(Rotate.class));
        for (Rotate rotate : Rotate.values()) {
            Mino mino = minoFactory.create(piece, rotate);
            // ミノの高さを計算
            int minoHeight = mino.getMaxY() - mino.getMinY() + 1;
            // 行候補をリストにする
            ArrayList<Integer> lineIndexes = new ArrayList<>();
            for (int index = 0; index < maxClearLine; index++) lineIndexes.add(index);
            // ブロックが置かれる行を選択する
            CombinationIterable<Integer> combinationIterable = new CombinationIterable<>(lineIndexes, minoHeight);
            // リストアップ
            ArrayList<DeleteKey> deleteLimitedMinos = new ArrayList<>();
            for (List<Integer> indexes : combinationIterable) {
                // ソートする
                indexes.sort(Integer::compare);
                // 一番下の行と一番上の行を取得
                int lowerY = indexes.get(0);
                int upperY = indexes.get(indexes.size() - 1);
                // ミノに挟まれる全ての行を含むdeleteKey
                long deleteKey = KeyOperators.getMaskForKeyAboveY(lowerY) & KeyOperators.getMaskForKeyBelowY(upperY + 1);
                long usingKey = 0L;
                assert Long.bitCount(deleteKey) == upperY - lowerY + 1;
                for (Integer index : indexes) {
                    long bitKey = KeyOperators.getDeleteBitKey(index);
                    // ブロックのある行のフラグを取り消す
                    deleteKey &= ~bitKey;
                    // ブロックのある行のフラグをたてる
                    usingKey |= bitKey;
                }
                assert Long.bitCount(deleteKey) + indexes.size() == upperY - lowerY + 1;
                deleteLimitedMinos.add(DeleteKey.create(mino, deleteKey, usingKey, lowerY, upperY));
            }
            rotateMaps.put(rotate, deleteLimitedMinos);
        }
    }
    return maps;
}
Also used : Rotate(core.srs.Rotate) ArrayList(java.util.ArrayList) CombinationIterable(common.iterable.CombinationIterable) Piece(core.mino.Piece) Mino(core.mino.Mino) List(java.util.List) ArrayList(java.util.ArrayList) EnumMap(java.util.EnumMap)

Example 79 with Mino

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

the class FullLimitedMinos method compareToMino.

private int compareToMino(FullLimitedMino o1, FullLimitedMino o2) {
    Mino mino = o1.getMino();
    Mino oMino = o2.getMino();
    int block = mino.getPiece().compareTo(oMino.getPiece());
    if (block != 0)
        return block;
    int rotate = mino.getRotate().compareTo(oMino.getRotate());
    if (rotate != 0)
        return rotate;
    int position = o1.getPositionLimit().compareTo(o2.getPositionLimit());
    if (position != 0)
        return position;
    int deleteKey = Long.compare(o1.getDeleteKey(), o2.getDeleteKey());
    if (deleteKey != 0)
        return deleteKey;
    return Integer.compare(o1.getLowerY(), o2.getLowerY());
}
Also used : Mino(core.mino.Mino)

Example 80 with Mino

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

the class PositionLimitParser method createLJ.

private List<PositionLimitedMino> createLJ(Piece piece, DeltaLimit delta) {
    Mino spawn = minoFactory.create(piece, Rotate.Spawn);
    Mino reverse = minoFactory.create(piece, Rotate.Reverse);
    Mino left = minoFactory.create(piece, Rotate.Left);
    Mino right = minoFactory.create(piece, Rotate.Right);
    switch(delta) {
        case OddUp:
            return Arrays.asList(PositionLimitedMino.create(spawn, PositionLimit.EvenX), PositionLimitedMino.create(reverse, PositionLimit.EvenX), PositionLimitedMino.create(left, PositionLimit.OddX), PositionLimitedMino.create(right, PositionLimit.OddX));
        case EvenUp:
            return Arrays.asList(PositionLimitedMino.create(spawn, PositionLimit.OddX), PositionLimitedMino.create(reverse, PositionLimit.OddX), PositionLimitedMino.create(left, PositionLimit.EvenX), PositionLimitedMino.create(right, PositionLimit.EvenX));
    }
    throw new IllegalStateException("No reachable");
}
Also used : DeltaLimitedMino(_implements.parity_based_pack.step1.DeltaLimitedMino) 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