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

Show parent comment

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

6

u/ZeroNihilist Apr 24 '13

Oh shit oh shit I'm going to hit the ground way too fast. Wait, I know, I'll grapple even faster towards the ground and be totally okay!

3

u/[deleted] Apr 24 '13

Plane flying by? GRAPPLE POWER!

→ More replies (6)

24

u/[deleted] Apr 24 '13

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

3

u/DR6 Apr 24 '13

Minecraft carts do it too: you can get more speed if you travel on both axis.

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

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.

→ 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.

3

u/[deleted] Apr 24 '13

They're sometimes avoided on RPG games because it increases the number of opponents that can surround you by 50%

5

u/kazagistar Apr 24 '13

Dunno, Civ moved to hex. Battle for Wesnoth is one of my favorite tactics games ever, and it has hex. And look at the original fallout games, which use hex.

The main reason hexes are unpopular in RPGs is because it is hard to draw hex-art; it is so much easier to create tiling art assets for a square world.

4

u/daftmutt Apr 24 '13

Depends on if you allow attacking across diagonals in a square grid or not.

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

4

u/ryeguy Apr 24 '13

Looks like you're correct for diagonals. But other than that it has to be uniform cost per this excellent article.

→ More replies (1)

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)

2

u/wlievens Apr 24 '13

It depends on what you call pre-processing I guess. It does involve multipe passes, I would think.