• 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
DeathCarrot

A* question

35 posts in this topic

ok, the news is good and bad:

Bad news first, look at this:


So the blue circles are start/stop points, the blue lines are the (relevant portion of the) triangulation, the green line is the optimal path, and the light blue line is the path chosen by A* over the triangulation, because the red path which, if optimized would yield the green path, is actually longer.

So, no proof :(

Good news next:

A delaunay triangulation cannot have this bad case.

more good news?

I conjecture that with some spiffy coding you can make an A* variant that will allow for discovery of the shorter secondary edges at search time; going on the Wikipedia description of A*:

function A*(start,goal)
var closed := the empty set
var q := make_queue(path(start))
while q is not empty
var p := remove_first(q)
var x := the last node of p
if x in closed
continue
if x = goal
return p
add x to closed
foreach y in successors(x)
enqueue(q, p, y) // magic goes here
return failure

At the line which I have marked magic goes here you would add discovery code to check for each successor, if it can create a secondary path with a node earlier in the path, this then provides a newer cheaper path to the successor.

Will this work?
0

Share this post


Link to post
Share on other sites
I see no reason why that wouldn't work.

If you are correct that the optimal path in the constrained delaunay triangulation always contains the nodes of the true optimal path, it may still be more efficient to use an unmodified A* and then smooth the resulting path. Adding edges during the A* search can waste time adding edges for nodes that won't be on the optimal path.
0

Share this post


Link to post
Share on other sites
or merge your triangles into convex polygons and just use a full navmesh.

and/or pathfind using the middle-point of the edges or the center of the triangles/poygons THEN constraint your navigation to the corners if that makes the path shorter.

or a dozen variations in-between...

but yeah, a delaunay triangulation, which tries to get close to equilateral triangles, would help. There are some pretty good implementations floating on the web.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Vorpy
Adding edges during the A* search can waste time adding edges for nodes that won't be on the optimal path.


Excellent point. Well now I've worked through some delaunay examples, and I can't find a counterexample, but a proof that A* with the pruning step will yield the optimal path eludes me...

Reading about navmeshes, more to come ;)
0

Share this post


Link to post
Share on other sites
Bad news: I found a counterexample.


I drew it the same way as the image above. In this case it is a Delaunay triangulation, and the path found does not go through the nodes of the shortest path. The red arc makes the upper path longer than the lower path when following the triangulation, but taking the upper path and going straight across is the shortest route. Time to try proving bounds on how far from optimal the path can be?

Edit: Actually it looks like I made a mistake and surprisingly in this picture the green and red path is actually shorter than the light blue path. The counterexample still works though, some stuff needs to be nudged around a little.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Vorpy
Bad news: I found a counterexample.


I drew it the same way as the image above. In this case it is a Delaunay triangulation, and the path found does not go through the nodes of the shortest path. The red arc makes the upper path longer than the lower path when following the triangulation, but taking the upper path and going straight across is the shortest route. Time to try proving bounds on how far from optimal the path can be?

Edit: Actually it looks like I made a mistake and surprisingly in this picture the green and red path is actually shorter than the light blue path. The counterexample still works though, some stuff needs to be nudged around a little.


This bad case happens because your discretisation of the continuous search space is too sparse. In other words, your triangles are too big for the precision you want in finding the minimum path.
0

Share this post


Link to post
Share on other sites
It's a counterexample to Symphonic's conjecture that the optimal path in a delaunay triangulation will contain a superset of the nodes in the true optimal path. The path it finds is still pretty good though, within sqrt(2) of the length of the optimal path, at least for this counterexample.

Even if the discretization is denser, if the obstacles do have the shape of those triangles the bad case will still exist, it will just be much more limited in how much error it can produce. There's an idea: adding extra points to the empty space could limit the error in the pathfinding around polygonal obstacles when using a triangulation as the navigation graph.
0

Share this post


Link to post
Share on other sites
fresh thoughts:

I read up on navmaps and other fun things like that. Our (deathcarrot's) problem can be described like this:

We have a space with some 1st order explicit geometric obstacles (points and straight lines forming polygons), we want the Geometrical shortest path, and which means that nodes in the search tree MUST be the points of the geometry, and not some secondary things (like the centroids of convex portions of the non-obstacle space).

We can construct a complete graph and cull edges that don't cross obstacles, but in the worst case this means storing O(n^2) edges, and an exponentially larger path space for searches than with triangulations.

There is no constrained triangulation that will add the necessary steiner points to provide an equivalent planar triangulation without exploding the search space. This is actually trivial to show; suppose there are O(n) secondary lines each of which crosses O(n) triangulation lines then for a constrained triangulation to detect these provide these secondary lines, there must be O(n^2) steiner points added to the plane.

Sooooo what do we do?

I think, the best approach is my original idea :P create a simple triangulation, and add some mechanism to the search to detect simpler paths at search time. Strictly speaking you can't escape the complexity of the search you're trying to do, but at least this way, you're not storing alot of data that's redundant anyway.

Steiner Point: a non-data point added to the space by an algorithm, (in this case, added by the constrained triangulation)
0

Share this post


Link to post
Share on other sites
This might seem a bit out of context, I didn't read the *whole* discussion. But judging from the example map you showed, I'd use simple steering behaviors for outside areas, since they seem pretty sparse (cast ray to target, for the first object it hits, find an intermediate point to go around it), and A* only inside buildings. Since the buildings seem pretty simple I'd just figure out every possible edge and eliminate the ones that intersect with the walls... A bit brute-force, really, but from my experience it would look good and get the job done!
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Jotaf
This might seem a bit out of context, I didn't read the *whole* discussion. But judging from the example map you showed, I'd use simple steering behaviors for outside areas, since they seem pretty sparse (cast ray to target, for the first object it hits, find an intermediate point to go around it), and A* only inside buildings. Since the buildings seem pretty simple I'd just figure out every possible edge and eliminate the ones that intersect with the walls... A bit brute-force, really, but from my experience it would look good and get the job done!

Yup, that's the approach I'm currently most considering, although there will be much larger indoor areas as well that encompass several cells, so I'll need to think up a proper indoor navigation system as well (navmeshes sound promising for the moment).

As for the triangulation discussion (taking simple collision avoidance out of the equation for the sake of argument) - I'm still not convinced that with the numbers we're talking about here that it's worth sacrificing run-time performance for a decrease in complexity at the node-generation stage.
Memory consumption certainly shouldn't be an issue, each edge would just be 2 pointers (one at each vertex pointing to the other) so 200-300 vertices worth of edges per 3x3 segment still wouldn't be much of a problem, a few hundred K at most.
Also, say we have a worst case of ~100000 edges to check per segment, this is still a one-time calculation, and I can't see that taking a long time given a point-line intersection is fairly quick to check for (no (maybe one?) sqrt, no trig), and there's quite a few optimisations like bounding circle checks that could be done to reduce the number of possibilities.

Thanks for the input everyone =D
0

Share this post


Link to post
Share on other sites
Quote:
Original post by DeathCarrot
Thanks for the input everyone =D
You're welcome :) I guess this is why I'm not an AI guy [rolleyes]

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