Search in sources :

Example 21 with ColoredField

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

the class FieldOnlyFigGenerator method updateField.

@Override
public void updateField(ColoredField field, Mino mino, int x, int y) {
    ColoredField freeze = field.freeze(field.getMaxHeight());
    if (mino != null)
        freeze.putMino(mino, x, y);
    int heightBlock = setting.getFieldHeightBlock();
    int widthBlock = setting.getFieldWidthBlock();
    for (int yIndex = 0; yIndex < heightBlock; yIndex++) {
        boolean isFilledLine = freeze.isFilledLine(yIndex);
        for (int xIndex = 0; xIndex < widthBlock; xIndex++) {
            ColorType type = field.getColorType(xIndex, yIndex);
            FigColor figColor = FigColor.parse(type);
            Color color = getColor(figColor, isFilledLine);
            graphics.setColor(color);
            Rectangle rectangle = positionDecider.getInField(xIndex, yIndex);
            fillRect(rectangle);
        }
    }
}
Also used : ColoredField(common.tetfu.field.ColoredField) FigColor(util.fig.FigColor) FigColor(util.fig.FigColor) Rectangle(util.fig.Rectangle) ColorType(common.tetfu.common.ColorType)

Example 22 with ColoredField

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

the class NoHoldFigGenerator method updateField.

@Override
public void updateField(ColoredField field, Mino mino, int x, int y) {
    ColoredField freeze = field.freeze(field.getMaxHeight());
    if (mino != null)
        freeze.putMino(mino, x, y);
    int heightBlock = setting.getFieldHeightBlock();
    int widthBlock = setting.getFieldWidthBlock();
    for (int yIndex = 0; yIndex < heightBlock; yIndex++) {
        boolean isFilledLine = freeze.isFilledLine(yIndex);
        for (int xIndex = 0; xIndex < widthBlock; xIndex++) {
            ColorType type = field.getColorType(xIndex, yIndex);
            FigColor figColor = FigColor.parse(type);
            Color color = getColor(figColor, isFilledLine);
            graphics.setColor(color);
            Rectangle rectangle = positionDecider.getInField(xIndex, yIndex);
            fillRect(rectangle);
        }
    }
}
Also used : ColoredField(common.tetfu.field.ColoredField) FigColor(util.fig.FigColor) FigColor(util.fig.FigColor) Rectangle(util.fig.Rectangle) ColorType(common.tetfu.common.ColorType)

Example 23 with ColoredField

use of common.tetfu.field.ColoredField 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 24 with ColoredField

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

the class PathSettingParser method loadTetfu.

private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PathSettings 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<Boolean> reservedOption = wrapper.getBoolOption("reserved");
    reservedOption.ifPresent(settings::setReserved);
    // 最大削除ラインの設定
    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);
    }
    if (settings.isReserved())
        settings.setFieldWithReserved(coloredField, settings.getMaxClearLine());
    else
        settings.setField(coloredField, settings.getMaxClearLine());
    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 25 with ColoredField

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

the class LinkPathOutput method outputOperationsToSimpleHTML.

private void outputOperationsToSimpleHTML(Field field, MyFile file, List<PathPair> pathPairs, SizedBit sizedBit) throws FinderExecuteException {
    // Get height
    int maxClearLine = sizedBit.getHeight();
    // テト譜用のフィールド作成
    ColoredField initField = ColoredFieldFactory.createField(24);
    for (int y = 0; y < maxClearLine; y++) for (int x = 0; x < 10; x++) if (!field.isEmpty(x, y))
        initField.setColorType(ColorType.Gray, x, y);
    // 並び替える
    Comparator<PathPair> comparator = new PathPairComparator();
    pathPairs.sort(comparator);
    // HTMLの生成  // true: ライン消去あり, false: ライン消去なし
    HTMLBuilder<HTMLColumn> htmlBuilder = new HTMLBuilder<>("Path Result");
    htmlBuilder.addHeader(String.format("<div>%dパターン</div>", pathPairs.size()));
    pathPairs.parallelStream().forEach(pathPair -> {
        PathHTMLColumn htmlColumn = getHTMLColumn(pathPair);
        Pair<String, Integer> linkAndPriority = createALink(pathPair);
        String line = String.format("<div>%s</div>", linkAndPriority.getKey());
        htmlBuilder.addColumn(htmlColumn, line, -linkAndPriority.getValue());
    });
    // 出力
    try (BufferedWriter writer = file.newBufferedWriter()) {
        List<HTMLColumn> priorityList = Arrays.asList(PathHTMLColumn.NotDeletedLine, PathHTMLColumn.DeletedLine);
        for (String line : htmlBuilder.toList(priorityList, false)) writer.write(line);
        writer.flush();
    } catch (Exception e) {
        throw new FinderExecuteException("Failed to output file", e);
    }
}
Also used : ColoredField(common.tetfu.field.ColoredField) HTMLBuilder(output.HTMLBuilder) FinderExecuteException(exceptions.FinderExecuteException) FinderInitializeException(exceptions.FinderInitializeException) BufferedWriter(java.io.BufferedWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HTMLColumn(output.HTMLColumn) FinderExecuteException(exceptions.FinderExecuteException)

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