Search in sources :

Example 51 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class CheckerUsingHoldInvokerTest method testSearch11.

@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void testSearch11(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws Exception {
    PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p5");
    int maxClearLine = 4;
    int maxDepth = 4;
    String marks = "" + "XXXX______" + "XXXXXXXXXX" + "XXXXX_____" + "XXXX_____X" + "";
    ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
    AnalyzeTree tree = runTestCase(invoker, marks, blocksGenerator, maxClearLine, maxDepth);
    // Source: myself 20170707
    assertThat(tree.getSuccessPercent()).isEqualTo(1758 / 2520.0);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 52 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class CheckerUsingHoldInvokerTest method testSearch2BT4_5.

@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void testSearch2BT4_5(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws Exception {
    PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p7");
    int maxClearLine = 6;
    int maxDepth = 7;
    String marks = "" + "XX________" + "XX________" + "XXX______X" + "XXXXXXX__X" + "XXXXXX___X" + "XXXXXXX_XX" + "";
    ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
    AnalyzeTree tree = runTestCase(invoker, marks, blocksGenerator, maxClearLine, maxDepth);
    // Source: myself 20170415
    assertThat(tree.getSuccessPercent()).isEqualTo(5038 / 5040.0);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 53 with PatternGenerator

use of common.pattern.PatternGenerator in project solution-finder by knewjade.

the class Verify method patterns.

public static PatternGenerator patterns(List<String> patterns, int depth) throws FinderInitializeException {
    PatternGenerator generator = patterns(patterns);
    int piecesDepth = generator.getDepth();
    if (piecesDepth < depth)
        throw new FinderInitializeException(String.format("Should specify equal to or more than %d pieces: CurrentPieces=%d", depth, piecesDepth));
    return generator;
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) FinderInitializeException(exceptions.FinderInitializeException)

Example 54 with PatternGenerator

use of common.pattern.PatternGenerator 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 55 with PatternGenerator

use of common.pattern.PatternGenerator 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

PatternGenerator (common.pattern.PatternGenerator)71 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)67 Test (org.junit.jupiter.api.Test)35 LongPieces (common.datastore.blocks.LongPieces)34 AnalyzeTree (common.tree.AnalyzeTree)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)27 Piece (core.mino.Piece)13 Randoms (lib.Randoms)12 Field (core.field.Field)10 Pieces (common.datastore.blocks.Pieces)9 MinoFactory (core.mino.MinoFactory)9 LongTest (module.LongTest)9 Action (common.datastore.action.Action)6 LockedCandidate (core.action.candidate.LockedCandidate)6 MinoShifter (core.mino.MinoShifter)6 HashSet (java.util.HashSet)6 PerfectValidator (searcher.common.validator.PerfectValidator)6 EntryPoint (entry.EntryPoint)5 ColorConverter (common.tetfu.common.ColorConverter)4