Search in sources :

Example 31 with MinoOperationWithKey

use of common.datastore.MinoOperationWithKey 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 32 with MinoOperationWithKey

use of common.datastore.MinoOperationWithKey in project solution-finder by knewjade.

the class PathCore method run.

List<PathPair> run(Field field, SizedBit sizedBit, BlockField blockField) throws ExecutionException, InterruptedException {
    int maxClearLine = sizedBit.getHeight();
    List<Result> candidates = searcher.stream(resultStream -> {
        return resultStream.filter(result -> {
            LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
            BlockField mergedField = new BlockField(maxClearLine);
            operations.forEach(operation -> {
                Field operationField = createField(operation, maxClearLine);
                mergedField.merge(operationField, operation.getPiece());
            });
            return mergedField.containsAll(blockField);
        }).collect(Collectors.toList());
    });
    return candidates.stream().map(result -> {
        LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
        // 地形の中で組むことができるoperationsを一つ作成
        BuildUpStream buildUpStream = buildUpStreamThreadLocal.get();
        List<MinoOperationWithKey> sampleOperations = buildUpStream.existsValidBuildPatternDirectly(field, operations).findFirst().orElse(Collections.emptyList());
        // 地形の中で組むことができるものがないときはスキップ
        if (sampleOperations.isEmpty())
            return PathPair.EMPTY_PAIR;
        // 地形の中で組むことができるSetを作成
        HashSet<LongPieces> piecesSolution = buildUpStream.existsValidBuildPatternDirectly(field, operations).map(operationWithKeys -> operationWithKeys.stream().map(OperationWithKey::getPiece).collect(Collectors.toList())).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
        // 探索シーケンスの中で組むことができるSetを作成
        HashSet<LongPieces> piecesPattern = getPiecesPattern(piecesSolution);
        // 探索シーケンスの中で組むことができるものがないときはスキップ
        if (piecesPattern.isEmpty())
            return PathPair.EMPTY_PAIR;
        // 譜面の作成
        String fumen = fumenParser.parse(sampleOperations, field, maxClearLine);
        return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(sampleOperations), validPieces);
    }).filter(pathPair -> pathPair != PathPair.EMPTY_PAIR).collect(Collectors.toList());
}
Also used : SyntaxException(common.SyntaxException) java.util(java.util) Pieces(common.datastore.blocks.Pieces) BlockField(common.datastore.BlockField) LongPieces(common.datastore.blocks.LongPieces) PatternGenerator(common.pattern.PatternGenerator) MinoOperationWithKey(common.datastore.MinoOperationWithKey) SizedBit(searcher.pack.SizedBit) OrderLookup(common.order.OrderLookup) Operation(common.datastore.Operation) FieldFactory(core.field.FieldFactory) StackOrder(common.order.StackOrder) BuildUpStream(common.buildup.BuildUpStream) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) ReverseOrderLookUp(common.order.ReverseOrderLookUp) Piece(core.mino.Piece) Result(searcher.pack.task.Result) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Field(core.field.Field) Stream(java.util.stream.Stream) SeparableMino(searcher.pack.separable_mino.SeparableMino) FumenParser(entry.path.output.FumenParser) Mino(core.mino.Mino) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationWithKey(common.datastore.OperationWithKey) SeparableMino(searcher.pack.separable_mino.SeparableMino) Result(searcher.pack.task.Result) BlockField(common.datastore.BlockField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) BlockField(common.datastore.BlockField) LongPieces(common.datastore.blocks.LongPieces) BuildUpStream(common.buildup.BuildUpStream)

Aggregations

MinoOperationWithKey (common.datastore.MinoOperationWithKey)32 Field (core.field.Field)23 MinoFactory (core.mino.MinoFactory)15 Piece (core.mino.Piece)15 Operations (common.datastore.Operations)12 Collectors (java.util.stream.Collectors)12 ColumnField (core.column_field.ColumnField)11 Test (org.junit.jupiter.api.Test)11 InOutPairField (searcher.pack.InOutPairField)11 List (java.util.List)10 OperationWithKey (common.datastore.OperationWithKey)9 Mino (core.mino.Mino)9 Randoms (lib.Randoms)9 LongTest (module.LongTest)9 SizedBit (searcher.pack.SizedBit)9 SeparableMino (searcher.pack.separable_mino.SeparableMino)9 Result (searcher.pack.task.Result)9 SRSValidSolutionFilter (searcher.pack.memento.SRSValidSolutionFilter)8 SolutionFilter (searcher.pack.memento.SolutionFilter)8 OnDemandBasicSolutions (searcher.pack.solutions.OnDemandBasicSolutions)8