Search in sources :

Example 1 with Neighbor

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

the class LockedNeighborCandidate method check.

private boolean check(Neighbor current) {
    OriginalPiece piece = current.getPiece();
    // ハードドロップで到達できるとき
    if (field.canReachOnHarddrop(piece))
        return true;
    if (cache.isFound(current))
        return true;
    // すでに訪問済みのとき
    if (cache.isVisited(current))
        // 訪問済みだが結果が出てないときは他の探索でカバーできるためfalseを返却
        return false;
    // 訪問済みにする
    cache.visit(current);
    // 上と左右に移動
    List<Neighbor> nextMovesSources = current.getNextMovesSources();
    for (Neighbor next : nextMovesSources) {
        OriginalPiece nextPiece = next.getPiece();
        if (field.canPut(nextPiece) && check(next)) {
            cache.found(current);
            return true;
        }
    }
    // 左回転でくる可能性がある場所を移動
    if (checkLeftRotation(current))
        return true;
    // 右回転でくる可能性がある場所を移動
    if (checkRightRotation(current))
        return true;
    return false;
}
Also used : Neighbor(core.neighbor.Neighbor) OriginalPiece(core.neighbor.OriginalPiece)

Example 2 with Neighbor

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

the class LockedNeighborCandidate method search.

@Override
public Set<Neighbor> search(Field field, Piece piece, int appearY) {
    this.field = field;
    HashSet<Neighbor> results = new HashSet<>();
    cache.clear();
    Set<Rotate> uniqueRotates = minoShifter.getUniqueRotates(piece);
    for (Rotate rotate : uniqueRotates) {
        Mino mino = minoFactory.create(piece, rotate);
        for (int x = -mino.getMinX(); x < FIELD_WIDTH - mino.getMaxX(); x++) {
            for (int y = -mino.getMinY(); y < appearY - mino.getMaxY(); y++) {
                Neighbor neighbor = neighbors.get(piece, rotate, x, y);
                if (field.canPut(neighbor.getPiece()) && field.isOnGround(mino, x, y)) {
                    loop(results, neighbor);
                }
            }
        }
    }
    return results;
}
Also used : Rotate(core.srs.Rotate) Neighbor(core.neighbor.Neighbor) Mino(core.mino.Mino) HashSet(java.util.HashSet)

Example 3 with Neighbor

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

the class LockedNeighborReachable method checks.

@Override
public boolean checks(Field field, Mino mino, int x, int y, int appearY) {
    assert field.canPut(mino, x, y);
    this.field = field;
    lockedCache.clear();
    Piece piece = mino.getPiece();
    Rotate rotate = mino.getRotate();
    Neighbor neighbor = neighbors.get(piece, rotate, x, y);
    if (checkFirst(neighbor))
        return true;
    List<Action> actions = minoShifter.enumerateSameOtherActions(piece, rotate, x, y);
    for (Action action : actions) if (checkFirst(piece, action.getRotate(), action.getX(), action.getY()))
        return true;
    return false;
}
Also used : Action(common.datastore.action.Action) Rotate(core.srs.Rotate) Piece(core.mino.Piece) OriginalPiece(core.neighbor.OriginalPiece) Neighbor(core.neighbor.Neighbor)

Example 4 with Neighbor

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

the class LockedNeighborReachable method checkLeftRotation.

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

Example 5 with Neighbor

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

the class LockedNeighborReachable method check.

private boolean check(Neighbor neighbor) {
    // harddropでたどりつけるとき
    OriginalPiece originalPiece = neighbor.getPiece();
    if (field.canReachOnHarddrop(originalPiece))
        return true;
    // すでに訪問済みのとき
    int x = originalPiece.getX();
    int y = originalPiece.getY();
    Rotate rotate = originalPiece.getRotate();
    if (lockedCache.isVisit(x, y, rotate))
        // 訪問済みだがまだ探索中の場合は、他の探索でカバーできるためfalseを返却
        return false;
    lockedCache.visit(x, y, rotate);
    // 上左右に移動
    List<Neighbor> moves = neighbor.getNextMovesSources();
    for (Neighbor move : moves) if (field.canPut(move.getPiece()) && check(move))
        return true;
    // 左回転でくる可能性がある場所を移動
    if (checkLeftRotation(neighbor))
        return true;
    // 右回転でくる可能性がある場所を移動
    if (checkRightRotation(neighbor))
        return true;
    return false;
}
Also used : Rotate(core.srs.Rotate) Neighbor(core.neighbor.Neighbor) OriginalPiece(core.neighbor.OriginalPiece)

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