Search in sources :

Example 21 with Pieces

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

the class ConcurrentVisitedTreeTest method random.

@Test
void random() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 1; size <= 7; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p" + size);
        ConcurrentVisitedTree tree = new ConcurrentVisitedTree();
        Set<LongPieces> success = Collections.synchronizedSet(new HashSet<>());
        Set<LongPieces> failed = Collections.synchronizedSet(new HashSet<>());
        List<Pieces> piecesList = generator.blocksStream().collect(Collectors.toList());
        piecesList.parallelStream().forEach(pieces -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> blocks = pieces.getPieces();
            tree.set(flag, blocks);
            LongPieces longPieces = new LongPieces(blocks);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.SUCCEED;
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isSucceed(blocks) == ConcurrentVisitedTree.FAILED;
        });
        assertThat(isFailed).isTrue();
    }
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) Randoms(lib.Randoms) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) Pieces(common.datastore.blocks.Pieces) LongPieces(common.datastore.blocks.LongPieces) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 22 with Pieces

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

the class CheckerNoHoldInvokerTest method runTestCase.

private AnalyzeTree runTestCase(ConcurrentCheckerInvoker invoker, Field field, List<Pieces> searchingPieces, int maxClearLine, int maxDepth) throws FinderExecuteException {
    List<Pair<Pieces, Boolean>> resultPairs = invoker.search(field, searchingPieces, maxClearLine, maxDepth);
    // 結果を集計する
    AnalyzeTree tree = new AnalyzeTree();
    for (Pair<Pieces, Boolean> resultPair : resultPairs) {
        Pieces pieces = resultPair.getKey();
        Boolean result = resultPair.getValue();
        tree.set(result, pieces);
    }
    System.out.println(tree.show());
    return tree;
}
Also used : Pair(common.datastore.Pair) AnalyzeTree(common.tree.AnalyzeTree) Pieces(common.datastore.blocks.Pieces)

Example 23 with Pieces

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

the class CheckerNoHoldInvokerTest method runTestCase.

private AnalyzeTree runTestCase(ConcurrentCheckerInvoker invoker, String marks, PatternGenerator blocksGenerator, int maxClearLine, int maxDepth) throws FinderExecuteException {
    Field field = FieldFactory.createField(marks);
    List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
    return runTestCase(invoker, field, searchingPieces, maxClearLine, maxDepth);
}
Also used : Field(core.field.Field) Pieces(common.datastore.blocks.Pieces)

Example 24 with Pieces

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

the class DevRandomEntryPoint method run.

@Override
public void run() throws FinderException {
    PatternGenerator generator = createBlockGenerator(pattern);
    List<Pieces> blocks = generator.blocksStream().collect(Collectors.toList());
    int index = new Random().nextInt(blocks.size());
    Pieces selected = blocks.get(index);
    String quiz = Tetfu.encodeForQuiz(selected.getPieces());
    MinoFactory minoFactory = new MinoFactory();
    ColorConverter converter = new ColorConverter();
    ColoredField coloredField = getTetfu(minoFactory, converter);
    Tetfu tetfu = new Tetfu(minoFactory, converter);
    TetfuElement element = new TetfuElement(coloredField, quiz);
    String encode = tetfu.encode(Collections.singletonList(element));
    System.out.println("v115@" + encode);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) ArrayColoredField(common.tetfu.field.ArrayColoredField) ColoredField(common.tetfu.field.ColoredField) Random(java.util.Random) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu) EntryPoint(entry.EntryPoint) Pieces(common.datastore.blocks.Pieces) TetfuElement(common.tetfu.TetfuElement)

Example 25 with Pieces

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

Pieces (common.datastore.blocks.Pieces)25 Field (core.field.Field)16 LongPieces (common.datastore.blocks.LongPieces)13 MinoFactory (core.mino.MinoFactory)12 Piece (core.mino.Piece)12 PatternGenerator (common.pattern.PatternGenerator)10 MinoShifter (core.mino.MinoShifter)10 ExecutionException (java.util.concurrent.ExecutionException)9 Test (org.junit.jupiter.api.Test)9 ColumnField (core.column_field.ColumnField)8 Collectors (java.util.stream.Collectors)8 LongTest (module.LongTest)8 PieceCounter (common.datastore.PieceCounter)7 BlockInterpreter (common.parser.BlockInterpreter)7 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)7 FieldFactory (core.field.FieldFactory)7 Files (java.nio.file.Files)7 Paths (java.nio.file.Paths)7 Stream (java.util.stream.Stream)7 SizedBit (searcher.pack.SizedBit)7