Search in sources :

Example 11 with MinoOperationWithKey

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

the class OneFumenParser method createBlockField.

private BlockField createBlockField(List<MinoOperationWithKey> operations, int maxClearLine) {
    BlockField blockField = new BlockField(maxClearLine);
    for (MinoOperationWithKey key : operations) {
        Field test = createField(key, maxClearLine);
        Mino mino = key.getMino();
        blockField.merge(test, mino.getPiece());
    }
    return blockField;
}
Also used : BlockField(common.datastore.BlockField) Field(core.field.Field) ColoredField(common.tetfu.field.ColoredField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) BlockField(common.datastore.BlockField) Mino(core.mino.Mino)

Example 12 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) throws ExecutionException, InterruptedException {
    List<Result> candidates = searcher.toList();
    int maxClearLine = sizedBit.getHeight();
    return candidates.parallelStream().map(result -> {
        LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
        // 地形の中で組むことができるoperationsをすべてリスト化する
        BuildUpStream buildUpStream2 = buildUpStreamThreadLocal.get();
        List<List<MinoOperationWithKey>> validOperaions = buildUpStream2.existsValidBuildPatternDirectly(field, operations).collect(Collectors.toList());
        // 地形の中で組むことができるものがないときはスキップ
        if (validOperaions.isEmpty())
            return PathPair.EMPTY_PAIR;
        // 地形の中で組むことができるSetを作成
        HashSet<LongPieces> piecesSolution = validOperaions.stream().map(operationWithKeys -> operationWithKeys.stream().map(OperationWithKey::getPiece)).map(LongPieces::new).collect(Collectors.toCollection(HashSet::new));
        // 探索シーケンスの中で組むことができるSetを作成
        HashSet<LongPieces> piecesPattern = getPiecesPattern(piecesSolution);
        // 探索シーケンスの中で組むことができるものがないときはスキップ
        if (piecesPattern.isEmpty())
            return PathPair.EMPTY_PAIR;
        // 探索シーケンスの中でテト譜にするoperationsを選択する
        List<MinoOperationWithKey> operationsToUrl = validOperaions.stream().filter(o -> validPieces.contains(new LongPieces(o.stream().map(Operation::getPiece)))).findFirst().orElse(Collections.emptyList());
        // 譜面の作成
        String fumen = fumenParser.parse(operationsToUrl, field, maxClearLine);
        return new PathPair(result, piecesSolution, piecesPattern, fumen, new ArrayList<>(operationsToUrl), 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) Result(searcher.pack.task.Result) MinoOperationWithKey(common.datastore.MinoOperationWithKey) LongPieces(common.datastore.blocks.LongPieces) BuildUpStream(common.buildup.BuildUpStream)

Example 13 with MinoOperationWithKey

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

the class OperationWithKeyInterpreter method parseToStream.

public static Stream<MinoOperationWithKey> parseToStream(String operations, MinoFactory minoFactory) {
    return Arrays.stream(operations.split(";")).map(s -> s.split(",")).map(strings -> {
        Piece piece = StringEnumTransform.toPiece(strings[0]);
        Rotate rotate = StringEnumTransform.toRotate(strings[1]);
        Mino mino = minoFactory.create(piece, rotate);
        int x = Integer.valueOf(strings[2]);
        int y = Integer.valueOf(strings[3]);
        long deleteKey = Long.valueOf(strings[4]);
        long usingKey = Long.valueOf(strings[5]);
        return new FullOperationWithKey(mino, x, y, deleteKey, usingKey);
    });
}
Also used : OperationWithKey(common.datastore.OperationWithKey) Piece(core.mino.Piece) Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) FullOperationWithKey(common.datastore.FullOperationWithKey) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) Mino(core.mino.Mino) Rotate(core.srs.Rotate) Piece(core.mino.Piece) Mino(core.mino.Mino) FullOperationWithKey(common.datastore.FullOperationWithKey)

Example 14 with MinoOperationWithKey

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

the class BuildUp method existsValidByOrder.

private static boolean existsValidByOrder(Field field, EnumMap<Piece, LinkedList<MinoOperationWithKey>> eachBlocks, List<Piece> pieces, int height, Reachable reachable, int depth) {
    long deleteKey = field.clearLineReturnKey();
    Piece piece = pieces.get(depth);
    LinkedList<MinoOperationWithKey> operationWithKeys = eachBlocks.get(piece);
    for (int index = 0; index < operationWithKeys.size(); index++) {
        MinoOperationWithKey key = operationWithKeys.remove(index);
        long needDeletedKey = key.getNeedDeletedKey();
        if ((deleteKey & needDeletedKey) != needDeletedKey) {
            // 必要な列が消えていない
            operationWithKeys.add(index, key);
            continue;
        }
        // すでに下のラインが消えているときは、その分スライドさせる
        int originalY = key.getY();
        int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
        Mino mino = key.getMino();
        int x = key.getX();
        int y = originalY - deletedLines;
        if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height - mino.getMinY())) {
            if (pieces.size() == depth + 1)
                return true;
            Field nextField = field.freeze(height);
            nextField.put(mino, x, y);
            nextField.insertBlackLineWithKey(deleteKey);
            boolean exists = existsValidByOrder(nextField, eachBlocks, pieces, height, reachable, depth + 1);
            if (exists)
                return true;
        }
        operationWithKeys.add(index, key);
    }
    field.insertBlackLineWithKey(deleteKey);
    return false;
}
Also used : Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Piece(core.mino.Piece) Mino(core.mino.Mino)

Example 15 with MinoOperationWithKey

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

the class BuildUpStream method existsValidBuildPatternRecursive.

private void existsValidBuildPatternRecursive(Field field, LinkedList<MinoOperationWithKey> operationWithKeys) {
    long deleteKey = field.clearLineReturnKey();
    for (int index = 0; index < operationWithKeys.size(); index++) {
        MinoOperationWithKey key = operationWithKeys.remove(index);
        this.currentOperations.addLast(key);
        // 必要な列が消えているかチェック
        long needDeletedKey = key.getNeedDeletedKey();
        if ((deleteKey & needDeletedKey) == needDeletedKey) {
            // すでに下のラインが消えているときは、その分スライドさせる
            int originalY = key.getY();
            int deletedLines = Long.bitCount(KeyOperators.getMaskForKeyBelowY(originalY) & deleteKey);
            Mino mino = key.getMino();
            int x = key.getX();
            int y = originalY - deletedLines;
            if (field.isOnGround(mino, x, y) && field.canPut(mino, x, y) && reachable.checks(field, mino, x, y, height)) {
                if (operationWithKeys.isEmpty()) {
                    // 解をみつけたとき
                    solutions.accept(new ArrayList<>(currentOperations));
                } else {
                    Field nextField = field.freeze(height);
                    nextField.put(mino, x, y);
                    nextField.insertBlackLineWithKey(deleteKey);
                    existsValidBuildPatternRecursive(nextField, operationWithKeys);
                }
            }
        }
        this.currentOperations.removeLast();
        operationWithKeys.add(index, key);
    }
    field.insertBlackLineWithKey(deleteKey);
}
Also used : Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Mino(core.mino.Mino)

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