Search in sources :

Example 21 with SeparableMino

use of searcher.pack.separable_mino.SeparableMino in project solution-finder by knewjade.

the class ConnectionsToStreamCallable method parseConnectionToMinoField.

private Stream<? extends RecursiveMinoField> parseConnectionToMinoField(ColumnFieldConnection connection) {
    // outerで重なりがないか確認する
    ColumnField nextOuterField = connection.getOuterField();
    if (nextOuterField.canMerge(limitOuterField) && nextOuterField.canMerge(outerColumnField)) {
        ColumnField freeze = nextOuterField.freeze(calculator.getHeight());
        // フィールドとミノ順を進める
        SeparableMino currentMino = connection.getMino();
        freeze.merge(outerColumnField);
        // 新しいフィールドを基に探索
        ColumnField innerField = connection.getInnerField();
        return calculate(innerField, freeze, wallField, currentMino);
    }
    return Stream.empty();
}
Also used : SeparableMino(searcher.pack.separable_mino.SeparableMino) ColumnField(core.column_field.ColumnField)

Example 22 with SeparableMino

use of searcher.pack.separable_mino.SeparableMino in project solution-finder by knewjade.

the class FullOperationSeparableMinoComparatorTest method compareMinoFieldDiff.

@Test
void compareMinoFieldDiff() {
    List<SeparableMino> minos = separableMinos.getMinos();
    Randoms randoms = new Randoms();
    FullOperationSeparableMinoComparator comparator = new FullOperationSeparableMinoComparator();
    for (int count = 0; count < 100000; count++) {
        int index1 = randoms.nextInt(minos.size() - 1);
        int index2 = randoms.nextInt(minos.size());
        if (index1 == index2)
            index2 += 1;
        // assert is not 0 & sign reversed
        SeparableMino mino1 = minos.get(index1);
        SeparableMino mino2 = minos.get(index2);
        assertThat(comparator.compare(mino1, mino2) * comparator.compare(mino2, mino1)).isLessThan(0);
    }
}
Also used : Randoms(lib.Randoms) SeparableMino(searcher.pack.separable_mino.SeparableMino) Test(org.junit.jupiter.api.Test)

Example 23 with SeparableMino

use of searcher.pack.separable_mino.SeparableMino in project solution-finder by knewjade.

the class MinoFieldComparatorTest method compareMinoFieldDiffSize.

@Test
void compareMinoFieldDiffSize() {
    Randoms randoms = new Randoms();
    List<SeparableMino> minos = separableMinos.getMinos();
    int index = randoms.nextInt(0, minos.size() - 1);
    SeparableMino mino = minos.get(index);
    RecursiveMinoField recursiveMinoField1 = new RecursiveMinoField(mino, ColumnFieldFactory.createField(), separableMinos);
    RecursiveMinoField recursiveMinoField2 = new RecursiveMinoField(mino, ColumnFieldFactory.createField(), separableMinos);
    recursiveMinoField2 = new RecursiveMinoField(mino, recursiveMinoField2, ColumnFieldFactory.createField(), separableMinos);
    // assert is not 0 & sign reversed
    MinoFieldComparator comparator = new MinoFieldComparator();
    assertThat(comparator.compare(recursiveMinoField1, recursiveMinoField2) * comparator.compare(recursiveMinoField2, recursiveMinoField1)).isLessThan(0);
}
Also used : Randoms(lib.Randoms) SeparableMino(searcher.pack.separable_mino.SeparableMino) RecursiveMinoField(searcher.pack.mino_field.RecursiveMinoField) Test(org.junit.jupiter.api.Test)

Example 24 with SeparableMino

use of searcher.pack.separable_mino.SeparableMino 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

SeparableMino (searcher.pack.separable_mino.SeparableMino)24 Field (core.field.Field)14 ColumnField (core.column_field.ColumnField)13 Test (org.junit.jupiter.api.Test)13 Randoms (lib.Randoms)12 SeparableMinos (searcher.pack.SeparableMinos)11 SizedBit (searcher.pack.SizedBit)11 Result (searcher.pack.task.Result)11 Collectors (java.util.stream.Collectors)10 PerfectPackSearcher (searcher.pack.task.PerfectPackSearcher)9 FieldFactory (core.field.FieldFactory)8 MinoFactory (core.mino.MinoFactory)8 MinoShifter (core.mino.MinoShifter)8 Piece (core.mino.Piece)8 List (java.util.List)8 Stream (java.util.stream.Stream)8 InOutPairField (searcher.pack.InOutPairField)8 SolutionFilter (searcher.pack.memento.SolutionFilter)8 TaskResultHelper (searcher.pack.task.TaskResultHelper)8 BuildUpStream (common.buildup.BuildUpStream)7