hexagonal_pathfinding_astar icon indicating copy to clipboard operation
hexagonal_pathfinding_astar copied to clipboard

Edge case: no path can be found

Open BlondeBurrito opened this issue 4 years ago • 0 comments

In the event that two distinct hexagon grids are merged into the same data set (think of two islands separated by an ocean where the ocean isn't made of traversable hexagons) and the start point is in one set and the end point is in the other set then no path will be found as there are no neighbours bridging the two sets. It will either panic or get stuck in an infinite loop.

This can be resolved by amending the end of the A-Star calculation to check the size of the queue of nodes to be processed. If queue.len() == 0 then it means all nodes have been exhausted and there is no path.

Rather than returning a Vec to the user an Option should instead be returned. Where None indicates that no path could be found and Some will contain a Vec of the best path.

BlondeBurrito avatar Apr 10 '22 20:04 BlondeBurrito