Search in sources :

Example 11 with Tetfu

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

the class Main3 method viewTetfu.

private static void viewTetfu(List<TetfuElement> elements) {
    if (elements.isEmpty()) {
        System.out.printf("<p>該当なし</p>%n");
    } else {
        MinoFactory minoFactory = new MinoFactory();
        ColorConverter colorConverter = new ColorConverter();
        int sizePerOne = 40;
        int split = ((elements.size() - 1) / sizePerOne) + 1;
        for (int index = 0; index < split; index++) {
            int startIndex = index * sizePerOne;
            int toIndex = index == split - 1 ? elements.size() : startIndex + sizePerOne;
            List<TetfuElement> subList = elements.subList(startIndex, toIndex);
            Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
            String encode = tetfu.encode(subList);
            if (split == 1)
                System.out.printf("<p><a href='http://fumen.zui.jp/?v115@%s' target='_blank'>全 %d パターン</a></p>%n", encode, elements.size());
            else
                System.out.printf("<p><a href='http://fumen.zui.jp/?v115@%s' target='_blank'>全 %d パターン (%d/%d)</a></p>%n", encode, elements.size(), index + 1, split);
        }
    }
}
Also used : ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 12 with Tetfu

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

the class OneFumenParser method parse.

@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
    // BlockField を生成
    BlockField blockField = createBlockField(operations, maxClearLine);
    // パターンを表す名前 を生成
    String blocksName = operations.stream().map(OperationWithKey::getPiece).map(Piece::getName).collect(Collectors.joining());
    // テト譜1ページを作成
    TetfuElement tetfuElement = createTetfuElement(field, blockField, blocksName, maxClearLine);
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    return tetfu.encode(Collections.singletonList(tetfuElement));
}
Also used : OperationWithKey(common.datastore.OperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) BlockField(common.datastore.BlockField) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 13 with Tetfu

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

the class EasyTetfu method encodeUrl.

public String encodeUrl(Field initField, BlockField blockField) {
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    TetfuElement elementOnePage = parseBlockFieldToTetfuElement(initField, colorConverter, blockField, "");
    return "http://fumen.zui.jp/?v115@" + tetfu.encode(Collections.singletonList(elementOnePage));
}
Also used : Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 14 with Tetfu

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

the class PercentSettingParser method parse.

public Optional<PercentSettings> parse() throws FinderParseException {
    Options options = createOptions();
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine = parseToCommandLine(options, parser, commands);
    CommandLineWrapper wrapper = new NormalCommandLineWrapper(commandLine);
    PercentSettings settings = new PercentSettings();
    // help
    if (wrapper.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("percent [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 {
                // 最大削除ラインの設定
                int maxClearLine = Integer.valueOf(fieldLines.pollFirst());
                settings.setMaxClearLine(maxClearLine);
                // フィールドの設定
                String fieldMarks = String.join("", fieldLines);
                Field field = FieldFactory.createField(fieldMarks);
                settings.setFieldFilePath(field);
            }
        } 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<Integer> treeDepth = wrapper.getIntegerOption("tree-depth");
    treeDepth.ifPresent(settings::setTreeDepth);
    // パフェ失敗パターンの表示個数の設定
    Optional<Integer> failedCount = wrapper.getIntegerOption("failed-count");
    failedCount.ifPresent(settings::setFailedCount);
    // ホールドの設定
    Optional<Boolean> isUsingHold = wrapper.getBoolOption("hold");
    isUsingHold.ifPresent(settings::setUsingHold);
    // ログファイルの設定
    Optional<String> logFilePath = wrapper.getStringOption("log-path");
    logFilePath.ifPresent(settings::setLogFilePath);
    // スレッド数の設定
    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) 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) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Path(java.nio.file.Path) Charset(java.nio.charset.Charset) IOException(java.io.IOException) FinderParseException(exceptions.FinderParseException) IOException(java.io.IOException) FinderParseException(exceptions.FinderParseException) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) CommandLineWrapper(entry.CommandLineWrapper)

Example 15 with Tetfu

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

the class DevRandomEntryPoint method run.

@Override
public void run() throws FinderException {
    PatternGenerator generator = createBlockGenerator(pattern);
    List<Pieces> blocks = generator.blocksStream().collect(Collectors.toList());
    int index = new Random().nextInt(blocks.size());
    Pieces selected = blocks.get(index);
    String quiz = Tetfu.encodeForQuiz(selected.getPieces());
    MinoFactory minoFactory = new MinoFactory();
    ColorConverter converter = new ColorConverter();
    ColoredField coloredField = getTetfu(minoFactory, converter);
    Tetfu tetfu = new Tetfu(minoFactory, converter);
    TetfuElement element = new TetfuElement(coloredField, quiz);
    String encode = tetfu.encode(Collections.singletonList(element));
    System.out.println("v115@" + encode);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) ArrayColoredField(common.tetfu.field.ArrayColoredField) ColoredField(common.tetfu.field.ColoredField) Random(java.util.Random) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu) EntryPoint(entry.EntryPoint) Pieces(common.datastore.blocks.Pieces) TetfuElement(common.tetfu.TetfuElement)

Aggregations

Tetfu (common.tetfu.Tetfu)17 ColorConverter (common.tetfu.common.ColorConverter)12 MinoFactory (core.mino.MinoFactory)12 FinderParseException (exceptions.FinderParseException)9 TetfuElement (common.tetfu.TetfuElement)7 TetfuPage (common.tetfu.TetfuPage)5 ColoredField (common.tetfu.field.ColoredField)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 ColorType (common.tetfu.common.ColorType)4 CommandLineWrapper (entry.CommandLineWrapper)4 NormalCommandLineWrapper (entry.NormalCommandLineWrapper)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 LinkedList (java.util.LinkedList)4 Optional (java.util.Optional)4 org.apache.commons.cli (org.apache.commons.cli)4