Search in sources :

Example 11 with BasicModule

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

the class LockedNeighborReachableTest method randoms.

@Test
void randoms() {
    int maxClearLine = 4;
    Injector injector = Guice.createInjector(new BasicModule(maxClearLine));
    LockedReachable reachable1 = createLockedReachable(injector, maxClearLine);
    LockedNeighborReachable reachable2 = createLockedNeighborReachable(injector, maxClearLine);
    OriginalPieceFactory pieceFactory = injector.getInstance(OriginalPieceFactory.class);
    Set<OriginalPiece> pieces = pieceFactory.create();
    Randoms randoms = new Randoms();
    for (int count = 0; count < 10000; count++) {
        Field field = randoms.field(4, 5);
        for (OriginalPiece piece : pieces) {
            // フィールドにそもそも置けないときは前提条件が合わないためスキップ
            if (!field.canPut(piece))
                continue;
            Mino mino = piece.getMino();
            int x = piece.getX();
            int y = piece.getY();
            boolean checks1 = reachable1.checks(field, mino, x, y, maxClearLine);
            boolean checks2 = reachable2.checks(field, mino, x, y, maxClearLine);
            assertThat(checks2).as(piece.toString()).isEqualTo(checks1);
        }
    }
}
Also used : Field(core.field.Field) Randoms(lib.Randoms) Injector(com.google.inject.Injector) BasicModule(module.BasicModule) Mino(core.mino.Mino) OriginalPiece(core.neighbor.OriginalPiece) OriginalPieceFactory(core.neighbor.OriginalPieceFactory) Test(org.junit.jupiter.api.Test)

Example 12 with BasicModule

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

the class LockedNeighborReachableTest method checks2.

@Test
void checks2() {
    int maxClearLine = 4;
    Injector injector = Guice.createInjector(new BasicModule(maxClearLine));
    LockedNeighborReachable reachable = createLockedNeighborReachable(injector, maxClearLine);
    Field field = FieldFactory.createField("" + "X______XXX" + "XXXXXX___X" + "XXX_____XX" + "XXX______X");
    boolean checks = reachable.checks(field, new Mino(Piece.J, Rotate.Spawn), 4, 0, maxClearLine);
    assertThat(checks).isFalse();
}
Also used : Field(core.field.Field) Injector(com.google.inject.Injector) BasicModule(module.BasicModule) Mino(core.mino.Mino) Test(org.junit.jupiter.api.Test)

Example 13 with BasicModule

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

the class NeighborsTest method nextLeftRotateDestinations.

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

Example 14 with BasicModule

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

the class NeighborsTest method nextRightRotateSources.

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

Example 15 with BasicModule

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

the class PercentCoreTest method assertPercentCore.

private void assertPercentCore(Obj obj, double successPercent) throws Exception {
    PatternGenerator generator = new LoadedPatternGenerator(obj.patterns);
    NormalEnumeratePieces enumeratePieces = new NormalEnumeratePieces(generator, obj.maxDepth, obj.isUsingHold);
    Set<LongPieces> blocks = enumeratePieces.enumerate();
    Injector injector = Guice.createInjector(new BasicModule(obj.maxClearLine));
    Optional<ExecutorService> executorService = obj.isSingleThread ? Optional.empty() : Optional.of(injector.getInstance(ExecutorService.class));
    LockedCandidateThreadLocal candidateThreadLocal = injector.getInstance(LockedCandidateThreadLocal.class);
    LockedReachableThreadLocal reachableThreadLocal = injector.getInstance(LockedReachableThreadLocal.class);
    MinoFactory minoFactory = injector.getInstance(MinoFactory.class);
    PercentCore percentCore = getPercentCore(obj, executorService.orElse(null), candidateThreadLocal, reachableThreadLocal, minoFactory);
    Field field = FieldFactory.createField(obj.marks);
    percentCore.run(field, blocks, obj.maxClearLine, obj.maxDepth);
    executorService.ifPresent(ExecutorService::shutdown);
    assertThat(percentCore.getResultTree().getSuccessPercent()).isEqualTo(successPercent);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) BasicModule(module.BasicModule) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LockedReachableThreadLocal(concurrent.LockedReachableThreadLocal) Field(core.field.Field) LongPieces(common.datastore.blocks.LongPieces) Injector(com.google.inject.Injector) LockedCandidateThreadLocal(concurrent.LockedCandidateThreadLocal) NormalEnumeratePieces(entry.searching_pieces.NormalEnumeratePieces) ExecutorService(java.util.concurrent.ExecutorService) MinoFactory(core.mino.MinoFactory)

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