Search in sources :

Example 6 with Neighbor

use of core.neighbor.Neighbor in project solution-finder by knewjade.

the class LockedNeighborCandidate method loop.

private void loop(HashSet<Neighbor> results, Neighbor neighbor) {
    cache.resetTrail();
    if (check(neighbor)) {
        results.add(neighbor);
    } else {
        OriginalPiece piece = neighbor.getPiece();
        Mino mino = piece.getMino();
        Piece block = mino.getPiece();
        List<Action> actions = minoShifter.enumerateSameOtherActions(block, mino.getRotate(), piece.getX(), piece.getY());
        for (Action action : actions) {
            Neighbor similar = neighbors.get(block, action.getRotate(), action.getX(), action.getY());
            if (check(similar))
                results.add(similar);
        }
    }
}
Also used : Action(common.datastore.action.Action) Piece(core.mino.Piece) OriginalPiece(core.neighbor.OriginalPiece) Neighbor(core.neighbor.Neighbor) Mino(core.mino.Mino) OriginalPiece(core.neighbor.OriginalPiece)

Example 7 with Neighbor

use of core.neighbor.Neighbor in project solution-finder by knewjade.

the class LockedNeighborCandidate method checkLeftRotation.

private boolean checkLeftRotation(Neighbor current) {
    List<Neighbor> nextLeftRotateSources = current.getNextLeftRotateSources();
    for (Neighbor source : nextLeftRotateSources) {
        if (!field.canPut(source.getPiece()))
            continue;
        // もう一度回して戻ってくるか
        List<Neighbor> destinations = source.getNextLeftRotateDestinations();
        Neighbor destination = getDestination(destinations);
        if (current.equals(destination) && check(source)) {
            cache.found(current);
            return true;
        }
    }
    return false;
}
Also used : Neighbor(core.neighbor.Neighbor)

Example 8 with Neighbor

use of core.neighbor.Neighbor in project solution-finder by knewjade.

the class LockedNeighborCandidate method checkRightRotation.

private boolean checkRightRotation(Neighbor current) {
    List<Neighbor> nextRightRotateSources = current.getNextRightRotateSources();
    for (Neighbor source : nextRightRotateSources) {
        if (!field.canPut(source.getPiece()))
            continue;
        // もう一度回して戻ってくるか
        List<Neighbor> destinations = source.getNextRightRotateDestinations();
        Neighbor destination = getDestination(destinations);
        if (current.equals(destination) && check(source)) {
            cache.found(current);
            return true;
        }
    }
    return false;
}
Also used : Neighbor(core.neighbor.Neighbor)

Example 9 with Neighbor

use of core.neighbor.Neighbor in project solution-finder by knewjade.

the class LockedNeighborReachable method checkRightRotation.

private boolean checkRightRotation(Neighbor current) {
    List<Neighbor> sources = current.getNextRightRotateSources();
    for (Neighbor source : sources) {
        if (!field.canPut(source.getPiece()))
            continue;
        // もう一度回して戻ってくるか
        List<Neighbor> destinations = source.getNextRightRotateDestinations();
        Neighbor destination = getDestination(destinations);
        if (current.equals(destination) && check(source)) {
            return true;
        }
    }
    return false;
}
Also used : Neighbor(core.neighbor.Neighbor)

Example 10 with Neighbor

use of core.neighbor.Neighbor 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

Neighbor (core.neighbor.Neighbor)11 OriginalPiece (core.neighbor.OriginalPiece)6 Action (common.datastore.action.Action)4 Piece (core.mino.Piece)4 Rotate (core.srs.Rotate)3 Guice (com.google.inject.Guice)2 Injector (com.google.inject.Injector)2 MinimalAction (common.datastore.action.MinimalAction)2 Field (core.field.Field)2 FieldFactory (core.field.FieldFactory)2 Mino (core.mino.Mino)2 MinoFactory (core.mino.MinoFactory)2 MinoShifter (core.mino.MinoShifter)2 OriginalPieceFactory (core.neighbor.OriginalPieceFactory)2 MinoRotation (core.srs.MinoRotation)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Randoms (lib.Randoms)2