Search in sources :

Example 6 with BasicModule

use of module.BasicModule in project solution-finder by knewjade.

the class NeighborsTest method nextRightRotateDestinations.

@Test
void nextRightRotateDestinations() {
    Injector injector = Guice.createInjector(new BasicModule(6));
    Neighbors neighbors = createNeighbors(injector);
    Neighbor neighbor = neighbors.get(Piece.T, Rotate.Spawn, 4, 3);
    assertThat(neighbor.getNextRightRotateDestinations()).containsExactlyInAnyOrder(neighbors.get(Piece.T, Rotate.Right, 4, 3), neighbors.get(Piece.T, Rotate.Right, 3, 3), neighbors.get(Piece.T, Rotate.Right, 3, 4), neighbors.get(Piece.T, Rotate.Right, 4, 1), neighbors.get(Piece.T, Rotate.Right, 3, 1));
}
Also used : Injector(com.google.inject.Injector) BasicModule(module.BasicModule) Test(org.junit.jupiter.api.Test)

Example 7 with BasicModule

use of module.BasicModule in project solution-finder by knewjade.

the class NeighborsTest method nextMovesSources.

@Test
void nextMovesSources() {
    Injector injector = Guice.createInjector(new BasicModule());
    Neighbors neighbors = createNeighbors(injector);
    Neighbor neighbor = neighbors.get(Piece.T, Rotate.Spawn, 4, 1);
    assertThat(neighbor.getNextMovesSources()).containsExactlyInAnyOrder(neighbors.get(Piece.T, Rotate.Spawn, 3, 1), neighbors.get(Piece.T, Rotate.Spawn, 5, 1), neighbors.get(Piece.T, Rotate.Spawn, 4, 2));
}
Also used : Injector(com.google.inject.Injector) BasicModule(module.BasicModule) Test(org.junit.jupiter.api.Test)

Example 8 with BasicModule

use of module.BasicModule 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 9 with BasicModule

use of module.BasicModule in project solution-finder by knewjade.

the class LockedNeighborCandidateTest method random.

@Test
void random() {
    Injector injector = Guice.createInjector(new BasicModule());
    int maxClearLine = 3;
    LockedCandidate candidate1 = createLockedCandidate(injector, maxClearLine);
    LockedNeighborCandidate candidate2 = createLockedNeighborCandidate(injector, maxClearLine);
    MinoShifter minoShifter = injector.getInstance(MinoShifter.class);
    Stopwatch stopwatch1 = Stopwatch.createStartedStopwatch();
    Stopwatch stopwatch2 = Stopwatch.createStartedStopwatch();
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        Field field = randoms.field(maxClearLine, 7);
        for (Piece piece : Piece.values()) {
            // LockedCandidate
            stopwatch1.start();
            Set<Action> search1 = candidate1.search(field, piece, maxClearLine);
            stopwatch1.stop();
            // LockedNeighborCandidate
            stopwatch2.start();
            Set<Neighbor> neighbors = candidate2.search(field, piece, maxClearLine);
            stopwatch2.stop();
            Set<Action> search2 = neighbors.stream().map(Neighbor::getPiece).map(this::createMinimalAction).map(action -> minoShifter.createTransformedAction(piece, action)).collect(Collectors.toSet());
            assertThat(search2).isEqualTo(search1);
        }
    }
    System.out.println(stopwatch1.toMessage(TimeUnit.NANOSECONDS));
    System.out.println(stopwatch2.toMessage(TimeUnit.NANOSECONDS));
}
Also used : MinimalAction(common.datastore.action.MinimalAction) Randoms(lib.Randoms) Stopwatch(lib.Stopwatch) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BasicModule(module.BasicModule) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Action(common.datastore.action.Action) Neighbor(core.neighbor.Neighbor) MinoFactory(core.mino.MinoFactory) FieldFactory(core.field.FieldFactory) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) MinoRotation(core.srs.MinoRotation) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) OriginalPieceFactory(core.neighbor.OriginalPieceFactory) Set(java.util.Set) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) Injector(com.google.inject.Injector) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Field(core.field.Field) Stream(java.util.stream.Stream) Guice(com.google.inject.Guice) OriginalPiece(core.neighbor.OriginalPiece) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) BasicModule(module.BasicModule) Stopwatch(lib.Stopwatch) Neighbor(core.neighbor.Neighbor) Field(core.field.Field) Randoms(lib.Randoms) Injector(com.google.inject.Injector) Piece(core.mino.Piece) OriginalPiece(core.neighbor.OriginalPiece) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with BasicModule

use of module.BasicModule in project solution-finder by knewjade.

the class LockedNeighborCandidateTest method testField.

@ParameterizedTest
@ArgumentsSource(FieldTestCase.class)
void testField(Field field, Piece piece) {
    Injector injector = Guice.createInjector(new BasicModule());
    int maxClearLine = 4;
    LockedCandidate candidate1 = createLockedCandidate(injector, maxClearLine);
    LockedNeighborCandidate candidate2 = createLockedNeighborCandidate(injector, maxClearLine);
    MinoShifter minoShifter = injector.getInstance(MinoShifter.class);
    // LockedCandidate
    Set<Action> search1 = candidate1.search(field, piece, maxClearLine);
    // LockedNeighborCandidate
    Set<Neighbor> neighbors = candidate2.search(field, piece, maxClearLine);
    Set<Action> search2 = neighbors.stream().map(Neighbor::getPiece).map(this::createMinimalAction).map(action -> minoShifter.createTransformedAction(piece, action)).collect(Collectors.toSet());
    assertThat(search2).isEqualTo(search1);
}
Also used : MinimalAction(common.datastore.action.MinimalAction) Randoms(lib.Randoms) Stopwatch(lib.Stopwatch) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BasicModule(module.BasicModule) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Action(common.datastore.action.Action) Neighbor(core.neighbor.Neighbor) MinoFactory(core.mino.MinoFactory) FieldFactory(core.field.FieldFactory) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) MinoRotation(core.srs.MinoRotation) MinoShifter(core.mino.MinoShifter) Piece(core.mino.Piece) OriginalPieceFactory(core.neighbor.OriginalPieceFactory) Set(java.util.Set) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) Injector(com.google.inject.Injector) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Field(core.field.Field) Stream(java.util.stream.Stream) Guice(com.google.inject.Guice) OriginalPiece(core.neighbor.OriginalPiece) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) Injector(com.google.inject.Injector) BasicModule(module.BasicModule) Neighbor(core.neighbor.Neighbor) MinoShifter(core.mino.MinoShifter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

Injector (com.google.inject.Injector)15 BasicModule (module.BasicModule)15 Test (org.junit.jupiter.api.Test)13 Field (core.field.Field)7 MinoFactory (core.mino.MinoFactory)4 Randoms (lib.Randoms)4 Action (common.datastore.action.Action)3 Mino (core.mino.Mino)3 MinoShifter (core.mino.MinoShifter)3 OriginalPiece (core.neighbor.OriginalPiece)3 OriginalPieceFactory (core.neighbor.OriginalPieceFactory)3 MinoRotation (core.srs.MinoRotation)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)3 Guice (com.google.inject.Guice)2 MinimalAction (common.datastore.action.MinimalAction)2 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)2 PatternGenerator (common.pattern.PatternGenerator)2 FieldFactory (core.field.FieldFactory)2 Piece (core.mino.Piece)2