Search in sources :

Example 21 with AnalyzeTree

use of common.tree.AnalyzeTree in project solution-finder by knewjade.

the class CheckerUsingHoldInvokerTest method random.

@LongTest
@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void random(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws FinderExecuteException, SyntaxException {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
    for (int count = 0; count < 20; count++) {
        int maxClearLine = randoms.nextInt(3, 6);
        int maxDepth = randoms.nextIntClosed(3, 5);
        Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
        Field field = randoms.field(maxClearLine, maxDepth);
        PatternGenerator blocksGenerator = createPiecesGenerator(maxDepth);
        List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
        Injector injector = Guice.createInjector(new BasicModule(maxClearLine));
        ExecutorService executorService = injector.getInstance(ExecutorService.class);
        ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
        List<Pair<Pieces, Boolean>> resultPairs = invoker.search(field, searchingPieces, maxClearLine, maxDepth);
        // 結果を集計する
        AnalyzeTree tree1 = new AnalyzeTree();
        for (Pair<Pieces, Boolean> resultPair : resultPairs) {
            Pieces pieces1 = resultPair.getKey();
            Boolean result = resultPair.getValue();
            tree1.set(result, pieces1);
        }
        System.out.println(tree1.show());
        executorService.shutdown();
        AnalyzeTree tree = tree1;
        for (Pieces pieces : searchingPieces) {
            boolean check = checker.check(field, pieces.getPieces(), candidate, maxClearLine, maxDepth);
            assertThat(tree.isSucceed(pieces)).isEqualTo(check);
        }
    }
}
Also used : Action(common.datastore.action.Action) BasicModule(module.BasicModule) LockedCandidate(core.action.candidate.LockedCandidate) Field(core.field.Field) Injector(com.google.inject.Injector) MinoFactory(core.mino.MinoFactory) PerfectValidator(searcher.common.validator.PerfectValidator) Pieces(common.datastore.blocks.Pieces) Pair(common.datastore.Pair) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) MinoRotation(core.srs.MinoRotation) Randoms(lib.Randoms) CheckerUsingHold(searcher.checker.CheckerUsingHold) ExecutorService(java.util.concurrent.ExecutorService) MinoShifter(core.mino.MinoShifter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 22 with AnalyzeTree

use of common.tree.AnalyzeTree in project solution-finder by knewjade.

the class CheckerNoHoldCountTest method runTestCase.

private AnalyzeTree runTestCase(PatternGenerator blocksGenerator, int maxClearLine, int maxDepth, String marks) {
    Field field = FieldFactory.createField(marks);
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
    // Measure
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    AnalyzeTree tree = new AnalyzeTree();
    blocksGenerator.blocksStream().forEach(blocks -> {
        List<Piece> pieceList = blocks.getPieces();
        boolean result = checker.check(field, pieceList, candidate, maxClearLine, maxDepth);
        tree.set(result, pieceList);
    });
    return tree;
}
Also used : Action(common.datastore.action.Action) AnalyzeTree(common.tree.AnalyzeTree) Field(core.field.Field) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) PerfectValidator(searcher.common.validator.PerfectValidator)

Example 23 with AnalyzeTree

use of common.tree.AnalyzeTree in project solution-finder by knewjade.

the class CheckerNoHoldCountTest method testCase4.

@Test
void testCase4() throws Exception {
    // Invoker
    PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p7");
    int maxClearLine = 4;
    int maxDepth = 6;
    // Field
    String marks = "" + "XXXX______" + "XXXX______" + "XXXX______" + "XXXX______" + "";
    AnalyzeTree tree = runTestCase(blocksGenerator, maxClearLine, maxDepth, marks);
    // Source: myself 20170415
    assertThat(tree.getSuccessPercent()).isEqualTo(1902 / 5040.0);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) Test(org.junit.jupiter.api.Test)

Example 24 with AnalyzeTree

use of common.tree.AnalyzeTree in project solution-finder by knewjade.

the class CheckerNoHoldCountTest method testCase2.

@Test
void testCase2() throws Exception {
    // Invoker
    PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p4");
    int maxClearLine = 5;
    int maxDepth = 4;
    // Field
    String marks = "" + "____XXXXXX" + "____XXXXXX" + "___XXXXXXX" + "__XXXXXXXX" + "___XXXXXXX" + "";
    AnalyzeTree tree = runTestCase(blocksGenerator, maxClearLine, maxDepth, marks);
    // Source: reply in twitter from @fullfool_14
    assertThat(tree.getSuccessPercent()).isEqualTo(477 / 2520.0);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) Test(org.junit.jupiter.api.Test)

Example 25 with AnalyzeTree

use of common.tree.AnalyzeTree in project solution-finder by knewjade.

the class CheckerNoHoldCountTest method testCase3.

@Test
void testCase3() throws Exception {
    // Invoker
    PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p7");
    int maxClearLine = 4;
    int maxDepth = 6;
    // Field
    String marks = "" + "X_________" + "X___X_____" + "XXXXXXX___" + "XXXXXX____" + "";
    AnalyzeTree tree = runTestCase(blocksGenerator, maxClearLine, maxDepth, marks);
    // Source: reply in twitter from @fullfool_14
    assertThat(tree.getSuccessPercent()).isEqualTo(727 / 5040.0);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) Test(org.junit.jupiter.api.Test)

Aggregations

AnalyzeTree (common.tree.AnalyzeTree)42 PatternGenerator (common.pattern.PatternGenerator)33 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)27 Field (core.field.Field)10 MinoFactory (core.mino.MinoFactory)9 Test (org.junit.jupiter.api.Test)9 Action (common.datastore.action.Action)8 LockedCandidate (core.action.candidate.LockedCandidate)8 MinoShifter (core.mino.MinoShifter)8 MinoRotation (core.srs.MinoRotation)8 PerfectValidator (searcher.common.validator.PerfectValidator)8 Piece (core.mino.Piece)7 LongTest (module.LongTest)7 Pieces (common.datastore.blocks.Pieces)6 List (java.util.List)5 Pair (common.datastore.Pair)4 PermutationIterable (common.iterable.PermutationIterable)4 LongPieces (common.datastore.blocks.LongPieces)2