Search in sources :

Example 6 with ColoredField

use of common.tetfu.field.ColoredField in project solution-finder by knewjade.

the class PathSettings method setField.

void setField(ColoredField coloredField, int height) {
    Field field = FieldFactory.createField(height);
    for (int y = 0; y < height; y++) for (int x = 0; x < 10; x++) if (coloredField.getColorType(x, y) != ColorType.Empty)
        field.setBlock(x, y);
    setField(field);
    setReservedBlock(null);
}
Also used : Field(core.field.Field) BlockField(common.datastore.BlockField) ColoredField(common.tetfu.field.ColoredField)

Example 7 with ColoredField

use of common.tetfu.field.ColoredField in project solution-finder by knewjade.

the class PathSettings method setFieldWithReserved.

void setFieldWithReserved(ColoredField coloredField, int height) {
    Field field = FieldFactory.createField(height);
    BlockField blockField = new BlockField(height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < 10; x++) {
            ColorConverter colorConverter = new ColorConverter();
            ColorType colorType = colorConverter.parseToColorType(coloredField.getBlockNumber(x, y));
            switch(colorType) {
                case Empty:
                    break;
                case Gray:
                    field.setBlock(x, y);
                    break;
                default:
                    Piece piece = colorConverter.parseToBlock(colorType);
                    blockField.setBlock(piece, x, y);
                    break;
            }
        }
    }
    setField(field);
    setReservedBlock(blockField);
}
Also used : Field(core.field.Field) BlockField(common.datastore.BlockField) ColoredField(common.tetfu.field.ColoredField) BlockField(common.datastore.BlockField) Piece(core.mino.Piece) ColorConverter(common.tetfu.common.ColorConverter) ColorType(common.tetfu.common.ColorType)

Example 8 with ColoredField

use of common.tetfu.field.ColoredField in project solution-finder by knewjade.

the class FigUtilSettings method adjust.

void adjust() {
    // Quizがない場合はホールドは使えない
    boolean isUsingQuiz = tetfuPages.subList(0, startPage).stream().map(TetfuPage::getComment).anyMatch(s -> s.startsWith("#Q="));
    if (!isUsingQuiz)
        setUsingHold(false);
    // 高さの指定がないときは最も高い場所 + 1とする
    if (this.height == -1) {
        MinoFactory minoFactory = new MinoFactory();
        ColorConverter colorConverter = new ColorConverter();
        OptionalInt maxHeight = tetfuPages.subList(startPage - 1, endPage).stream().mapToInt(page -> {
            ColoredField field = page.getField();
            int fieldHeight = field.getUsingHeight();
            ColorType colorType = page.getColorType();
            if (ColorType.isMinoBlock(colorType)) {
                Piece piece = colorConverter.parseToBlock(colorType);
                Rotate rotate = page.getRotate();
                Mino mino = minoFactory.create(piece, rotate);
                int minoHeight = page.getY() + mino.getMaxY() + 1;
                return fieldHeight < minoHeight ? minoHeight : fieldHeight;
            } else {
                return fieldHeight;
            }
        }).max();
        this.height = maxHeight.orElse(0) + 1;
        if (height <= 0)
            this.height = 1;
        else if (23 <= height)
            this.height = 23;
    }
    // ホールドを使わない場合はRightに変更
    if (!this.isUsingHold && frameType == FrameType.Basic) {
        frameType = FrameType.Right;
    }
    // ネクストがない場合はチェックは必要がない
    if (frameType == FrameType.NoFrame) {
        return;
    }
    // フィールドの高さを計算し、その高さで置けるネクスト数を計算
    int fieldHeight = 34 * this.height + 2;
    int canPutCount = (fieldHeight - 5) / 52;
    // ネクスト (& ホールド)で必要な個数を算出し、ネクストを置けるならチェック終了
    int count = this.isUsingHold && frameType == FrameType.Right ? nextBoxCount + 1 : nextBoxCount;
    if (count <= canPutCount)
        return;
    // ネクストを置けるようにフィールドの高さを調整
    int needHeightPx = 52 * count + 5;
    setHeight((int) Math.ceil((needHeightPx - 2) / 34.0));
}
Also used : TetfuPage(common.tetfu.TetfuPage) Piece(core.mino.Piece) List(java.util.List) ColorType(common.tetfu.common.ColorType) MinoFactory(core.mino.MinoFactory) FrameType(util.fig.FrameType) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) OptionalInt(java.util.OptionalInt) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) ArrayList(java.util.ArrayList) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) Piece(core.mino.Piece) ColorConverter(common.tetfu.common.ColorConverter) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino) MinoFactory(core.mino.MinoFactory) OptionalInt(java.util.OptionalInt)

Example 9 with ColoredField

use of common.tetfu.field.ColoredField in project solution-finder by knewjade.

the class EasyTetfu method parseBlockFieldToTetfuElement.

private TetfuElement parseBlockFieldToTetfuElement(Field initField, ColorConverter colorConverter, BlockField blockField, String comment) {
    ColoredField coloredField = ColoredFieldFactory.createGrayField(initField);
    for (Piece piece : Piece.values()) {
        Field target = blockField.get(piece);
        ColorType colorType = colorConverter.parseToColorType(piece);
        fillInField(coloredField, colorType, target);
    }
    return new TetfuElement(coloredField, ColorType.Empty, Rotate.Reverse, 0, 0, comment);
}
Also used : BlockField(common.datastore.BlockField) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) TetfuElement(common.tetfu.TetfuElement)

Example 10 with ColoredField

use of common.tetfu.field.ColoredField in project solution-finder by knewjade.

the class Tetfu method decodeMain.

private List<TetfuPage> decodeMain(String str) {
    LinkedList<Integer> values = str.replace("?", "").chars().boxed().map(c -> decodeData((char) c.intValue())).collect(Collectors.toCollection(LinkedList::new));
    ArrayList<TetfuPage> pages = new ArrayList<>();
    ColoredField prevField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
    ColoredField currentField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
    int[] blockUp = new int[FILED_WIDTH];
    int repeatCount = -1;
    while (!values.isEmpty()) {
        if (repeatCount <= 0) {
            int index = 0;
            boolean isChange = false;
            while (index < TETFU_FIELD_BLOCKS) {
                int diffBlock = pollValues(values, 2);
                int diff = diffBlock / TETFU_FIELD_BLOCKS;
                int block = diffBlock % TETFU_FIELD_BLOCKS;
                if (block != TETFU_FIELD_BLOCKS - 1)
                    isChange = true;
                for (int b = 0; b < block + 1; b++) {
                    int x = index % 10;
                    int y = TETFU_FIELD_TOP - (index / 10) - 1;
                    if (0 <= y) {
                        int prevBlockNumber = prevField.getBlockNumber(x, y);
                        currentField.setBlockNumber(x, y, diff + prevBlockNumber - 8);
                    } else {
                        blockUp[x] += diff - 8;
                    }
                    index += 1;
                }
            }
            if (!isChange)
                repeatCount = pollValues(values, 1);
        } else {
            currentField = prevField;
            repeatCount -= 1;
        }
        int action = pollValues(values, 3);
        ActionDecoder actionDecoder = new ActionDecoder(action);
        String escapedComment = "";
        if (actionDecoder.isComment) {
            List<Integer> commentValues = new ArrayList<>();
            int commentLength = pollValues(values, 2);
            for (int commentCounter = 0; commentCounter < (commentLength + 3) / 4; commentCounter++) {
                int commentValue = pollValues(values, 5);
                commentValues.add(commentValue);
            }
            CommentDecoder commentDecoder = new CommentDecoder(commentLength, commentValues);
            escapedComment = commentDecoder.getEscapedComment();
        }
        TetfuPage tetfuPage = new DecodedTetfuPage(actionDecoder, escapedComment, currentField);
        pages.add(tetfuPage);
        ColorType colorType = actionDecoder.colorType;
        if (actionDecoder.isLock) {
            if (ColorType.isMinoBlock(colorType)) {
                Rotate rotate = actionDecoder.rotate;
                Coordinate coordinate = actionDecoder.coordinate;
                Piece piece = converter.parseToBlock(colorType);
                Mino mino = minoFactory.create(piece, rotate);
                currentField.putMino(mino, coordinate.x, coordinate.y);
            }
            currentField.clearLine();
            if (actionDecoder.isBlockUp) {
                currentField.blockUp();
                for (int x = 0; x < TETFU_FIELD_WIDTH; x++) currentField.setBlockNumber(x, 0, blockUp[x]);
            }
            if (actionDecoder.isMirror)
                currentField.mirror();
        }
        prevField = currentField;
    }
    return pages;
}
Also used : CommentDecoder(common.tetfu.decorder.CommentDecoder) Piece(core.mino.Piece) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) ActionFlags(common.tetfu.common.ActionFlags) ActionDecoder(common.tetfu.decorder.ActionDecoder) CommentEncoder(common.tetfu.encorder.CommentEncoder) FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) ENCODE_TABLE_SIZE(common.tetfu.TetfuTable.ENCODE_TABLE_SIZE) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) FieldEncoder(common.tetfu.encorder.FieldEncoder) Coordinate(common.tetfu.common.Coordinate) LinkedList(java.util.LinkedList) ColoredField(common.tetfu.field.ColoredField) TetfuTable.decodeData(common.tetfu.TetfuTable.decodeData) ActionEncoder(common.tetfu.encorder.ActionEncoder) Mino(core.mino.Mino) ColoredField(common.tetfu.field.ColoredField) ActionDecoder(common.tetfu.decorder.ActionDecoder) Rotate(core.srs.Rotate) ArrayList(java.util.ArrayList) CommentDecoder(common.tetfu.decorder.CommentDecoder) Coordinate(common.tetfu.common.Coordinate) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino)

Aggregations

ColoredField (common.tetfu.field.ColoredField)30 ColorType (common.tetfu.common.ColorType)19 Field (core.field.Field)12 Piece (core.mino.Piece)11 ColorConverter (common.tetfu.common.ColorConverter)10 Mino (core.mino.Mino)10 MinoFactory (core.mino.MinoFactory)9 Rotate (core.srs.Rotate)9 TetfuPage (common.tetfu.TetfuPage)8 List (java.util.List)8 Tetfu (common.tetfu.Tetfu)7 FinderParseException (exceptions.FinderParseException)7 LinkedList (java.util.LinkedList)7 Collectors (java.util.stream.Collectors)7 TetfuElement (common.tetfu.TetfuElement)6 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)6 CommandLineWrapper (entry.CommandLineWrapper)6 NormalCommandLineWrapper (entry.NormalCommandLineWrapper)6 PriorityCommandLineWrapper (entry.PriorityCommandLineWrapper)6 IOException (java.io.IOException)6