A* is a computer algorithm that is widely used in path finding and graph traversal, the process of
plotting an efficiently traversable path between points, called nodes.One important element in
computer games is finding the shortest path between two points. The easiest implementation is to
just have the character walk in a straight line. This will work as long as there are no obstacles or
distractions along the way. If there is a chasm or a large rock in the way, then the character needs
to figure out a way to move around and still reach the goal.
Below is the classic representation of the A* algorithm.
f'(n) = g(n) + h'(n)
g(n) is the total distance it has taken to get from the starting position to the current location.
h'(n) is the estimated distance from the current position to the goal destination/state. A heuristic
function is used to create this estimate on how far away it will take to reach the goal state.
f'(n) is the sum of g(n) and h'(n). This is the current estimated shortest path. f(n) is the true
shortest path which is not discovered until the A* algorithm is finished.
Here is another way to think about things. Consider a family vacation where the Dad, the Mom,
the two kids and the family goat are all crammed into a car. After about 5 minutes, the kids start
the fidget and start asking annoying questions. One of the questions (or a varient, thereof) is
"How much farther 'til we get there?" To sate the children's curiosity for a few minutes, the Dad
will make a rough guess. "Another 300 miles. It will be awhile, so why don't you take a nap?" If
the family had already driven 100 miles at that point, that would represent g(n), the total distance
traveled so far. The estimate of 300 miles would be h'(n), the guess on how much farther it
would be. So the f'(n) would be 100 + 300 = 400 miles.
One of the more difficult parts in solving A* is creating a good heuristic function to determine
h'(n). A heuristic function differs from an algorithm in that a heuristic is more of an estimate and
is not necessarily provably correct. An algorithm is a set of steps which can be proven to halt on
a particular given set of input.
The heuristic function in A* is arbitrary, however the better your heuristic is, the faster and more
accurate your solution will become. However, therein lies the problem -- deciding a good
heuristic.