Search in sources :

Example 1 with ColoredField

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

the class SequenceFumenParser method createInitColoredField.

private ColoredField createInitColoredField(Field initField, int maxClearLine) {
    ColoredField coloredField = ColoredFieldFactory.createField(24);
    fillInField(coloredField, ColorType.Gray, initField, maxClearLine);
    return coloredField;
}
Also used : ColoredField(common.tetfu.field.ColoredField)

Example 2 with ColoredField

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

the class SequenceFumenParser method parse.

@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
    Operations operations2 = OperationTransform.parseToOperations(field, operations, maxClearLine);
    List<? extends Operation> operationsList = operations2.getOperations();
    // ブロック順に変換
    List<Piece> pieceList = operationsList.stream().map(Operation::getPiece).collect(Collectors.toList());
    // テト譜を作成
    String quiz = Tetfu.encodeForQuiz(pieceList);
    ArrayList<TetfuElement> tetfuElements = new ArrayList<>();
    // 最初のelement
    Operation firstKey = operationsList.get(0);
    ColorType colorType1 = colorConverter.parseToColorType(firstKey.getPiece());
    ColoredField coloredField = createInitColoredField(field, maxClearLine);
    TetfuElement firstElement = new TetfuElement(coloredField, colorType1, firstKey.getRotate(), firstKey.getX(), firstKey.getY(), quiz);
    tetfuElements.add(firstElement);
    // 2番目以降のelement
    if (1 < operationsList.size()) {
        operationsList.subList(1, operationsList.size()).stream().map(operation -> {
            ColorType colorType = colorConverter.parseToColorType(operation.getPiece());
            return new TetfuElement(colorType, operation.getRotate(), operation.getX(), operation.getY(), quiz);
        }).forEach(tetfuElements::add);
    }
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    return tetfu.encode(tetfuElements);
}
Also used : Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) OperationTransform(common.parser.OperationTransform) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement) ColorConverter(common.tetfu.common.ColorConverter) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Operations(common.datastore.Operations) List(java.util.List) Field(core.field.Field) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Operation(common.datastore.Operation) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) ArrayList(java.util.ArrayList) Operation(common.datastore.Operation) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Operations(common.datastore.Operations) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 3 with ColoredField

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

the class PercentSettings 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.getBlockNumber(x, y) != EMPTY_BLOCK_NUMBER)
        field.setBlock(x, y);
    setFieldFilePath(field);
}
Also used : Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField)

Example 4 with ColoredField

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

the class DirectTetfuPageTest method test1.

@Test
void test1() {
    ColoredField coloredField = ColoredFieldFactory.createColoredField("______IIII");
    TetfuPage page = new DirectTetfuPage(ColorType.I, 3, 0, Rotate.Left, "test", coloredField, true);
    assertThat(page).returns(ColorType.I, TetfuPage::getColorType).returns(3, TetfuPage::getX).returns(0, TetfuPage::getY).returns("test", TetfuPage::getComment).returns(coloredField, TetfuPage::getField).returns(true, TetfuPage::isPutMino);
}
Also used : ColoredField(common.tetfu.field.ColoredField) Test(org.junit.jupiter.api.Test)

Example 5 with ColoredField

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

the class PathSettingParser method parse.

public Optional<PathSettings> parse() throws FinderParseException {
    Options options = createOptions();
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine = parseToCommandLine(options, parser, commands);
    CommandLineWrapper wrapper = new NormalCommandLineWrapper(commandLine);
    PathSettings settings = new PathSettings();
    // help
    if (wrapper.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("path [options]", options);
        return Optional.empty();
    }
    // フィールド・最大削除ラインの設定
    if (wrapper.hasOption("tetfu")) {
        // テト譜から
        Optional<String> tetfuData = wrapper.getStringOption("tetfu");
        if (!tetfuData.isPresent())
            throw new FinderParseException("Should specify option value: --tetfu");
        String encoded = Tetfu.removeDomainData(tetfuData.get());
        wrapper = loadTetfu(encoded, parser, options, wrapper, settings);
    } else {
        // フィールドファイルから
        Optional<String> fieldPathOption = wrapper.getStringOption("field-path");
        String fieldPath = fieldPathOption.orElse(DEFAULT_FIELD_TXT);
        Path path = Paths.get(fieldPath);
        Charset charset = Charset.forName(CHARSET_NAME);
        try {
            LinkedList<String> fieldLines = Files.lines(path, charset).map(str -> {
                if (str.contains("#"))
                    return str.substring(0, str.indexOf('#'));
                return str;
            }).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toCollection(LinkedList::new));
            if (fieldLines.isEmpty())
                throw new FinderParseException("Should specify clear-line & field-definition in field file");
            String removeDomainData = Tetfu.removeDomainData(fieldLines.get(0));
            if (Tetfu.isDataLater115(removeDomainData)) {
                // テト譜から
                wrapper = loadTetfu(removeDomainData, parser, options, wrapper, settings);
            } else {
                // 固定ピースの指定があるか
                Optional<Boolean> reservedOption = wrapper.getBoolOption("reserved");
                reservedOption.ifPresent(settings::setReserved);
                // 最大削除ラインの設定
                int maxClearLine = Integer.valueOf(fieldLines.pollFirst());
                settings.setMaxClearLine(maxClearLine);
                // フィールドの設定
                String fieldMarks = String.join("", fieldLines);
                ColoredField coloredField = ColoredFieldFactory.createColoredField(fieldMarks);
                if (settings.isReserved()) {
                    settings.setFieldWithReserved(coloredField, maxClearLine);
                } else {
                    settings.setField(coloredField, maxClearLine);
                }
            }
        } catch (NumberFormatException e) {
            throw new FinderParseException("Cannot read clear-line from " + fieldPath);
        } catch (IOException e) {
            throw new FinderParseException("Cannot open field file", e);
        }
    }
    // ドロップの設定
    Optional<String> dropType = wrapper.getStringOption("drop");
    try {
        dropType.ifPresent(type -> {
            String key = dropType.orElse("softdrop");
            try {
                settings.setDropType(key);
            } catch (FinderParseException e) {
                throw new RuntimeException(e);
            }
        });
    } catch (Exception e) {
        throw new FinderParseException("Unsupported format: format=" + dropType.orElse("<empty>"));
    }
    // ホールドの設定
    Optional<Boolean> isUsingHold = wrapper.getBoolOption("hold");
    isUsingHold.ifPresent(settings::setUsingHold);
    // キャッシュ
    Optional<Integer> cachedMinBit = wrapper.getIntegerOption("cached-bit");
    cachedMinBit.ifPresent(settings::setCachedMinBit);
    // ログファイルの設定
    Optional<String> logFilePath = wrapper.getStringOption("log-path");
    logFilePath.ifPresent(settings::setLogFilePath);
    // アウトプットファイルの設定
    Optional<String> outputBaseFilePath = wrapper.getStringOption("output-base");
    outputBaseFilePath.ifPresent(settings::setOutputBaseFilePath);
    // 最大レイヤーの設定
    Optional<Integer> maxLayerNumber = wrapper.getIntegerOption("max-layer");
    Optional<PathLayer> pathLayer = maxLayerNumber.map(this::getPathLayer);
    pathLayer.ifPresent(settings::setPathLayer);
    // 出力タイプの設定
    Optional<String> outputType = wrapper.getStringOption("format");
    Optional<String> keyType = wrapper.getStringOption("key");
    try {
        outputType.ifPresent(type -> {
            String key = keyType.orElse("none");
            try {
                settings.setOutputType(type, key);
            } catch (FinderParseException e) {
                throw new RuntimeException(e);
            }
        });
    } catch (Exception e) {
        throw new FinderParseException("Unsupported format: format=" + outputType.orElse("<empty>"));
    }
    // 出力分割の設定
    Optional<Boolean> isSplit = wrapper.getBoolOption("split");
    isSplit.ifPresent(settings::setTetfuSplit);
    // スレッド数の設定
    Optional<Integer> threadCount = wrapper.getIntegerOption("threads");
    threadCount.ifPresent(settings::setThreadCount);
    // 探索パターンの設定
    if (wrapper.hasOption("patterns")) {
        // パターン定義から
        Optional<String> patternOption = wrapper.getStringOption("patterns");
        assert patternOption.isPresent();
        String patternValue = patternOption.get();
        List<String> patterns = Arrays.stream(patternValue.split(PATTERN_DELIMITER)).collect(Collectors.toList());
        settings.setPatterns(patterns);
    } else {
        // パターンファイルから
        Optional<String> patternPathOption = wrapper.getStringOption("patterns-path");
        String patternPath = patternPathOption.orElse(DEFAULT_PATTERNS_TXT);
        Path path = Paths.get(patternPath);
        Charset charset = Charset.forName(CHARSET_NAME);
        try {
            List<String> patterns = Files.lines(path, charset).collect(Collectors.toList());
            settings.setPatterns(patterns);
        } catch (IOException e) {
            throw new FinderParseException("Cannot open patterns file", e);
        }
    }
    return Optional.of(settings);
}
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) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Path(java.nio.file.Path) ColoredField(common.tetfu.field.ColoredField) Charset(java.nio.charset.Charset) IOException(java.io.IOException) IOException(java.io.IOException) FinderParseException(exceptions.FinderParseException) FinderParseException(exceptions.FinderParseException) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) CommandLineWrapper(entry.CommandLineWrapper)

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