Skip to content

Commit

Permalink
Skip already-visited tiles during radius calculation (approx. 5% fewe…
Browse files Browse the repository at this point in the history
…r tiles) (#34)

Co-authored-by: James Ide <[email protected]>

GitOrigin-RevId: 68a53050c15bb4700fbc0d31bac0272dc3967a02
  • Loading branch information
cpojer committed May 19, 2024
1 parent a5d4f86 commit 8089b3b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions athena/Radius.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,25 @@ function calculateRadius(

while (!queue.isEmpty()) {
const { cost: parentCost, vector } = queue.poll()!;
if (closed[map.getTileIndex(vector)]) {
const index = map.getTileIndex(vector);
if (closed[index]) {
continue;
}
closed[index] = true;

const vectors = vector.adjacent();
for (let i = 0; i < vectors.length; i++) {
const currentVector = vectors[i];
if (!map.contains(currentVector)) {
continue;
}
const index = map.getTileIndex(currentVector);
if (closed[index] || currentVector.equals(start)) {
const currentIndex = map.getTileIndex(currentVector);
if (closed[currentIndex]) {
continue;
}
const cost = getCost(map, unit, currentVector);
if (cost < 0 || !isAccessible(map, unit, currentVector)) {
closed[index] = true;
closed[currentIndex] = true;
continue;
}
const nextCost =
Expand Down

0 comments on commit 8089b3b

Please sign in to comment.