home >> Comments on waypointing/pathfinding
last update: dec 2006

Pathfinding

I assume that pathfinding is formulated as a minimization problem.

A* (A-star) and monotonous g cost functions

Reminder: the Closed List is by definition the current set of previously explored graph-nodes (waypoints here) selected as being on the current shortest paths. An often overlooked point is the following: if the cost function g is never negative and once a node is in the Closed List, there is no way a better path to it can be found later.
Consequently there is no need to check the Closed List nodes for possible total cost improvement, hence no need to bother coding path recomputation, nor using CPU for it.

A* and Floyd's algorithm

Whenever possible, using Floyd's algorithm is obviously the best solution: running it is a one shot CPU cost, and pathfinding is then merely looking at two 2D matrices of Source and Destination waypoints, one for the waypoint next to Source on the optimal path, and another for path total cost. Moreover, there is no need to store the path.
But this algorithm assumes the g cost function is known and fixed, whereas A* allows to choose a g function for each special need without incurring the one shot cost of the Floyd algorithm.
The point is, in cases where the specific g cost function for A-star is known to always return a higher value than the one used for Floyd for any two directly connected waypoints, A-star will returns a solution often much quicker by using the Floyd total cost from the current waypoint to the final destination as the A* heuristic function h.
The condition is not that difficult to meet as the bot-designer can define the particular g function as he/she wants. Moreover for navigation, Floyd is computed on the waypoints graph using distance or time-to-travel; A* is then used in particular cases where a connection between 2 waypoints is not available anymore, ie g is infinite. Another case is whenever the connection is temporarily more costly, either due to some kind of friction ( eg: other bots/players in the way) or due to a malus added to distance to make a connection less "desirable"( eg: dangerous paths, random malus to vary paths ).