I have been learning about the A* path finding algorithm and I can't understand the heuristic cost in this algorithm. What is it and what is its use in the algorithm?
Asked
Active
Viewed 140 times
0
-
3Does this answer your question? How does A* pathfinding work? – Aug 20 '20 at 06:14
1 Answers
1
It is merely a “wild guess about the distance left to goal.”
A guess that does not take into account any obstacles in the world.
So you use the shortest line between points.
It is the brown distance in the example below, used by the algorithm to compute the actual path in cyan.
It is best to underestimate the true distance, otherwise a path may be generated that is not the shortest.

Bram
- 3,729
- 18
- 23
-
Not quite a "wild" guess, as it does have some constraints. To work correctly (to be "admissible"), it has to be an optimistic guess, one that's guaranteed to not exceed the true distance/cost. – DMGregory Aug 20 '20 at 16:08
-
At the same time, higher resolution of data is better. -1,0,1 for further/same/closer is technically a valid heuristic, but it won't save much time over Dijkstra. – Weckar E. Aug 20 '20 at 17:24