Search in sources :

Example 6 with BlockField

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

the class SetupSettings method setFieldWithReserved.

void setFieldWithReserved(Field initField, Field needFilledField, Field notFilledField, ColoredField coloredField, int maxHeight) {
    BlockField blockField = new BlockField(maxHeight);
    for (int y = 0; y < maxHeight; y++) {
        for (int x = 0; x < 10; x++) {
            ColorConverter colorConverter = new ColorConverter();
            ColorType colorType = colorConverter.parseToColorType(coloredField.getBlockNumber(x, y));
            switch(colorType) {
                case Gray:
                case Empty:
                    break;
                default:
                    Piece piece = colorConverter.parseToBlock(colorType);
                    blockField.setBlock(piece, x, y);
                    break;
            }
        }
    }
    setMaxHeight(maxHeight);
    setInitField(initField);
    setNeedFilledField(needFilledField);
    setNotFilledField(notFilledField);
    setReservedBlock(blockField);
}
Also used : BlockField(common.datastore.BlockField) Piece(core.mino.Piece) ColorConverter(common.tetfu.common.ColorConverter) ColorType(common.tetfu.common.ColorType)

Example 7 with BlockField

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

the class OneFumenParser method createTetfuElement.

private TetfuElement createTetfuElement(Field initField, BlockField blockField, String comment, int maxClearLine) {
    ColoredField coloredField = createInitColoredField(initField, maxClearLine);
    for (Piece piece : Piece.values()) {
        Field target = blockField.get(piece);
        ColorType colorType = this.colorConverter.parseToColorType(piece);
        fillInField(coloredField, colorType, target, maxClearLine);
    }
    return new TetfuElement(coloredField, ColorType.Empty, Rotate.Reverse, 0, 0, comment);
}
Also used : BlockField(common.datastore.BlockField) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) TetfuElement(common.tetfu.TetfuElement)

Example 8 with BlockField

use of common.datastore.BlockField 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 9 with BlockField

use of common.datastore.BlockField 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 10 with BlockField

use of common.datastore.BlockField 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

BlockField (common.datastore.BlockField)11 Field (core.field.Field)8 ColoredField (common.tetfu.field.ColoredField)6 Piece (core.mino.Piece)6 TetfuElement (common.tetfu.TetfuElement)5 ColorType (common.tetfu.common.ColorType)5 MinoOperationWithKey (common.datastore.MinoOperationWithKey)4 ColorConverter (common.tetfu.common.ColorConverter)4 PatternGenerator (common.pattern.PatternGenerator)3 Operation (common.datastore.Operation)2 OperationWithKey (common.datastore.OperationWithKey)2 Pieces (common.datastore.blocks.Pieces)2 Tetfu (common.tetfu.Tetfu)2 Mino (core.mino.Mino)2 MinoFactory (core.mino.MinoFactory)2 MinoShifter (core.mino.MinoShifter)2 EntryPoint (entry.EntryPoint)2 SizedBit (searcher.pack.SizedBit)2 SyntaxException (common.SyntaxException)1 BuildUpStream (common.buildup.BuildUpStream)1