
Pathfinding Demystified - iKlsR
http://gabrielgambetta.com/path1.html
======
muhuk
Very cool series of articles.

My take-away, from the last part:

    
    
        The state represented by each search node doesn’t have to be limited to a position; 
        on the contrary, it can include an arbitrarly complex set of values. For example, 
        if turning 90 degrees takes the same time as walking from one square to the next, 
        the state of your character can be [position, heading]. Each node now represents 
        not only the position of the character, but also its heading; and the new edges 
        of the graph (implicit or explicit) reflect that.
    
        Going back to the original 5x5 grid, the starting position of the search now may 
        be [A, East]. The adjacent nodes are now [B, East] and [A, South] - if you want 
        to reach F, you need to correct your heading first, so the path would be 
        [A, East], [A, South], [F, South].
    
        First-person shooter? At least four dimensions: [X, Y, Z, Heading]. Maybe even
        [X, Y, Z, Heading, Health, Ammo].

~~~
ggambetta
It's even more than that. You can get great results from A* on any graph
search problem where you can find a good heuristic for the distance to the
goal from some node, which may not be related to position at all. For example,
I once did this with nodes that represented sets of database attributes and
arcs that represented table joins.

~~~
Vaskivo
A* is not only a pathfinding algorithm, but a search algorithm. In my AI
classes I used it for pathfinding, solving sudokus and other puzzles, and even
to solve a job shop scheduling problem[1]. If you can translate your problem
into a graph, you can use A* with it.

In these classes, we had a problem to solve, and we had to solve it using
different algorithms and in the end submit a report in wich we compared the
result and efficiency of each. The ones that used heuristics, we had to
implement about three different heuristics, analyze each and mix them up.

[1]
[https://en.wikipedia.org/wiki/Job_shop_scheduling](https://en.wikipedia.org/wiki/Job_shop_scheduling)

------
royjacobs
Cool article! If you're interested in how to do pathfinding in 3d, there's a
very interesting library called Recast that does this [0]. The author also has
a blog where he wrote about his progress, but that seems to have gone quiet.
[1]

[0]
[https://github.com/memononen/recastnavigation](https://github.com/memononen/recastnavigation)
[1] [http://digestingduck.blogspot.com/](http://digestingduck.blogspot.com/)

------
Kiro
Maybe I misunderstand how this works but I want to find a pathfinding
algorithm that is super fast and only calculates the first few steps toward a
target. The target is moving and the calculation needs to happen several times
every second so calculating the whole path is not feasible. It doesn't really
matter if it gets stuck or doesn't find the optimal path, just that it looks
like it's trying to move closer to the target.

Any ideas?

~~~
ggambetta
If "trying to move closer" is enough, maybe you don't even need a pathfinding
algorithm - if the target is to the right move one step to the right, if the
target is above move one step up, and so on?

~~~
datashaman
What if there are obstacles in the path? You'll need a more complex algorithm
to deal with the possibility of getting stuck in corners.

~~~
ggambetta
Well, he did say _" It doesn't really matter if it gets stuck"_.

~~~
datashaman
_puts glasses on_ ah. :-$

------
ichinaski
> # If we just got to the goal node, build and return the path.
    
    
      if adjacent == goal_node: 
        return build_path(goal_node)
    

If you want to ensure the path is optimal, you'll have to wait until you
'expand' the goal node, as there might exist goal states in the open set with
lower costs.

~~~
ggambetta
Fixed. It's a copy-paste artifact from Part I, where the algorithm is looking
for _a_ path, not the _optimal_ path, so it didn't matter. Thanks!

------
pjmlp
Great article!

Just in time, as I am tracking down some A* implementation issues on an old
codebase I am trying to revive.

------
conjectures
These articles are very well structured. Excellent delivery.

~~~
ggambetta
Thank you!

------
jokoon
found this a while ago

[http://code.activestate.com/recipes/577457-a-star-
shortest-p...](http://code.activestate.com/recipes/577457-a-star-shortest-
path-algorithm/)

For those who prefer to read code...

