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

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.

0

u/[deleted] Apr 24 '13

[deleted] — view deleted comment

2

u/porkchop_d_clown Apr 24 '13

You're right - I typo'ed.

4

u/ixache Apr 24 '13

No you're wrong now and you were (accidentally) right the first time around

41% is the speed advantage taking the diagonal of a square instead of the side, per unit of time. Because the diagonal is 41% longer than the side: (1.41-1)/1*100.

2

u/totemcatcher Apr 24 '13

This has always irked me. The cause/implementation of the advantage is different from grid based movement. Basic trig solves it in an FPS, but for a grid game only by wildly decreasing the grid square size can it approach being solved. ;)

→ More replies (2)

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)