Skip to content
This repository has been archived by the owner on Oct 1, 2022. It is now read-only.

Commit

Permalink
Fixed bug in BucketQueueAStar when starting from a blocked partition.…
Browse files Browse the repository at this point in the history
… Only blocked positions, but not the sea should be accessible be such movables. Otherwise fleeing movables will try to walk through the sea.
  • Loading branch information
andreas-eberle committed Jan 6, 2016
1 parent b5b0dfe commit a6da068
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public final Path findPath(IPathCalculatable requester, ShortPoint2D target) {

@Override
public final Path findPath(IPathCalculatable requester, final short sx, final short sy, final short tx, final short ty) {
final boolean blockedAtStart;
final short blockedAtStartPartition;
if (!isInBounds(sx, sy)) {
throw new InvalidStartPositionException("Start position is out of bounds!", sx, sy);
} else if (!isInBounds(tx, ty) || isBlocked(requester, tx, ty) || map.getBlockedPartition(sx, sy) != map.getBlockedPartition(tx, ty)) {
return null; // target can not be reached
} else if (sx == tx && sy == ty) {
return null;
} else if (isBlocked(requester, sx, sy)) {
blockedAtStart = true;
blockedAtStartPartition = map.getBlockedPartition(sx, sy);
} else {
blockedAtStart = false;
blockedAtStartPartition = -1;
}

final int targetFlatIdx = getFlatIdx(tx, ty);
Expand Down Expand Up @@ -111,7 +111,7 @@ public final Path findPath(IPathCalculatable requester, final short sx, final sh
final int neighborX = x + xDeltaArray[i];
final int neighborY = y + yDeltaArray[i];

if (isValidPosition(requester, neighborX, neighborY, blockedAtStart)) {
if (isValidPosition(requester, neighborX, neighborY, blockedAtStartPartition)) {
final int flatNeighborIdx = getFlatIdx(neighborX, neighborY);

if (!closedBitSet.get(flatNeighborIdx)) {
Expand Down Expand Up @@ -185,8 +185,9 @@ private final void initStartNode(int sx, int sy, int tx, int ty) {
openBitSet.set(flatIdx);
}

private final boolean isValidPosition(IPathCalculatable requester, int x, int y, boolean blockedAtStart) {
return isInBounds(x, y) && (!isBlocked(requester, x, y) || blockedAtStart);
private final boolean isValidPosition(IPathCalculatable requester, int x, int y, short blockedAtStartPartition) {
return isInBounds(x, y)
&& (blockedAtStartPartition >= 0 && map.getBlockedPartition(x, y) == blockedAtStartPartition || !isBlocked(requester, x, y));
}

private final boolean isInBounds(int x, int y) {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit a6da068

Please sign in to comment.