Skip to content

Commit

Permalink
Fix suboptimal paths on multiple droids pathfinding to same location.
Browse files Browse the repository at this point in the history
On finding the optimal path for a droid, pathfinding was immediately terminated, on
reaching the droid, without considering paths crossing the droid's tile. The next droid
to pathfind to the same location would re-use the pathfinding map, which has a hole
around where the previous droid was, which could lead to long detours (or not finding a
path) if the previous droid/droids was/were in a 1-tile-wide/narrow passage.
  • Loading branch information
Cyp committed Mar 17, 2012
1 parent 4d0b5d7 commit c9a618c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/astar.cpp
Expand Up @@ -338,7 +338,8 @@ static PathCoord fpathAStarExplore(PathfindContext &context, PathCoord tileF)
unsigned nearestDist = 0xFFFFFFFF;

// search for a route
while (!context.nodes.empty())
bool foundIt = false;
while (!context.nodes.empty() && !foundIt)
{
PathNode node = fpathTakeNode(context.nodes);
if (context.map[node.p.x + node.p.y*mapWidth].visited)
Expand All @@ -358,7 +359,7 @@ static PathCoord fpathAStarExplore(PathfindContext &context, PathCoord tileF)
{
// reached the target
nearestCoord = node.p;
break;
foundIt = true; // Break out of loop, but not before inserting neighbour nodes, since the neighbours may be important if the context gets reused.
}

// loop through possible moves in 8 directions to find a valid move
Expand Down

0 comments on commit c9a618c

Please sign in to comment.