Search in sources :

Example 46 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class OnDemandBasicSolutionsTest method createSeparableMinos.

private static SeparableMinos createSeparableMinos(SizedBit sizedBit) {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    return SeparableMinos.createSeparableMinos(minoFactory, minoShifter, sizedBit);
}
Also used : MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter)

Example 47 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class LimitIterationCandidateTest method testSearch3When3Iteration.

@Test
void testSearch3When3Iteration() throws Exception {
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    Candidate<Action> candidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 3);
    String marks = "" + "XXXX______" + "XX_XXXXX__" + "X___X_____" + "XX_X______";
    Field field = FieldFactory.createField(marks);
    Set<Action> actions = candidate.search(field, Piece.T, 4);
    assertThat(actions).hasSize(9).contains(MinimalAction.create(8, 0, Rotate.Spawn)).contains(MinimalAction.create(7, 0, Rotate.Spawn)).contains(MinimalAction.create(8, 1, Rotate.Reverse)).contains(MinimalAction.create(7, 1, Rotate.Reverse)).contains(MinimalAction.create(6, 1, Rotate.Reverse)).contains(MinimalAction.create(8, 3, Rotate.Reverse)).contains(MinimalAction.create(9, 1, Rotate.Left)).contains(MinimalAction.create(8, 1, Rotate.Left)).contains(MinimalAction.create(8, 1, Rotate.Right));
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 48 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class LimitIterationCandidateTest method testRandomLocked.

@Disabled
@Test
@LongTest
// TODO: mesure time, 移動回数をチェックしていないためテストに失敗することがある
void testRandomLocked() {
    Randoms randoms = new Randoms();
    MinoFactory minoFactory = new MinoFactory();
    MinoShifter minoShifter = new MinoShifter();
    MinoRotation minoRotation = new MinoRotation();
    LimitIterationCandidate limitIterationCandidate = new LimitIterationCandidate(minoFactory, minoShifter, minoRotation, 12);
    for (int count = 0; count < 10; count++) {
        int randomHeight = randoms.nextIntClosed(10, 12);
        int numOfMinos = randoms.nextIntClosed(4, randomHeight * 10 / 4 - 1);
        Field field = randoms.field(randomHeight, numOfMinos);
        int clearLine = field.clearLine();
        int height = randomHeight - clearLine;
        Piece piece = randoms.block();
        String description = FieldView.toString(field, height) + piece;
        Set<Action> actions1 = limitIterationCandidate.search(field, piece, height);
        LockedCandidate lockedCandidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, height);
        Set<Action> actions2 = lockedCandidate.search(field, piece, height);
        assertThat(actions2).as(description).isEqualTo(actions1);
    }
}
Also used : MinoRotation(core.srs.MinoRotation) Field(core.field.Field) Randoms(lib.Randoms) MinimalAction(common.datastore.action.MinimalAction) Action(common.datastore.action.Action) Piece(core.mino.Piece) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest) LongTest(module.LongTest) Disabled(org.junit.jupiter.api.Disabled)

Example 49 with MinoShifter

use of core.mino.MinoShifter in project solution-finder by knewjade.

the class LockedNeighborCandidateTest method createLockedNeighborCandidate.

private LockedNeighborCandidate createLockedNeighborCandidate(Injector injector, int maxClearLine) {
    MinoFactory minoFactory = injector.getInstance(MinoFactory.class);
    MinoShifter minoShifter = injector.getInstance(MinoShifter.class);
    MinoRotation minoRotation = injector.getInstance(MinoRotation.class);
    OriginalPieceFactory pieceFactory = new OriginalPieceFactory(maxClearLine + 3);
    return new LockedNeighborCandidate(minoFactory, minoShifter, minoRotation, pieceFactory);
}
Also used : MinoRotation(core.srs.MinoRotation) MinoFactory(core.mino.MinoFactory) MinoShifter(core.mino.MinoShifter) OriginalPieceFactory(core.neighbor.OriginalPieceFactory)

Example 50 with MinoShifter

use of core.mino.MinoShifter 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)

Aggregations

MinoShifter (core.mino.MinoShifter)60 MinoFactory (core.mino.MinoFactory)59 MinoRotation (core.srs.MinoRotation)39 Field (core.field.Field)36 Test (org.junit.jupiter.api.Test)35 LongTest (module.LongTest)29 Action (common.datastore.action.Action)22 ColumnField (core.column_field.ColumnField)19 Piece (core.mino.Piece)19 InOutPairField (searcher.pack.InOutPairField)18 Randoms (lib.Randoms)17 LockedReachable (core.action.reachable.LockedReachable)15 LockedCandidate (core.action.candidate.LockedCandidate)14 PermutationIterable (common.iterable.PermutationIterable)12 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 PerfectValidator (searcher.common.validator.PerfectValidator)10 SizedBit (searcher.pack.SizedBit)10 SolutionFilter (searcher.pack.memento.SolutionFilter)10