Search in sources :

Example 16 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class AllSeparableMinoFactoryTest method create2x4.

@Test
void create2x4() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    int width = 2;
    int height = 4;
    Set<SeparableMino> minos = getSeparableMinos(minoFactory, minoShifter, width, height);
    for (SeparableMino separableMino : minos) {
        ColumnField field = separableMino.getColumnField();
        System.out.println(ColumnFieldView.toString(field, 5, 4));
        System.out.println("===");
    }
    assertThat(minos.stream()).hasSize(182);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.T))).hasSize(40);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.I))).hasSize(10);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.S))).hasSize(20);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.Z))).hasSize(20);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.O))).hasSize(12);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.L))).hasSize(40);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.J))).hasSize(40);
}
Also used : ColumnField(core.column_field.ColumnField) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test)

Example 17 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class AllSeparableMinoFactoryTest method create2x5.

@Test
void create2x5() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    int width = 2;
    int height = 5;
    Set<SeparableMino> minos = getSeparableMinos(minoFactory, minoShifter, width, height);
    assertThat(minos.stream()).hasSize(360);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.T))).hasSize(80);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.I))).hasSize(20);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.S))).hasSize(40);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.Z))).hasSize(40);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.O))).hasSize(20);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.L))).hasSize(80);
    assertThat(minos.stream().filter(createBlockPredicate(Piece.J))).hasSize(80);
}
Also used : MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test)

Example 18 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class SequenceFumenParser method parse.

@Override
public String parse(List<MinoOperationWithKey> operations, Field field, int maxClearLine) {
    Operations operations2 = OperationTransform.parseToOperations(field, operations, maxClearLine);
    List<? extends Operation> operationsList = operations2.getOperations();
    // ブロック順に変換
    List<Piece> pieceList = operationsList.stream().map(Operation::getPiece).collect(Collectors.toList());
    // テト譜を作成
    String quiz = Tetfu.encodeForQuiz(pieceList);
    ArrayList<TetfuElement> tetfuElements = new ArrayList<>();
    // 最初のelement
    Operation firstKey = operationsList.get(0);
    ColorType colorType1 = colorConverter.parseToColorType(firstKey.getPiece());
    ColoredField coloredField = createInitColoredField(field, maxClearLine);
    TetfuElement firstElement = new TetfuElement(coloredField, colorType1, firstKey.getRotate(), firstKey.getX(), firstKey.getY(), quiz);
    tetfuElements.add(firstElement);
    // 2番目以降のelement
    if (1 < operationsList.size()) {
        operationsList.subList(1, operationsList.size()).stream().map(operation -> {
            ColorType colorType = colorConverter.parseToColorType(operation.getPiece());
            return new TetfuElement(colorType, operation.getRotate(), operation.getX(), operation.getY(), quiz);
        }).forEach(tetfuElements::add);
    }
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    return tetfu.encode(tetfuElements);
}
Also used : Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) OperationTransform(common.parser.OperationTransform) MinoOperationWithKey(common.datastore.MinoOperationWithKey) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement) ColorConverter(common.tetfu.common.ColorConverter) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Operations(common.datastore.Operations) List(java.util.List) Field(core.field.Field) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Operation(common.datastore.Operation) ColoredField(common.tetfu.field.ColoredField) ColoredField(common.tetfu.field.ColoredField) ArrayList(java.util.ArrayList) Operation(common.datastore.Operation) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Operations(common.datastore.Operations) Tetfu(common.tetfu.Tetfu) TetfuElement(common.tetfu.TetfuElement)

Example 19 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class PercentEntryPoint method run.

@Override
public void run() throws FinderException {
    output("# Setup Field");
    // Setup field
    Field field = settings.getField();
    Verify.field(field);
    // Setup max clear line
    int maxClearLine = settings.getMaxClearLine();
    Verify.maxClearLineUnder12(maxClearLine);
    // Output field
    output(FieldView.toString(field, maxClearLine));
    // Setup max depth
    // パフェに必要なミノ数
    int maxDepth = Verify.maxDepth(field, maxClearLine);
    output();
    // ========================================
    // Output user-defined
    output("# Initialize / User-defined");
    output("Max clear lines: " + maxClearLine);
    output("Using hold: " + (settings.isUsingHold() ? "use" : "avoid"));
    output("Drop: " + settings.getDropType().name().toLowerCase());
    output("Searching patterns:");
    // Setup patterns
    List<String> patterns = settings.getPatterns();
    PatternGenerator generator = Verify.patterns(patterns, maxDepth);
    // Output patterns
    for (String pattern : patterns) output("  " + pattern);
    output();
    // ========================================
    // Setup core
    output("# Initialize / System");
    ExecutorService executorService = createExecutorService();
    output("Version = " + FinderConstant.VERSION);
    output("Necessary Pieces = " + maxDepth);
    output();
    // ========================================
    // Holdができるときは必要なミノ分(maxDepth + 1)だけを取り出す。maxDepth + 1だけないときはブロックの個数をそのまま指定
    output("# Enumerate pieces");
    int piecesDepth = generator.getDepth();
    int popCount = settings.isUsingHold() && maxDepth < piecesDepth ? maxDepth + 1 : maxDepth;
    output("Piece pop count = " + popCount);
    if (popCount < piecesDepth) {
        output();
        output("####################################################################");
        output("WARNING: Inputted pieces is more than 'necessary blocks'.");
        output("         Because reduce unnecessary pieces,");
        output("         there is a possibility of getting no expected percentages.");
        output("####################################################################");
        output();
    }
    // 探索パターンの列挙
    NormalEnumeratePieces normalEnumeratePieces = new NormalEnumeratePieces(generator, maxDepth, settings.isUsingHold());
    Set<LongPieces> searchingPieces = normalEnumeratePieces.enumerate();
    output("Searching pattern size (duplicate) = " + normalEnumeratePieces.getCounter());
    output("Searching pattern size ( no dup. ) = " + searchingPieces.size());
    output();
    // ========================================
    // 探索を行う
    output("# Search");
    output("  -> Stopwatch start");
    Stopwatch stopwatch = Stopwatch.createStartedStopwatch();
    ThreadLocal<Candidate<Action>> candidateThreadLocal = createCandidateThreadLocal(settings.getDropType(), maxClearLine);
    ThreadLocal<? extends Reachable> reachableThreadLocal = createReachableThreadLocal(settings.getDropType(), maxClearLine);
    MinoFactory minoFactory = new MinoFactory();
    PercentCore percentCore = new PercentCore(executorService, candidateThreadLocal, settings.isUsingHold(), reachableThreadLocal, minoFactory);
    percentCore.run(field, searchingPieces, maxClearLine, maxDepth);
    AnalyzeTree tree = percentCore.getResultTree();
    List<Pair<Pieces, Boolean>> resultPairs = percentCore.getResultPairs();
    stopwatch.stop();
    output("  -> Stopwatch stop : " + stopwatch.toMessage(TimeUnit.MILLISECONDS));
    output();
    // ========================================
    // Output tree
    output("# Output");
    output(tree.show());
    output();
    // Output failed patterns
    int treeDepth = settings.getTreeDepth();
    if (piecesDepth < treeDepth)
        treeDepth = piecesDepth;
    output(String.format("Success pattern tree [Head %d pieces]:", treeDepth));
    output(tree.tree(treeDepth));
    output("-------------------");
    int failedMaxCount = settings.getFailedCount();
    // skip if failedMaxCount == 0
    if (0 < failedMaxCount) {
        output(String.format("Fail pattern (max. %d)", failedMaxCount));
        List<Pair<Pieces, Boolean>> failedPairs = resultPairs.stream().filter(pair -> !pair.getValue()).limit(failedMaxCount).collect(Collectors.toList());
        outputFailedPatterns(failedPairs);
    } else if (failedMaxCount < 0) {
        output("Fail pattern (all)");
        List<Pair<Pieces, Boolean>> failedPairs = resultPairs.stream().filter(pair -> !pair.getValue()).collect(Collectors.toList());
        outputFailedPatterns(failedPairs);
    }
    output();
    // ========================================
    output("# Finalize");
    if (executorService != null)
        executorService.shutdown();
    output("done");
}
Also used : Candidate(core.action.candidate.Candidate) PatternGenerator(common.pattern.PatternGenerator) Stopwatch(lib.Stopwatch) EntryPoint(entry.EntryPoint) AnalyzeTree(common.tree.AnalyzeTree) Field(core.field.Field) LongPieces(common.datastore.blocks.LongPieces) NormalEnumeratePieces(entry.searching_pieces.NormalEnumeratePieces) ExecutorService(java.util.concurrent.ExecutorService) MinoFactory(core.mino.MinoFactory) List(java.util.List) Pair(common.datastore.Pair) Pieces(common.datastore.blocks.Pieces) LongPieces(common.datastore.blocks.LongPieces) NormalEnumeratePieces(entry.searching_pieces.NormalEnumeratePieces)

Example 20 with MinoFactory

use of core.mino.MinoFactory in project solution-finder by knewjade.

the class PercentSettingParser method encodeTetfu.

private List<TetfuPage> encodeTetfu(String encoded) throws FinderParseException {
    MinoFactory minoFactory = new MinoFactory();
    ColorConverter colorConverter = new ColorConverter();
    Tetfu tetfu = new Tetfu(minoFactory, colorConverter);
    String data = Tetfu.removePrefixData(encoded);
    if (data == null)
        throw new FinderParseException("Unsupported tetfu: data=" + encoded);
    return tetfu.decode(data);
}
Also used : FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) MinoFactory(core.mino.MinoFactory) Tetfu(common.tetfu.Tetfu)

Aggregations

MinoFactory (core.mino.MinoFactory)113 Test (org.junit.jupiter.api.Test)70 MinoShifter (core.mino.MinoShifter)59 LongTest (module.LongTest)51 Field (core.field.Field)45 MinoRotation (core.srs.MinoRotation)40 ColorConverter (common.tetfu.common.ColorConverter)33 Piece (core.mino.Piece)28 Action (common.datastore.action.Action)22 ColumnField (core.column_field.ColumnField)22 Randoms (lib.Randoms)22 InOutPairField (searcher.pack.InOutPairField)21 LockedReachable (core.action.reachable.LockedReachable)17 PerfectValidator (searcher.common.validator.PerfectValidator)17 LockedCandidate (core.action.candidate.LockedCandidate)16 MinoOperationWithKey (common.datastore.MinoOperationWithKey)15 List (java.util.List)15 Collectors (java.util.stream.Collectors)15 PermutationIterable (common.iterable.PermutationIterable)12 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)12