Search in sources :

Example 6 with Pieces

use of common.datastore.blocks.Pieces in project solution-finder by knewjade.

the class PackSearcherComparingParityBasedTest method testAllSRSValidPacksHeight5.

// 高さ5: パリティベースとの探索結果を比較する (同一ミノは2つまで)
@Test
void testAllSRSValidPacksHeight5() throws Exception {
    int width = 2;
    int height = 5;
    String resultPath = ClassLoader.getSystemResource("perfects/pack_height5.txt").getPath();
    List<TestData> testCases = Files.lines(Paths.get(resultPath)).map(line -> line.split("//")[0]).map(String::trim).filter(line -> !line.isEmpty()).map(line -> line.split("=")).map(split -> {
        Stream<Piece> blocks = BlockInterpreter.parse(split[0]);
        LongPieces pieces = new LongPieces(blocks);
        int count = Integer.valueOf(split[1]);
        return new TestData(pieces, count);
    }).collect(Collectors.toList());
    compareCount(width, height, testCases);
}
Also used : java.util(java.util) Pieces(common.datastore.blocks.Pieces) RecursiveMinoFields(searcher.pack.mino_fields.RecursiveMinoFields) BasicSolutionsCalculator(searcher.pack.solutions.BasicSolutionsCalculator) LongPieces(common.datastore.blocks.LongPieces) ColumnField(core.column_field.ColumnField) PieceCounter(common.datastore.PieceCounter) SizedBit(searcher.pack.SizedBit) MinoFactory(core.mino.MinoFactory) SeparableMinos(searcher.pack.SeparableMinos) CombinationIterable(common.iterable.CombinationIterable) FieldFactory(core.field.FieldFactory) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) MinoShifter(core.mino.MinoShifter) MappedBasicSolutions(searcher.pack.solutions.MappedBasicSolutions) Piece(core.mino.Piece) Files(java.nio.file.Files) InOutPairField(searcher.pack.InOutPairField) BlockInterpreter(common.parser.BlockInterpreter) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UsingBlockAndValidKeySolutionFilter(searcher.pack.memento.UsingBlockAndValidKeySolutionFilter) ExecutionException(java.util.concurrent.ExecutionException) SolutionFilter(searcher.pack.memento.SolutionFilter) Field(core.field.Field) BasicSolutions(searcher.pack.calculator.BasicSolutions) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) LongPieces(common.datastore.blocks.LongPieces) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test)

Example 7 with Pieces

use of common.datastore.blocks.Pieces in project solution-finder by knewjade.

the class CheckerNoHoldInvokerTest 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();
    CheckerNoHold<Action> checker = new CheckerNoHold<>(minoFactory, validator);
    for (int count = 0; count < 40; 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());
        ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
        AnalyzeTree tree = runTestCase(invoker, field, searchingPieces, maxClearLine, maxDepth);
        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) PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) MinoRotation(core.srs.MinoRotation) LockedCandidate(core.action.candidate.LockedCandidate) Field(core.field.Field) Randoms(lib.Randoms) CheckerNoHold(searcher.checker.CheckerNoHold) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) PerfectValidator(searcher.common.validator.PerfectValidator) Pieces(common.datastore.blocks.Pieces) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 8 with Pieces

use of common.datastore.blocks.Pieces in project solution-finder by knewjade.

the class CheckerUsingHoldInvokerTest method runTestCase.

private AnalyzeTree runTestCase(ConcurrentCheckerInvoker invoker, String marks, PatternGenerator blocksGenerator, int maxClearLine, int maxDepth) throws FinderExecuteException {
    List<Pieces> searchingPieces = blocksGenerator.blocksStream().collect(Collectors.toList());
    Field field = FieldFactory.createField(marks);
    List<Pair<Pieces, Boolean>> resultPairs = invoker.search(field, searchingPieces, maxClearLine, maxDepth);
    // 結果を集計する
    AnalyzeTree tree = new AnalyzeTree();
    for (Pair<Pieces, Boolean> resultPair : resultPairs) {
        Pieces pieces = resultPair.getKey();
        Boolean result = resultPair.getValue();
        tree.set(result, pieces);
    }
    System.out.println(tree.show());
    return tree;
}
Also used : Field(core.field.Field) Pieces(common.datastore.blocks.Pieces) Pair(common.datastore.Pair) AnalyzeTree(common.tree.AnalyzeTree)

Example 9 with Pieces

use of common.datastore.blocks.Pieces 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 10 with Pieces

use of common.datastore.blocks.Pieces in project solution-finder by knewjade.

the class ConcurrentCheckerNoHoldInvoker method search.

@Override
public List<Pair<Pieces, Boolean>> search(Field field, List<Pieces> searchingPieces, int maxClearLine, int maxDepth) throws FinderExecuteException {
    ConcurrentVisitedTree visitedTree = new ConcurrentVisitedTree();
    Obj obj = new Obj(field, maxClearLine, maxDepth, visitedTree);
    ArrayList<Task> tasks = new ArrayList<>();
    for (Pieces target : searchingPieces) tasks.add(new Task(obj, commonObj, target));
    try {
        return execute(tasks);
    } catch (InterruptedException | ExecutionException e) {
        throw new FinderExecuteException(e);
    }
}
Also used : CheckerCommonObj(concurrent.checker.invoker.CheckerCommonObj) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) FinderExecuteException(exceptions.FinderExecuteException) ConcurrentVisitedTree(common.tree.ConcurrentVisitedTree) Pieces(common.datastore.blocks.Pieces)

Aggregations

Pieces (common.datastore.blocks.Pieces)25 Field (core.field.Field)16 LongPieces (common.datastore.blocks.LongPieces)13 MinoFactory (core.mino.MinoFactory)12 Piece (core.mino.Piece)12 PatternGenerator (common.pattern.PatternGenerator)10 MinoShifter (core.mino.MinoShifter)10 ExecutionException (java.util.concurrent.ExecutionException)9 Test (org.junit.jupiter.api.Test)9 ColumnField (core.column_field.ColumnField)8 Collectors (java.util.stream.Collectors)8 LongTest (module.LongTest)8 PieceCounter (common.datastore.PieceCounter)7 BlockInterpreter (common.parser.BlockInterpreter)7 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)7 FieldFactory (core.field.FieldFactory)7 Files (java.nio.file.Files)7 Paths (java.nio.file.Paths)7 Stream (java.util.stream.Stream)7 SizedBit (searcher.pack.SizedBit)7