Search in sources :

Example 1 with CheckerUsingHold

use of searcher.checker.CheckerUsingHold in project solution-finder by knewjade.

the class BuildUpTest method cansBuildRandomShortByCheck.

@Test
void cansBuildRandomShortByCheck() {
    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 < 10000; count++) {
        // Pickup solution from checker
        int numOfMinos = randoms.nextInt(1, 7);
        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)

Example 2 with CheckerUsingHold

use of searcher.checker.CheckerUsingHold 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 3 with CheckerUsingHold

use of searcher.checker.CheckerUsingHold in project solution-finder by knewjade.

the class CheckerUsingHoldThreadLocal method initialValue.

@Override
protected Checker<T> initialValue() {
    MinoFactory minoFactory = new MinoFactory();
    PerfectValidator validator = new PerfectValidator();
    return new CheckerUsingHold<>(minoFactory, validator);
}
Also used : CheckerUsingHold(searcher.checker.CheckerUsingHold) MinoFactory(core.mino.MinoFactory) PerfectValidator(searcher.common.validator.PerfectValidator)

Example 4 with CheckerUsingHold

use of searcher.checker.CheckerUsingHold 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)

Aggregations

MinoFactory (core.mino.MinoFactory)4 CheckerUsingHold (searcher.checker.CheckerUsingHold)4 PerfectValidator (searcher.common.validator.PerfectValidator)4 Action (common.datastore.action.Action)3 LockedCandidate (core.action.candidate.LockedCandidate)3 Field (core.field.Field)3 MinoShifter (core.mino.MinoShifter)3 MinoRotation (core.srs.MinoRotation)3 Randoms (lib.Randoms)3 LongTest (module.LongTest)3 LockedReachable (core.action.reachable.LockedReachable)2 ColumnField (core.column_field.ColumnField)2 Piece (core.mino.Piece)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.jupiter.api.Test)2 InOutPairField (searcher.pack.InOutPairField)2 Injector (com.google.inject.Injector)1 Pair (common.datastore.Pair)1 Pieces (common.datastore.blocks.Pieces)1 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)1