Search in sources :

Example 6 with PerfectValidator

use of searcher.common.validator.PerfectValidator in project solution-finder by knewjade.

the class BuildUpTest method cansBuildRandomLongByCheck.

@Test
@LongTest
void cansBuildRandomLongByCheck() {
    Randoms randoms = new Randoms();
    // Create field
    int height = 4;
    // Initialize
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    PerfectValidator validator = new PerfectValidator();
    CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, height);
    AtomicInteger counter = new AtomicInteger();
    for (int count = 0; count < 100; count++) {
        // Pickup solution from checker
        int numOfMinos = randoms.nextIntClosed(7, 10);
        Field field = randoms.field(height, numOfMinos);
        List<Piece> pieces = randoms.blocks(numOfMinos);
        boolean check = checker.check(field, pieces, candidate, height, numOfMinos);
        if (check) {
            counter.incrementAndGet();
            Stream<Operation> operationStream = ResultHelper.createOperationStream(checker.getResult());
            Operations operations = new Operations(operationStream);
            List<MinoOperationWithKey> operationWithKeys = OperationTransform.parseToOperationWithKeys(field, operations, minoFactory, height);
            assertThat(BuildUp.cansBuild(field, operationWithKeys, height, reachable)).as(FieldView.toString(field) + pieces).isTrue();
        }
    }
    System.out.println(counter);
}
Also used : Action(common.datastore.action.Action) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) ColumnField(core.column_field.ColumnField) InOutPairField(searcher.pack.InOutPairField) Field(core.field.Field) Randoms(lib.Randoms) CheckerUsingHold(searcher.checker.CheckerUsingHold) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) LockedReachable(core.action.reachable.LockedReachable) PerfectValidator(searcher.common.validator.PerfectValidator) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 7 with PerfectValidator

use of searcher.common.validator.PerfectValidator 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 8 with PerfectValidator

use of searcher.common.validator.PerfectValidator in project solution-finder by knewjade.

the class CheckerUsingHoldCountTest method testTemplate.

@Test
void testTemplate() throws Exception {
    // Invoker
    List<Piece> pieces = Arrays.asList(I, T, S, Z, J, L, O);
    int popCount = 4;
    int maxClearLine = 4;
    int maxDepth = 3;
    // Field
    String marks = "" + "XXXXX____X" + "XXXXXX___X" + "XXXXXXX__X" + "XXXXXX___X" + "";
    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();
    Iterable<List<Piece>> combinations = new PermutationIterable<>(pieces, popCount);
    for (List<Piece> combination : combinations) {
        boolean result = checker.check(field, combination, candidate, maxClearLine, maxDepth);
        tree.set(result, combination);
    }
    // Source: Nilgiri: https://docs.google.com/spreadsheets/d/1bVY3t_X96xRmUL0qdgB9tViSIGenu6RMKX4RW7qWg8Y/edit#gid=0
    assertThat(tree.getSuccessPercent()).isEqualTo(514 / 840.0);
}
Also used : Action(common.datastore.action.Action) PermutationIterable(common.iterable.PermutationIterable) 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) List(java.util.List) PerfectValidator(searcher.common.validator.PerfectValidator) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 9 with PerfectValidator

use of searcher.common.validator.PerfectValidator in project solution-finder by knewjade.

the class CheckerUsingHoldCountTest method testBT4_5.

@Test
@LongTest
void testBT4_5() throws Exception {
    // Invoker
    List<Piece> pieces = Arrays.asList(I, T, S, Z, J, L, O);
    int popCount = 7;
    int maxClearLine = 6;
    int maxDepth = 7;
    // Field
    String marks = "" + "XX________" + "XX________" + "XXX______X" + "XXXXXXX__X" + "XXXXXX___X" + "XXXXXXX_XX" + "";
    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();
    Iterable<List<Piece>> combinations = new PermutationIterable<>(pieces, popCount);
    for (List<Piece> combination : combinations) {
        boolean result = checker.check(field, combination, candidate, maxClearLine, maxDepth);
        tree.set(result, combination);
    }
    // Source: myself 20170415
    assertThat(tree.getSuccessPercent()).isEqualTo(5038 / 5040.0);
}
Also used : Action(common.datastore.action.Action) PermutationIterable(common.iterable.PermutationIterable) 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) List(java.util.List) PerfectValidator(searcher.common.validator.PerfectValidator) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest)

Example 10 with PerfectValidator

use of searcher.common.validator.PerfectValidator in project solution-finder by knewjade.

the class CheckerUsingHoldCountTest method runTestCase.

private AnalyzeTree runTestCase(List<Piece> pieces, int popCount, 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();
    CheckerUsingHold<Action> checker = new CheckerUsingHold<>(minoFactory, validator);
    // Measure
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    AnalyzeTree tree = new AnalyzeTree();
    Iterable<List<Piece>> combinations = new PermutationIterable<>(pieces, popCount);
    for (List<Piece> combination : combinations) {
        // Hold分の追加
        combination.add(0, Piece.T);
        boolean result = checker.check(field, combination, candidate, maxClearLine, maxDepth);
        tree.set(result, combination);
    }
    return tree;
}
Also used : Action(common.datastore.action.Action) PermutationIterable(common.iterable.PermutationIterable) 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) List(java.util.List) PerfectValidator(searcher.common.validator.PerfectValidator)

Aggregations

PerfectValidator (searcher.common.validator.PerfectValidator)15 Action (common.datastore.action.Action)13 LockedCandidate (core.action.candidate.LockedCandidate)13 Field (core.field.Field)13 MinoFactory (core.mino.MinoFactory)13 MinoShifter (core.mino.MinoShifter)11 MinoRotation (core.srs.MinoRotation)11 Piece (core.mino.Piece)10 AnalyzeTree (common.tree.AnalyzeTree)8 LongTest (module.LongTest)8 PatternGenerator (common.pattern.PatternGenerator)6 Randoms (lib.Randoms)6 Test (org.junit.jupiter.api.Test)6 Pieces (common.datastore.blocks.Pieces)5 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)5 PermutationIterable (common.iterable.PermutationIterable)4 LockedReachable (core.action.reachable.LockedReachable)4 ColumnField (core.column_field.ColumnField)4 List (java.util.List)4 CheckerNoHold (searcher.checker.CheckerNoHold)4