• Create Account

## What heuristic should i use for A* ?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1andreilng  Members

100
Like
0Likes
Like

Posted 30 October 2011 - 01:49 AM

Im working on some basic pathfinding in 3D space. Im able to create a navigation graph, using a flood-fill algorithm. I start in one point, and extend it in 4 directions, if there are no colliders in that particular direction. Its pretty nice until now. Works ok. Creates a nice grid, without the inaccessible nodes or edges. But theres one more thing i have to do in order to make enemies / NPCs come to the player or go to a certain place.

Use A* to find the shortest path from a node closest to the enemy to a node closest to the target.

I studied A* 1-2 years ago in college, gotta read a bit more about it though, to refresh my memory. But still, which heuristic is the most suitable here?
Is it ok if i use the straight distance between 2 points? And the cost being the number of graph edges traveled until the current position? (since each edge has the same length.)

And is there anything else i should need to know about this? Im gonna look into it today, but a direction, for a head start, would be really, really nice.

3523
Like
4Likes
Like

Posted 30 October 2011 - 06:19 AM

Yeah... in a grid world, you are pretty well off just using the straight line distance. Also, if you can't move diagonally, you can use the Manhattan distance which is simply delta x + delta y. As long as your heuristic is no greater than the absolute minimum number of moves, you're good.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC

Professional consultant on game AI, mathematical modeling, simulation modeling
Co-advisor of the GDC AI Summit
Co-founder of the AI Game Programmers Guild
Author of the book, Behavioral Mathematics for Game AI

Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

### #3jameszhao00  Members

271
Like
0Likes
Like

Posted 30 October 2011 - 07:27 AM

If I have two admissible heuristics (less than the true cost), does using the more detailed heuristic (absolute distance) provide any benefit over the coarser heuristic (manhattan distance)? The more detailed heuristic returns different results when the coarser heuristic returns the same results.

### #4Jarod42  Members

100
Like
0Likes
Like

Posted 31 October 2011 - 08:05 AM

If I have two admissible heuristics (less than the true cost), does using the more detailed heuristic (absolute distance) provide any benefit over the coarser heuristic (manhattan distance)? The more detailed heuristic returns different results when the coarser heuristic returns the same results.

In a grid world without diagonal move, Manhattan distance is more accurate than Euclidean distance.
The better is your heuristic, the less node you may expect to visit.

An other thing with heuristic is how it breaks tie which can favour some (equivalent) path from other.
Euclidean Distance will favour path along the straight line.

### #5pithlit  Members

179
Like
0Likes
Like

Posted 31 October 2011 - 05:06 PM

The better is your heuristic, the less node you may expect to visit.

Correct. For grids, Manhattan distance is OK if diagonal moves are not allowed. Otherwise, I'd use Octile Distance.

An other thing with heuristic is how it breaks tie which can favour some (equivalent) path from other.
Euclidean Distance will favour path along the straight line.

I don't see how. Unless you program A* to break ties in favour of the path with the fewest turns? At any rate, this isn't a good approach. Normally ties should be broken in favour of the node with the larger g value. Otherwise A* can expand an awful lot of extra states. See Figure 1 in this article for an example.

### #6Trienco  Members

2555
Like
2Likes
Like

Posted 31 October 2011 - 11:36 PM

If I have two admissible heuristics (less than the true cost), does using the more detailed heuristic (absolute distance) provide any benefit over the coarser heuristic (manhattan distance)? The more detailed heuristic returns different results when the coarser heuristic returns the same results.

The key is to use the best heuristic that doesn't overestimate the actual cost. If your heuristic tends to drastically underestimate you can end up expanding tons of useless nodes, so the closer your heuristic to the actual cost, the faster A* might find your solution.

You can also overestimate on purpose to get a result faster, but once your heuristic overestimates, you might not get the shortest path. That's not always a real problem, because personally, I had 3 options to walk to work every day and no, I never bothered to find out which one might be a few steps longer. So in some cases overestimating a little can even be a good thing.
f@dzhttp://festini.device-zero.de

3523
Like
2Likes
Like

Posted 01 November 2011 - 07:08 AM

You can also overestimate on purpose to get a result faster, but once your heuristic overestimates, you might not get the shortest path. That's not always a real problem, because personally, I had 3 options to walk to work every day and no, I never bothered to find out which one might be a few steps longer. So in some cases overestimating a little can even be a good thing.

This is actually a useful point. People rarely bother with climbing that asymptotic curve to perfection. Eventually we get to "good enough". If you overestimate a little and speed up your search, not too many people are going to notice a slightly sub-optimal result.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC

Professional consultant on game AI, mathematical modeling, simulation modeling
Co-advisor of the GDC AI Summit
Co-founder of the AI Game Programmers Guild
Author of the book, Behavioral Mathematics for Game AI

Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

### #8 Graelig   Banned

-801
Like
0Likes
Like

Posted 03 November 2011 - 09:27 PM

When I did the overestimating it made things much faster, but while most paths were fine when I had irregular geometry it could do strange things like hug a wall that was curving AROUND the goal.

For heuristing I was wondering if there's something that takes directionality into account more as I still don't always get the most obvious path for straight line.

This is my thread. There are many threads like it, but this one is mine.

3523
Like
0Likes
Like

Posted 03 November 2011 - 09:33 PM

When I did the overestimating it made things much faster, but while most paths were fine when I had irregular geometry it could do strange things like hug a wall that was curving AROUND the goal.

For heuristing I was wondering if there's something that takes directionality into account more as I still don't always get the most obvious path for straight line.

Directionality is taken into account when you compare the other values of the potential squares you want to search next. If you move away from the goal, your cost goes up. If you move toward, the cost goes down. All the heuristic represents is a starting point from which to compare the total distances of your future selections. And for distance, no direction is needed.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC

Professional consultant on game AI, mathematical modeling, simulation modeling
Co-advisor of the GDC AI Summit
Co-founder of the AI Game Programmers Guild
Author of the book, Behavioral Mathematics for Game AI

Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

### #10Storyyeller  Members

215
Like
0Likes
Like

Posted 04 November 2011 - 08:48 PM

Thanks for the link. Jump point pruning looks like an interesting technique, though I think the article overstates the benefits slightly. I'll have to try it out if I ever need to use A*.
I trust exceptions about as far as I can throw them.

### #11 Graelig   Banned

-801
Like
0Likes
Like

Posted 04 November 2011 - 11:49 PM

When I did the overestimating it made things much faster, but while most paths were fine when I had irregular geometry it could do strange things like hug a wall that was curving AROUND the goal.

For heuristing I was wondering if there's something that takes directionality into account more as I still don't always get the most obvious path for straight line.

Directionality is taken into account when you compare the other values of the potential squares you want to search next. If you move away from the goal, your cost goes up. If you move toward, the cost goes down. All the heuristic represents is a starting point from which to compare the total distances of your future selections. And for distance, no direction is needed.

Yeah but there's multiple paths that might be optimal but some are better than others. The problem I get is that I usually get a path that has one krink in it and looks odd and deviates too much from the straight line path.

Then I do something similar to the "funnel" algorithm to get a better path but it would be nice to start with something closer to what I want.

This is my thread. There are many threads like it, but this one is mine.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.