• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ayrton2388

What heuristic should i use for A* ?

10 posts in this topic

I`m working on some basic pathfinding in 3D space. I`m 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. It`s pretty nice until now. Works ok. Creates a nice grid, without the inaccessible nodes or edges. But there`s 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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='jameszhao00' timestamp='1319981226' post='4878565']
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.
[/quote]
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.
0

Share this post


Link to post
Share on other sites
[quote name='Jarod42' timestamp='1320069928' post='4878889']
The better is your heuristic, the less node you may expect to visit.
[/quote]

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

[quote]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.
[/quote]

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 [url="https://harablog.wordpress.com/2011/08/26/fast-pathfinding-via-symmetry-breaking/"]article[/url] for an example.
0

Share this post


Link to post
Share on other sites
[quote name='jameszhao00' timestamp='1319981226' post='4878565']
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.
[/quote]


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

Share this post


Link to post
Share on other sites
[quote name='Trienco' timestamp='1320125811' post='4879149']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.
[/quote]
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.


2

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='thatguyfromthething' timestamp='1320377248' post='4880362']
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.
[/quote]
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.
0

Share this post


Link to post
Share on other sites
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*.
0

Share this post


Link to post
Share on other sites
[quote name='IADaveMark' timestamp='1320377631' post='4880364']
[quote name='thatguyfromthething' timestamp='1320377248' post='4880362']
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.
[/quote]
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.
[/quote]

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0