Search in sources :

Example 21 with MinoOperationWithKey

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

the class ParityBasedPackSearcher method search.

public Stream<List<MinoOperationWithKey>> search(List<Piece> usingPieces) {
    // 準備
    MinoFactory minoFactory = new MinoFactory();
    PositionLimitParser positionLimitParser = new PositionLimitParser(minoFactory, maxClearLine);
    LockedReachableThreadLocal threadLocal = new LockedReachableThreadLocal(maxClearLine);
    ParityField parityField = new ParityField(field);
    PieceCounter pieceCounter = new PieceCounter(usingPieces);
    ColumnParityLimitation limitation = new ColumnParityLimitation(pieceCounter, parityField, maxClearLine);
    return limitation.enumerate().parallelStream().map(EstimateBuilder::create).flatMap(Collection::stream).flatMap(deltaLimitedMinos -> parseToSortedFullLimitedMinoStream(positionLimitParser, deltaLimitedMinos)).limit(// parallelでの並列数をリセットする(同時実行数を増やす)
    Long.MAX_VALUE).flatMap(sets -> new CrossBuilder(sets, field, maxClearLine).create().stream()).filter(operationWithKeys -> BuildUp.existsValidBuildPattern(verifyField, operationWithKeys, maxClearLine, threadLocal.get()));
}
Also used : PositionLimitParser(_implements.parity_based_pack.step2.PositionLimitParser) Piece(core.mino.Piece) EstimateBuilder(_implements.parity_based_pack.step1.EstimateBuilder) PositionLimitParser(_implements.parity_based_pack.step2.PositionLimitParser) BuildUp(common.buildup.BuildUp) Collection(java.util.Collection) MinoOperationWithKey(common.datastore.MinoOperationWithKey) DeltaLimitedMino(_implements.parity_based_pack.step1.DeltaLimitedMino) CrossBuilder(_implements.parity_based_pack.step3.CrossBuilder) Collectors(java.util.stream.Collectors) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) PieceCounter(common.datastore.PieceCounter) List(java.util.List) Field(core.field.Field) Stream(java.util.stream.Stream) MinoFactory(core.mino.MinoFactory) ColumnParityLimitation(_implements.parity_based_pack.step1.ColumnParityLimitation) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Comparator(java.util.Comparator) CrossBuilder(_implements.parity_based_pack.step3.CrossBuilder) PieceCounter(common.datastore.PieceCounter) Collection(java.util.Collection) MinoFactory(core.mino.MinoFactory) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) ColumnParityLimitation(_implements.parity_based_pack.step1.ColumnParityLimitation)

Example 22 with MinoOperationWithKey

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

the class CrossBuilder method recordResult.

private void recordResult() {
    boolean isReuse = true;
    for (int index = 0; index < prev.length; index++) {
        if (!isReuse || fullLimitedMinos[index] != prev[index]) {
            isReuse = false;
            List<XField> xFields = cache.get(index);
            List<XField> nextXFields = new ArrayList<>();
            for (XField xField : xFields) {
                Field field = xField.getField();
                XHistory xHistory = xField.getxHistory();
                FullLimitedMino current = fullLimitedMinos[index];
                MinoMask minoMask = current.getMinoMask();
                int[] xs = current.getXs();
                for (int x : xs) {
                    Field mask = minoMask.getMinoMask(x);
                    if (field.canMerge(mask)) {
                        Field newField = field.freeze(maxClearLine);
                        newField.merge(mask);
                        if (perfectValidator.validate(newField, maxClearLine)) {
                            XHistory newHistory = xHistory.recordAndReturnNew(x);
                            nextXFields.add(new XField(newField, newHistory));
                        }
                    }
                }
            }
            if (index < prev.length - 1) {
                cache.set(index + 1, nextXFields);
            } else {
                for (XField nextXField : nextXFields) {
                    int[] history = nextXField.getxHistory().getHistory();
                    assert fullLimitedMinos.length == history.length;
                    List<MinoOperationWithKey> result = new ArrayList<>();
                    for (int i = 0, length = history.length; i < length; i++) {
                        FullLimitedMino limitedMino = fullLimitedMinos[i];
                        int x = history[i];
                        Mino mino = limitedMino.getMino();
                        long deleteKey = limitedMino.getDeleteKey();
                        long usingKey = limitedMino.getUsingKey();
                        int lowerY = limitedMino.getLowerY();
                        MinoOperationWithKey withKey = new FullOperationWithKey(mino, x, deleteKey, usingKey, lowerY);
                        result.add(withKey);
                    }
                    results.add(result);
                }
            }
            prev[index] = fullLimitedMinos[index];
        }
    }
}
Also used : FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) ArrayList(java.util.ArrayList) FullOperationWithKey(common.datastore.FullOperationWithKey) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) MinoMask(searcher.pack.separable_mino.mask.MinoMask) FullLimitedMino(_implements.parity_based_pack.step2.FullLimitedMino) Mino(core.mino.Mino)

Example 23 with MinoOperationWithKey

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

the class BuildUpStreamTest method buildUp2.

@Test
void buildUp2() {
    // Create LockedReachable
    int height = 4;
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    // Create OperationWithKey List
    Field field = FieldFactory.createField("" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX" + "____XXXXXX");
    Operations operations = OperationInterpreter.parseToOperations("J,R,0,1;O,0,1,0;L,L,3,1;I,0,1,0");
    List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
    // Create Pieces
    Set<String> valid = new BuildUpStream(reachable, height).existsValidBuildPattern(field, operationWithKeys).map(op -> op.stream().map(OperationWithKey::getPiece).map(Piece::name).collect(Collectors.joining())).collect(Collectors.toSet());
    // Assertion
    assertThat(valid).hasSize(16).doesNotContain("IJOL", "IJLO", "IOJL", "IOLJ", "ILOJ", // starts I
    "ILJO").doesNotContain("OIJL", // starts OI
    "OILJ").contains("OJLI", "OJIL", "JOIL", "JLIO", "LOJI", "LIOJ");
}
Also used : TaskResultHelper(searcher.pack.task.TaskResultHelper) Randoms(lib.Randoms) OperationTransform(common.parser.OperationTransform) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ColumnField(core.column_field.ColumnField) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationInterpreter(common.parser.OperationInterpreter) AllPassedSolutionFilter(searcher.pack.memento.AllPassedSolutionFilter) FieldView(core.field.FieldView) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeparableMinos(searcher.pack.SeparableMinos) FieldFactory(core.field.FieldFactory) Tag(org.junit.jupiter.api.Tag) LinkedList(java.util.LinkedList) MinoRotation(core.srs.MinoRotation) LockedReachable(core.action.reachable.LockedReachable) PerfectPackSearcher(searcher.pack.task.PerfectPackSearcher) OperationWithKey(common.datastore.OperationWithKey) Field4x10MinoPackingHelper(searcher.pack.task.Field4x10MinoPackingHelper) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) PermutationIterable(common.iterable.PermutationIterable) Predicate(java.util.function.Predicate) Result(searcher.pack.task.Result) InOutPairField(searcher.pack.InOutPairField) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Operations(common.datastore.Operations) SolutionFilter(searcher.pack.memento.SolutionFilter) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) SRSValidSolutionFilter(searcher.pack.memento.SRSValidSolutionFilter) Optional(java.util.Optional) OnDemandBasicSolutions(searcher.pack.solutions.OnDemandBasicSolutions) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongTest(module.LongTest) MinoOperationWithKey(common.datastore.MinoOperationWithKey) OperationWithKey(common.datastore.OperationWithKey) MinoRotation(core.srs.MinoRotation) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) MinoOperationWithKey(common.datastore.MinoOperationWithKey) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) Operations(common.datastore.Operations) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 24 with MinoOperationWithKey

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

the class CSVPathOutput method outputOperationsToCSV.

private void outputOperationsToCSV(Field field, MyFile file, List<PathPair> pathPairs, SizedBit sizedBit) throws FinderExecuteException {
    LockedBuildUpListUpThreadLocal threadLocal = new LockedBuildUpListUpThreadLocal(sizedBit.getHeight());
    List<List<MinoOperationWithKey>> samples = pathPairs.parallelStream().map(resultPair -> {
        Result result = resultPair.getResult();
        LinkedList<MinoOperationWithKey> operations = result.getMemento().getSeparableMinoStream(sizedBit.getWidth()).map(SeparableMino::toMinoOperationWithKey).collect(Collectors.toCollection(LinkedList::new));
        BuildUpStream buildUpStream = threadLocal.get();
        return buildUpStream.existsValidBuildPatternDirectly(field, operations).findFirst().orElse(Collections.emptyList());
    }).collect(Collectors.toList());
    try (BufferedWriter writer = file.newBufferedWriter()) {
        for (List<MinoOperationWithKey> operationWithKeys : samples) {
            Operations operations = OperationTransform.parseToOperations(field, operationWithKeys, sizedBit.getHeight());
            String operationLine = OperationInterpreter.parseToString(operations);
            writer.write(operationLine);
            writer.newLine();
        }
        writer.flush();
    } catch (IOException e) {
        throw new FinderExecuteException("Failed to output file", e);
    }
}
Also used : OperationTransform(common.parser.OperationTransform) entry.path(entry.path) BufferedWriter(java.io.BufferedWriter) Result(searcher.pack.task.Result) LongPieces(common.datastore.blocks.LongPieces) MinoOperationWithKey(common.datastore.MinoOperationWithKey) IOException(java.io.IOException) OperationInterpreter(common.parser.OperationInterpreter) FinderExecuteException(exceptions.FinderExecuteException) FinderInitializeException(exceptions.FinderInitializeException) Collectors(java.util.stream.Collectors) File(java.io.File) Operations(common.datastore.Operations) SizedBit(searcher.pack.SizedBit) List(java.util.List) Field(core.field.Field) SeparableMino(searcher.pack.separable_mino.SeparableMino) LinkedList(java.util.LinkedList) Collections(java.util.Collections) BuildUpStream(common.buildup.BuildUpStream) SeparableMino(searcher.pack.separable_mino.SeparableMino) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Result(searcher.pack.task.Result) BufferedWriter(java.io.BufferedWriter) MinoOperationWithKey(common.datastore.MinoOperationWithKey) List(java.util.List) LinkedList(java.util.LinkedList) FinderExecuteException(exceptions.FinderExecuteException) BuildUpStream(common.buildup.BuildUpStream) Operations(common.datastore.Operations)

Example 25 with MinoOperationWithKey

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

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