Search in sources :

Example 16 with ColorConverter

use of common.tetfu.common.ColorConverter 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 17 with ColorConverter

use of common.tetfu.common.ColorConverter 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 18 with ColorConverter

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

the class MoveSettingParser method loadTetfu.

private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, MoveSettings settings) throws FinderParseException {
    // テト譜面のエンコード
    List<TetfuPage> decoded = encodeTetfu(data);
    // 指定されたページを抽出
    int page = wrapper.getIntegerOption("page").orElse(1);
    TetfuPage tetfuPage = extractTetfuPage(decoded, page);
    // コメントの抽出
    // 先頭が数字ではない(--clear-line -p *p7のようになる)場合でも、parserはエラーにならない
    // データ取得時にOptional.emptyがかえるだけ
    String comment = "--clear-line " + tetfuPage.getComment();
    List<String> splitComment = Arrays.stream(comment.split(" ")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    // コマンド引数を配列に変換
    String[] commentArgs = new String[splitComment.size()];
    splitComment.toArray(commentArgs);
    // オプションとして読み込む
    try {
        CommandLine commandLineTetfu = parseToCommandLine(options, parser, commentArgs);
        CommandLineWrapper newWrapper = new NormalCommandLineWrapper(commandLineTetfu);
        // 削除ラインが読み取れればOK
        newWrapper.getIntegerOption("clear-line");
        wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
    } catch (FinderParseException ignore) {
    }
    // 最大削除ラインの設定
    Optional<Integer> maxClearLineOption = wrapper.getIntegerOption("clear-line");
    maxClearLineOption.ifPresent(settings::setMaxClearLine);
    // フィールドを設定
    ColoredField coloredField = tetfuPage.getField();
    if (tetfuPage.isPutMino()) {
        ColorType colorType = tetfuPage.getColorType();
        Rotate rotate = tetfuPage.getRotate();
        int x = tetfuPage.getX();
        int y = tetfuPage.getY();
        ColorConverter colorConverter = new ColorConverter();
        Mino mino = new Mino(colorConverter.parseToBlock(colorType), rotate);
        coloredField.putMino(mino, x, y);
    }
    settings.setField(coloredField);
    return wrapper;
}
Also used : TetfuPage(common.tetfu.TetfuPage) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Files(java.nio.file.Files) org.apache.commons.cli(org.apache.commons.cli) IOException(java.io.IOException) Tetfu(common.tetfu.Tetfu) FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) List(java.util.List) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Charset(java.nio.charset.Charset) Paths(java.nio.file.Paths) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) Optional(java.util.Optional) CommandLineWrapper(entry.CommandLineWrapper) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) FinderParseException(exceptions.FinderParseException) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) CommandLineWrapper(entry.CommandLineWrapper) ColorType(common.tetfu.common.ColorType) ColorConverter(common.tetfu.common.ColorConverter) Mino(core.mino.Mino) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper)

Example 19 with ColorConverter

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

the class SetupSettingParser method encodeTetfu.

private List<TetfuPage> encodeTetfu(String encoded) throws FinderParseException {
    MinoFactory minoFactory = new MinoFactory();
    ColorConverter colorConverter = new ColorConverter();
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    String data = Tetfu.removePrefixData(encoded);
    if (data == null)
        throw new FinderParseException("Unsupported tetfu: data=" + encoded);
    return tetfu.decode(data);
}
Also used : FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu)

Example 20 with ColorConverter

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

the class FigUtilSettingParser method encodeTetfu.

private List<TetfuPage> encodeTetfu(String encoded) throws FinderParseException {
    MinoFactory minoFactory = new MinoFactory();
    ColorConverter colorConverter = new ColorConverter();
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    String data = Tetfu.removePrefixData(encoded);
    if (data == null)
        throw new FinderParseException("Unsupported tetfu: data=" + encoded);
    return tetfu.decode(data);
}
Also used : FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu)

Aggregations

ColorConverter (common.tetfu.common.ColorConverter)38 MinoFactory (core.mino.MinoFactory)36 LongTest (module.LongTest)18 Test (org.junit.jupiter.api.Test)18 Tetfu (common.tetfu.Tetfu)13 ColoredField (common.tetfu.field.ColoredField)11 ColorType (common.tetfu.common.ColorType)10 FinderParseException (exceptions.FinderParseException)10 Field (core.field.Field)9 Piece (core.mino.Piece)8 Mino (core.mino.Mino)7 Rotate (core.srs.Rotate)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 TetfuPage (common.tetfu.TetfuPage)6 ColoredFieldFactory (common.tetfu.field.ColoredFieldFactory)6 IOException (java.io.IOException)6 Arrays (java.util.Arrays)5 Optional (java.util.Optional)5 BlockField (common.datastore.BlockField)4