Search in sources :

Example 26 with LoadedPatternGenerator

use of common.pattern.LoadedPatternGenerator 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 27 with LoadedPatternGenerator

use of common.pattern.LoadedPatternGenerator 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 28 with LoadedPatternGenerator

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

Example 29 with LoadedPatternGenerator

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

the class CheckerUsingHoldCountTest method testTemplateWithHoldI.

@Test
void testTemplateWithHoldI() throws Exception {
    // Invoker
    String pattern = "I, *p4";
    int maxClearLine = 4;
    int maxDepth = 4;
    // Field
    String marks = "" + "XXXXX_____" + "XXXXXX____" + "XXXXXXX___" + "XXXXXX____" + "";
    Field field = FieldFactory.createField(marks);
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
    // Measure
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    AnalyzeTree tree = new AnalyzeTree();
    PatternGenerator generator = new LoadedPatternGenerator(pattern);
    generator.blocksStream().forEach(blocks -> {
        List<Piece> pieceList = blocks.getPieces();
        boolean result = checker.check(field, pieceList, candidate, maxClearLine, maxDepth);
        tree.set(result, pieceList);
    });
    // Source: Nilgiri: https://docs.google.com/spreadsheets/d/1bVY3t_X96xRmUL0qdgB9tViSIGenu6RMKX4RW7qWg8Y/edit#gid=0
    assertThat(tree.getSuccessPercent()).isEqualTo(711 / 840.0);
}
Also used : Action(common.datastore.action.Action) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) 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) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 30 with LoadedPatternGenerator

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

the class AnalyzeTreeTest method randomLong.

@Test
@LongTest
void randomLong() throws SyntaxException {
    Randoms randoms = new Randoms();
    for (int size = 8; size <= 11; size++) {
        PatternGenerator generator = new LoadedPatternGenerator("*p7, *p" + (size - 7));
        AnalyzeTree tree = new AnalyzeTree();
        HashSet<LongPieces> success = new HashSet<>();
        HashSet<LongPieces> failed = new HashSet<>();
        generator.blocksStream().forEach(blocks -> {
            boolean flag = randoms.nextBoolean();
            List<Piece> pieceList = blocks.getPieces();
            tree.set(flag, pieceList);
            LongPieces longPieces = new LongPieces(pieceList);
            if (flag) {
                success.add(longPieces);
            } else {
                failed.add(longPieces);
            }
        });
        boolean isSucceed = success.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isVisited(blocks) && tree.isSucceed(blocks);
        });
        assertThat(isSucceed).isTrue();
        boolean isFailed = failed.stream().allMatch(pieces -> {
            List<Piece> blocks = pieces.getPieces();
            return tree.isVisited(blocks) && !tree.isSucceed(blocks);
        });
        assertThat(isFailed).isTrue();
        double percent = (double) success.size() / (success.size() + failed.size());
        assertThat(tree.getSuccessPercent()).isCloseTo(percent, offset(0.0001));
    }
}
Also used : Randoms(lib.Randoms) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LongPieces(common.datastore.blocks.LongPieces) Piece(core.mino.Piece) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Aggregations

LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)61 PatternGenerator (common.pattern.PatternGenerator)61 Test (org.junit.jupiter.api.Test)35 LongPieces (common.datastore.blocks.LongPieces)31 AnalyzeTree (common.tree.AnalyzeTree)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)25 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)25 Piece (core.mino.Piece)11 Randoms (lib.Randoms)8 LongTest (module.LongTest)7 HashSet (java.util.HashSet)4 Pieces (common.datastore.blocks.Pieces)2 Field (core.field.Field)2 MinoFactory (core.mino.MinoFactory)2 ArrayList (java.util.ArrayList)2 Injector (com.google.inject.Injector)1 Action (common.datastore.action.Action)1 LockedCandidateThreadLocal (concurrent.LockedCandidateThreadLocal)1 LockedReachableThreadLocal (concurrent.LockedReachableThreadLocal)1 LockedCandidate (core.action.candidate.LockedCandidate)1