Search in sources :

Example 1 with PriorityCommandLineWrapper

use of entry.PriorityCommandLineWrapper 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 2 with PriorityCommandLineWrapper

use of entry.PriorityCommandLineWrapper in project solution-finder by knewjade.

the class SetupSettingParser method loadTetfu.

private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, SetupSettings settings) throws FinderParseException {
    // テト譜面のエンコード
    List<TetfuPage> decoded = encodeTetfu(data);
    // 指定されたページを抽出
    int page = wrapper.getIntegerOption("page").orElse(1);
    TetfuPage tetfuPage = extractTetfuPage(decoded, page);
    // コメントの抽出
    String comment = 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);
        wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
    } catch (FinderParseException ignore) {
    }
    // 固定ピースの指定があるか
    // Optional<Boolean> reservedOption = wrapper.getBoolOption("reserved");
    // reservedOption.ifPresent(settings::setReserved);
    // マージン色の指定があるか
    Optional<String> fillColorOption = wrapper.getStringOption("fill");
    if (fillColorOption.isPresent()) {
        settings.setFillColorType(fillColorOption.get());
    }
    // マージン色の指定があるか
    Optional<String> marginColorOption = wrapper.getStringOption("margin");
    if (marginColorOption.isPresent()) {
        settings.setMarginColorType(marginColorOption.get());
    }
    // フィールドを設定
    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);
    }
    // 最大削除ラインの設定
    Optional<Integer> maxHeightOption = wrapper.getIntegerOption("line");
    int maxHeight = maxHeightOption.orElse(coloredField.getUsingHeight());
    if (settings.isReserved()) {
        Field initField = FieldFactory.createField(maxHeight);
        Field needFilledField = FieldFactory.createField(maxHeight);
        Field notFilledField = FieldFactory.createField(maxHeight);
        ColorType marginColorType = settings.getMarginColorType();
        ColorType fillColorType = settings.getFillColorType();
        for (int y = 0; y < maxHeight; y++) {
            for (int x = 0; x < 10; x++) {
                ColorType colorType = coloredField.getColorType(x, y);
                if (colorType.equals(marginColorType)) {
                    coloredField.setColorType(ColorType.Empty, x, y);
                } else if (colorType.equals(fillColorType)) {
                    coloredField.setColorType(ColorType.Empty, x, y);
                    needFilledField.setBlock(x, y);
                } else {
                    switch(colorType) {
                        case Gray:
                            initField.setBlock(x, y);
                            notFilledField.setBlock(x, y);
                            coloredField.setColorType(ColorType.Empty, x, y);
                            break;
                        case Empty:
                            notFilledField.setBlock(x, y);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        settings.setFieldWithReserved(initField, needFilledField, notFilledField, coloredField, maxHeight);
    } else {
        Field initField = FieldFactory.createField(maxHeight);
        Field needFilledField = FieldFactory.createField(maxHeight);
        Field notFilledField = FieldFactory.createField(maxHeight);
        ColorType marginColorType = settings.getMarginColorType();
        ColorType fillColorType = settings.getFillColorType();
        for (int y = 0; y < maxHeight; y++) {
            for (int x = 0; x < 10; x++) {
                ColorType colorType = coloredField.getColorType(x, y);
                if (colorType.equals(marginColorType)) {
                // skip
                } else if (colorType.equals(fillColorType)) {
                    needFilledField.setBlock(x, y);
                } else {
                    switch(colorType) {
                        case Empty:
                            notFilledField.setBlock(x, y);
                            break;
                        case Gray:
                        default:
                            initField.setBlock(x, y);
                            notFilledField.setBlock(x, y);
                            break;
                    }
                }
            }
        }
        settings.setField(initField, needFilledField, notFilledField, maxHeight);
    }
    return wrapper;
}
Also used : TetfuPage(common.tetfu.TetfuPage) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) org.apache.commons.cli(org.apache.commons.cli) Tetfu(common.tetfu.Tetfu) FinderParseException(exceptions.FinderParseException) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Charset(java.nio.charset.Charset) FieldFactory(core.field.FieldFactory) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Files(java.nio.file.Files) IOException(java.io.IOException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) List(java.util.List) Field(core.field.Field) Paths(java.nio.file.Paths) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) Optional(java.util.Optional) CommandLineWrapper(entry.CommandLineWrapper) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) 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 3 with PriorityCommandLineWrapper

use of entry.PriorityCommandLineWrapper 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 4 with PriorityCommandLineWrapper

use of entry.PriorityCommandLineWrapper in project solution-finder by knewjade.

the class PercentSettingParser method loadTetfu.

private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PercentSettings 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, settings.getMaxClearLine());
    return wrapper;
}
Also used : TetfuPage(common.tetfu.TetfuPage) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) org.apache.commons.cli(org.apache.commons.cli) Tetfu(common.tetfu.Tetfu) FinderParseException(exceptions.FinderParseException) MinoFactory(core.mino.MinoFactory) Charset(java.nio.charset.Charset) FieldFactory(core.field.FieldFactory) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Files(java.nio.file.Files) IOException(java.io.IOException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) List(java.util.List) Field(core.field.Field) Paths(java.nio.file.Paths) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) Optional(java.util.Optional) CommandLineWrapper(entry.CommandLineWrapper) 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)

Aggregations

Tetfu (common.tetfu.Tetfu)4 TetfuPage (common.tetfu.TetfuPage)4 ColorConverter (common.tetfu.common.ColorConverter)4 ColorType (common.tetfu.common.ColorType)4 ColoredField (common.tetfu.field.ColoredField)4 Mino (core.mino.Mino)4 MinoFactory (core.mino.MinoFactory)4 Rotate (core.srs.Rotate)4 CommandLineWrapper (entry.CommandLineWrapper)4 NormalCommandLineWrapper (entry.NormalCommandLineWrapper)4 PriorityCommandLineWrapper (entry.PriorityCommandLineWrapper)4 FinderParseException (exceptions.FinderParseException)4 IOException (java.io.IOException)4 Charset (java.nio.charset.Charset)4 Files (java.nio.file.Files)4 Path (java.nio.file.Path)4 Paths (java.nio.file.Paths)4 Arrays (java.util.Arrays)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4