Search in sources :

Example 11 with Operations

use of common.datastore.Operations 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 12 with Operations

use of common.datastore.Operations 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 13 with Operations

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

Aggregations

Operations (common.datastore.Operations)13 Field (core.field.Field)11 MinoOperationWithKey (common.datastore.MinoOperationWithKey)10 Test (org.junit.jupiter.api.Test)10 MinoFactory (core.mino.MinoFactory)9 ColumnField (core.column_field.ColumnField)7 LongTest (module.LongTest)7 InOutPairField (searcher.pack.InOutPairField)7 Piece (core.mino.Piece)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 OperationTransform (common.parser.OperationTransform)5 MinoShifter (core.mino.MinoShifter)5 MinoRotation (core.srs.MinoRotation)5 Randoms (lib.Randoms)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 SizedBit (searcher.pack.SizedBit)5 SeparableMino (searcher.pack.separable_mino.SeparableMino)5 Result (searcher.pack.task.Result)5 Operation (common.datastore.Operation)4