Jump to content

  • Log In with Google      Sign In   
  • Create Account

Is there anything faster than A* pathing?


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.

  • You cannot reply to this topic
13 replies to this topic

#1 latch   Members   -  Reputation: 753

Like
1Likes
Like

Posted 01 May 2013 - 09:36 PM

Really the title says what I'm asking- clear, concise and correct.



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30424

Like
3Likes
Like

Posted 01 May 2013 - 10:07 PM

There's a lot of variations on A*, which will be better in different circumstances:
http://theory.stanford.edu/~amitp/GameProgramming/Variations.html

#3 Ed Welch   Members   -  Reputation: 483

Like
1Likes
Like

Posted 02 May 2013 - 01:17 AM

If you try to do path finding on a target that's not reachable the A* algorithm iterates through every possible square in the scene, which is very slow. To solve that I use floodfill to check that the target is reachable. The floodfill checks that both start and target squares are both in the same area.



#4 powly k   Members   -  Reputation: 653

Like
2Likes
Like

Posted 02 May 2013 - 05:31 AM

Things faster than A* include, for example, summing two numbers, calculating a dot product or doing nothing at all. Most problems have many good solutions, and the best one must be picked by you depending on the specifics. And even better than a good solution is avoiding the problem altogether, which is also sometimes possible.


Edited by powly k, 02 May 2013 - 05:31 AM.


#5 latch   Members   -  Reputation: 753

Like
0Likes
Like

Posted 02 May 2013 - 09:35 AM

If you try to do path finding on a target that's not reachable the A* algorithm iterates through every possible square in the scene, which is very slow. To solve that I use floodfill to check that the target is reachable. The floodfill checks that both start and target squares are both in the same area.

 I was thinking a floodfill type to determine a solution and then A* only the nodes floodfill evaluated when finding the target.



#6 C0lumbo   Crossbones+   -  Reputation: 2296

Like
0Likes
Like

Posted 02 May 2013 - 10:22 AM

If you try to do path finding on a target that's not reachable the A* algorithm iterates through every possible square in the scene, which is very slow. To solve that I use floodfill to check that the target is reachable. The floodfill checks that both start and target squares are both in the same area.

 

If your data is static enough you can just pre-calculate 'islands' so that you never do any work evaluating impossible paths.

 

For the OP, the key is really understanding your problem domain. E.g. On a simple top-down driving game, your 'pathfinding' could be as simple as caching a direction/speed vector for every point on your map. In a more general case though, A* is pretty hard to beat.



#7 Norman Barrows   Crossbones+   -  Reputation: 2158

Like
0Likes
Like

Posted 02 May 2013 - 10:32 AM

A*'s strong point is that its guaranteed to give you a correct answer. 
 
as i recall, it (and its variations) and slower algo's such as Dijkstra's and breadth/depth first are the only ones guaranteed to work.
 
that floodfill trick Ed mentioned sounds like a good idea, where warranted.
 
obviously there are many things you could do (including nothing) that would run faster. but they aren't guaranteed to work, the way A* and its brethren are.
 
I recall reading an article about something called jump-A* or something like that. probably one of the speedups in the list Hodgman mentioned. there they seemed to be speeding up things by having the search "jump" across open expanses of empty map.
 
personally, i've always suspected that a pathfinding AI that modeled human behavior might be a good approach, especially in those cases where A* and its ilk have difficulties, such as very big maps, lots of units, dynamic environments, areas of the map that are hidden or unknown, limited pathfinding range, etc.  i mean think about it, when we humans want to calculate a path, we don't star making maps and lists of the room in order to figure out how to get to the fridge.  or maybe we do. what we do IS similar, in that we think in terms of the goal (range to target in A*). and then we start plotting the intervening objects.  so we don't create a whole map of the room.  our map is just us at point A, and the goal at point B, and a line connecting them. then we start adding intervening objects, and adjusting the path as needed to go around them. we add objects until all intervening objects have been added, or until we add an object that makes the goal unreachable.  
 
adding an object may cause the path to change drastically (the local maxima problem). we're 3/4 of the way to the goal, then an object comes along that means the shortest path around the objects is now going entirely the other way.  humans probably also do something like add large obstacles to the map first. for convex obstacles, this would work well. for concave we probably enclose them mentally in convex shapes and solve as usual.  and we do it at 2 levels. i'm in room or area A, the goal is in room or area B. at the low level, how do i get out of room A, and in general at the low level, navigation across a given area. then at the high level, we calculate a path through rooms or areas from area A to area B.
 
implementing the low level would be pretty easy. you already have an A* map, and a start point and a goal point. you cast a ray from start to goal. if it hits a BBox on the map, you figure out whether its shorter to go left or right. given the point of impact and the BBox location and size, this is trivial. you move your ray casting point to that corner,and record that corner as a navpoint on your calculated path. then you cast a ray from there to the goal and repeat the process until you cast a ray and reach the goal. the list of navpoints generated describes the line path around the edges of the BBox obstacles.
 
but then you still have the problem of local maxima. i'm in a room with a door to the south. my goal is to the north. any attempt to go north without leaving the room first results in a wall to the north blocking me - a dead end - i'm boxed in.   there i suppose we humans do some sort of "is the goal in my room?" check first. if the goal is not in the same "area" we are, we go to high level (room) navigation to get to the correct area, then raycast our way from the door to the goal.
 
then the question is how does the high level room navigation work?

Edited by Norman Barrows, 02 May 2013 - 10:39 AM.

Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#8 NEXUSKill   Members   -  Reputation: 459

Like
0Likes
Like

Posted 02 May 2013 - 10:43 AM

A* is really one of the fastest there are, but it can be used inefficiently, for instance imagine you have 5 actors standing more or less in the same place and they all want to go to the same destination, do you run A* for all 5 actors? if so, that is inefficient, but not because A* isn't fast enough.

Another example, imagine that in order to get from A to B you must traverse a room from one door to another walking around a table that is in between both doors, barring the prescence of a mobile obstacle, such as another actor, the path within that room will always be the same, are you running A* to find out what it is every time you need to traverse that room? also wasteful, it can be pre-computed on level design and saved into the room information.

 

There are tens or hundreds of tricks like these that improve performance without resorting to an algorithm other than A*, A* is fast enough, reliable, well known and documented and simple to implement for most (but not all) pathfinding requirements, its all about context.

Your question is "clear, concise and correct." but incomplete, why do you feel you need a faster algorithm? what are you using A* for? what is the context?


Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272



#9 iMalc   Crossbones+   -  Reputation: 2306

Like
0Likes
Like

Posted 02 May 2013 - 01:22 PM

I was going to note Rectangular Symmetry Reduction, but that seems to already be mentioned in the link Hodgman posted.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

#10 latch   Members   -  Reputation: 753

Like
0Likes
Like

Posted 02 May 2013 - 04:20 PM

Your question is "clear, concise and correct." but incomplete, why do you feel you need a faster algorithm? what are you using A* for? what is the context?

I'm actually not going to use it at all.

 

I was looking at another devs blog and saw he used A* in his rts so I looked it up and watched a couple videos about it and was curious how the community felt about it and if there was something more epic out there.

 

The context is a mobile tank maze game for android which is a rewrite/upgrade to my first game to bring it a bit more modern. I'm drawing 225 blocks, background, shadows,  up to 200 rounds of ammo, up to 50 rockets, all the interface buttons and displays, and tracking up to ~50 enemies

 

-on a phone or tablet.

 

Those numbers are tentitive so if all continues as it is now on my testing device, I might bump those numbers up- at least the number of enemies because at full power up, my bullets and rockets pour out of my vehicle like water and cut a smexy path of destruction. And I will need my foes to catch my wrath.

 

Screenshot here.


Edited by latch, 02 May 2013 - 05:04 PM.


#11 KnolanCross   Members   -  Reputation: 1317

Like
0Likes
Like

Posted 03 May 2013 - 11:55 AM

I have a grid based A* that uses an unordered list (written in C), it is the slowest implementation of A*.

 

In a 695x132 grid test grid, it takes 15138 microsseconds to find a path from the uppermost part to the bottom (running on a core 2 duo 8400, ubuntu 32 bits). Realistically, the monsters (that use the pathfinding) can only see as far as 20 cells, so this is the maximum size of a path in my game (which takes 54 microsseconds).

 

Answering your question: A* is an algorithm find the lowest cost of going from one node to another, using edges as connections, in a graph. For this problem it is the fastest algorithm you can find. The problem of pathfinding is not the same problem as the one that A* solves, it can merely be reduced to it. So you can use particular properties of the pathfinding to improve its performance (for instance, if someone asks for a very big path, you can break into multiple smaller paths, you can reuse paths for units that are close to each other, you can have a region map to instantly solve unreachable paths and many others).

 

If I were you I would try a very simple A* implemetation and see how it goes, then either try to improve it or limit the action radius of the agents.


Edited by KnolanCross, 03 May 2013 - 11:57 AM.

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).


#12 D.Chhetri   Members   -  Reputation: 181

Like
5Likes
Like

Posted 03 May 2013 - 08:41 PM

Check this http://qiao.github.io/PathFinding.js/visual/ out. Check out the jump point search, with preprocessing and future information that algorithm is very fast. So it all depends on the context. But A* is a good starting point in most scenarios. 


Edited by D.Chhetri, 03 May 2013 - 08:42 PM.

Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github

#13 latch   Members   -  Reputation: 753

Like
0Likes
Like

Posted 03 May 2013 - 11:58 PM

^That's a pretty cool implementation demonstration.



#14 latch   Members   -  Reputation: 753

Like
0Likes
Like

Posted 05 May 2013 - 07:45 PM

One of the units may still require a short path to the player, but don't need it right now. I published the game and you can see me spamming here: http://www.gamedev.net/topic/642744-afv-hail-of-gunfire/






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.



PARTNERS