Search in sources :

Example 36 with ColorConverter

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

the class MoveEntryPoint method run.

@Override
public void run() throws FinderException {
    output("# Setup Field");
    // Setup field
    Field field = settings.getField();
    Verify.field(field);
    int maxClearLine = settings.getMaxClearLine();
    output(FieldView.toString(field, maxClearLine));
    // Setup max depth
    // パフェに必要なミノ数
    int maxDepth = Verify.maxDepth(field, maxClearLine);
    output();
    // ========================================
    output("Searching patterns:");
    // Setup patterns
    List<String> patterns = settings.getPatterns();
    PatternGenerator generator = Verify.patterns(patterns);
    // Output patterns
    for (String pattern : patterns) output("  " + pattern);
    output();
    // ========================================
    // baseファイル
    MyFile base = new MyFile(settings.getOutputBaseFilePath());
    base.mkdirs();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    ColorConverter colorConverter = new ColorConverter();
    PerfectValidator perfectValidator = new PerfectValidator();
    PutterNoHold<Action> putter = new PutterNoHold<>(minoFactory, perfectValidator);
    output("# Calculate");
    try (BufferedWriter bw = base.newBufferedWriter()) {
        List<Pieces> pieces = generator.blocksStream().collect(Collectors.toList());
        for (Pieces piece : pieces) {
            String using = piece.blockStream().map(Piece::getName).collect(Collectors.joining());
            output("   -> " + using);
            TreeSet<Order> first = putter.first(field, piece.getPieceArray(), new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine), maxClearLine, maxDepth);
            for (Order order : first) {
                Stream<Operation> operationStream = order.getHistory().getOperationStream();
                List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, new Operations(operationStream), minoFactory, maxClearLine);
                BlockField blockField = OperationTransform.parseToBlockField(operationWithKeys, minoFactory, maxClearLine);
                String encodeColor = encodeColor(field, minoFactory, colorConverter, blockField);
                String encodeGray = encodeGray(order.getField(), minoFactory, colorConverter);
                bw.write(String.format("%s,%s,%s", using, encodeColor, encodeGray));
                bw.newLine();
            }
        }
        bw.flush();
    } catch (IOException e) {
        throw new FinderExecuteException("Failed to output file", e);
    }
}
Also used : Action(common.datastore.action.Action) MyFile(entry.path.output.MyFile) Operation(common.datastore.Operation) BufferedWriter(java.io.BufferedWriter) BlockField(common.datastore.BlockField) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) LockedCandidate(core.action.candidate.LockedCandidate) MinoOperationWithKey(common.datastore.MinoOperationWithKey) BlockField(common.datastore.BlockField) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) PutterNoHold(searcher.PutterNoHold) PerfectValidator(searcher.common.validator.PerfectValidator) Operations(common.datastore.Operations) Pieces(common.datastore.blocks.Pieces) Order(common.datastore.order.Order) PatternGenerator(common.pattern.PatternGenerator) IOException(java.io.IOException) EntryPoint(entry.EntryPoint) MinoRotation(core.srs.MinoRotation) MinoShifter(core.mino.MinoShifter) FinderExecuteException(exceptions.FinderExecuteException)

Example 37 with ColorConverter

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

the class MoveSettingParser 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 38 with ColorConverter

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

the class PathEntryPoint method run.

@Override
public void run() throws FinderException {
    output("# Setup Field");
    // Setup field
    Field field = settings.getField();
    Verify.field(field);
    // Setup max clear line
    int maxClearLine = settings.getMaxClearLine();
    Verify.maxClearLineUnder10(maxClearLine);
    // Setup reserved blocks
    BlockField reservedBlocks = settings.getReservedBlock();
    if (settings.isReserved()) {
        Verify.reservedBlocks(reservedBlocks);
        for (int y = maxClearLine - 1; 0 <= y; y--) {
            StringBuilder builder = new StringBuilder();
            for (int x = 0; x < 10; x++) {
                if (reservedBlocks.getBlock(x, y) != null)
                    builder.append(reservedBlocks.getBlock(x, y).getName());
                else if (!field.isEmpty(x, y))
                    builder.append('X');
                else
                    builder.append('_');
            }
            output(builder.toString());
        }
    } else {
        output(FieldView.toString(field, maxClearLine));
    }
    // Setup max depth
    // パフェに必要なミノ数
    int maxDepth = Verify.maxDepth(field, maxClearLine);
    output();
    // ========================================
    // Output user-defined
    output("# Initialize / User-defined");
    output("Max clear lines: " + maxClearLine);
    output("Using hold: " + (settings.isUsingHold() ? "use" : "avoid"));
    output("Drop: " + settings.getDropType().name().toLowerCase());
    output("Searching patterns:");
    // Setup patterns
    List<String> patterns = settings.getPatterns();
    PatternGenerator generator = Verify.patterns(patterns, maxDepth);
    // Output patterns
    for (String pattern : patterns) output("  " + pattern);
    output();
    // ========================================
    // Setup core
    output("# Initialize / System");
    int threadCount = getThreadCount();
    // Output system-defined
    output("Version = " + FinderConstant.VERSION);
    output("Threads = " + threadCount);
    output("Need Pieces = " + maxDepth);
    output();
    // ========================================
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    ColorConverter colorConverter = new ColorConverter();
    SizedBit sizedBit = decideSizedBitSolutionWidth(maxClearLine);
    SolutionFilter solutionFilter = new ForPathSolutionFilter(generator, maxClearLine);
    // Holdができるときは必要なミノ分(maxDepth + 1)だけを取り出す。maxDepth + 1だけないときはブロックの個数をそのまま指定
    output("# Enumerate pieces");
    boolean isUsingHold = settings.isUsingHold();
    int piecesDepth = generator.getDepth();
    output("Piece pop count = " + (isUsingHold && maxDepth < piecesDepth ? maxDepth + 1 : maxDepth));
    output();
    // ========================================
    output("# Cache");
    output("  -> Stopwatch start");
    Stopwatch stopwatch1 = Stopwatch.createStartedStopwatch();
    BasicSolutions basicSolutions = calculateBasicSolutions(field, minoFactory, minoShifter, sizedBit, solutionFilter);
    stopwatch1.stop();
    output("     ... done");
    output("  -> Stopwatch stop : " + stopwatch1.toMessage(TimeUnit.MILLISECONDS));
    output();
    // ========================================
    output("# Search");
    output("  -> Stopwatch start");
    output("     ... searching");
    Stopwatch stopwatch2 = Stopwatch.createStartedStopwatch();
    PathCore pathCore = createPathCore(field, maxClearLine, maxDepth, patterns, minoFactory, colorConverter, sizedBit, solutionFilter, isUsingHold, basicSolutions, threadCount);
    List<PathPair> pathPairs = run(pathCore, field, sizedBit, reservedBlocks);
    stopwatch2.stop();
    output("     ... done");
    output("  -> Stopwatch stop : " + stopwatch2.toMessage(TimeUnit.MILLISECONDS));
    output();
    // ========================================
    output("# Output file");
    OutputType outputType = settings.getOutputType();
    PathOutput pathOutput = createOutput(outputType, generator, maxDepth);
    pathOutput.output(pathPairs, field, sizedBit);
    output();
    // ========================================
    output("# Finalize");
    output("done");
}
Also used : PatternGenerator(common.pattern.PatternGenerator) Stopwatch(lib.Stopwatch) EntryPoint(entry.EntryPoint) FilterOnDemandBasicSolutions(searcher.pack.solutions.FilterOnDemandBasicSolutions) BasicSolutions(searcher.pack.calculator.BasicSolutions) BlockField(common.datastore.BlockField) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) ColumnSmallField(core.column_field.ColumnSmallField) BlockField(common.datastore.BlockField) SizedBit(searcher.pack.SizedBit) SolutionFilter(searcher.pack.memento.SolutionFilter) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter)

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