r/programming • • Apr 23 '13

PathFinding algorithm, visually explained

http://qiao.github.io/PathFinding.js/visual/
2.2k Upvotes

230 comments sorted by

View all comments

269

u/smallstepforman Apr 23 '13

I've never heard of Jump Point Search before, and I'm amazed with its performance. I've done A* for a Civ like game using hexes (it only takes 4 hours to implement from scratch), but now that I've seen Jump Point Search, it's time to rework the path finding algorithm.

26

u/schmon Apr 24 '13

Someone please implement this in Dwarf Fortress!

13

u/Mazo Apr 24 '13

FPS Death from the pathfinding in DF makes me sad.

→ More replies (18)

24

u/[deleted] Apr 24 '13

[removed] — view removed comment

9

u/[deleted] Apr 24 '13

I believe that the algorithm is explained in this paper. The latest reference I could find in the paper comes from 2009, so it appears as though the algorithm is a relatively new algorithm. Its astoundingly fast!

4

u/alphabytes Apr 25 '13

my eyeballs popped out watching this crazy fast algo ... seriously... WTF...

→ More replies (2)

49

u/TinynDP Apr 23 '13

Jump Point requires some pre-processing, to find all the clear square (I guess it expands to hex shaped regions) regions which are otherwise identical. If those squares are not constant, such that you have to re-create them every run though, it might not actually be a winner.

61

u/shoffing Apr 23 '13

But in this blog post, one of the properties listed is "It involves no pre-processing"...

66

u/Rainfly_X Apr 23 '13

Basically, as I understand it, it depends on the nature of the map data you're feeding it, as it only understands binary (obstacle vs clear) gridlike patterns (presumably including hex maps, for anyone smart enough to work it out). The pre-processing penalty is for maps that need to be "simplified" into grids first.

But obviously, this also applies to just about any other pathfinding algorithm you'd be using anyways, and it's unfair to single out jump point for something so standard.

39

u/kazagistar Apr 23 '13

Hex is a grid where you cannot move along one of the diagonals. It really isn't that "smart" to figure out.

57

u/Zarokima Apr 23 '13

Sometimes people like me need people like you to point out stuff like that, though. I never would have thought of hex tiles in that way.

33

u/porkchop_d_clown Apr 24 '13

If you've ever seen an old fashioned Avalon-Hill style board game, look at the hex grid: the whole point is that there are no diagonals - this is done to eliminate the distance advantage a player can get by moving diagonally on a traditional grid map.

12

u/BraveSirRobin Apr 24 '13

I've noticed that diagonal advantage in a few FPS PC games, Just Cause 2 for example.

0

u/[deleted] Apr 24 '13

[deleted] — view deleted comment

56

u/[deleted] Apr 24 '13 edited Apr 24 '13

[removed] — view removed comment

→ More replies

24

u/[deleted] Apr 24 '13

It's not uncommon - EA Sports does it in their football simulators, which is downright absurd.

→ More replies (5)

8

u/porkchop_d_clown Apr 24 '13 edited Apr 24 '13

If you're clever, you can really get an edge with it - effectively, it's a 41% (edit) speed boost for any unit that can stay on the diagonals.

0

u/[deleted] Apr 24 '13

[deleted] — view deleted comment

→ More replies
→ More replies (3)

4

u/Romenhurst Apr 24 '13

I think kazagistar was referring to the way hex tiles are represented in the code. The result of shifting every other row by half a tile width and only allowing diagonal movement in either NW/SE or NE/SW will effectively create a hex grid.

→ More replies (3)

7

u/kazagistar Apr 24 '13

Sorry, I didn't mean to sound like an ass... I had it pointed out to me a while back too.

11

u/ryeguy Apr 24 '13

To put this into A* terms, it only works for fixed-cost maps. That means the cost is only allowed to be a function of manhattan distance, nothing more.

3

u/[deleted] Apr 24 '13 edited Apr 24 '13

[removed] — view removed comment

→ More replies (2)

4

u/TinynDP Apr 24 '13

Huh. I assumed it pre-processed the map, created a list of equivilant squares, and treated anything that steps into any point in the squares as stepping into all points of the square equally.

It looks like its more about having two different recursive paths. One for the obvious steps, and one for the non-obvious steps. The visualization only treats the non-obvious steps as worth drawing, even though the code had to at very least gloss over the obvious steps along the way.

→ More replies (1)
→ More replies (1)
→ More replies (3)