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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations