View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# simple pathfinding

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.

21 replies to this topic

### #1BeanDog  Members

Posted 18 May 2000 - 06:58 AM

I''ve got an array of about 256x256, which stores, among other things, an array of bool''s that say whether or not my unit can move there. How can I make a very good pathfinder from any one spot to any other? ~BenDilts( NULL* AIexperience); Bean Dog

### #2Andreas Jonsson  Moderators

Posted 18 May 2000 - 08:10 AM

You''ll want to look into the algorithm called A* (pronounced ''a star''). It is a farly simple yet powerful pathfinding algorithms. There are better algorithms but they are usually modifications to A*, and they are only needed for very long paths.

You can find a lot of info on A* at Amit''s Game Programming Information.

- WitchLord

### #3BeanDog  Members

Posted 19 May 2000 - 08:58 AM

thanks for the tip.

a* seems way overkill for what I''m doing, though. I am doing a real time strategy game (very early in development). I just got my creatures to move correctly, but (go figure) they don''t go around stuff by themselves. So I was thinking, I could do a really simple algorithm, since my units can either go onto a space or not, and I store my terrain-blocked map squares separate from my unit-blocked ones. I could just do a search straight from the unit to the destination. If the search path hits some terrain, it SPLITS into two other searches going on simultaneously, one going left and one going right, and so on. If two paths ever cross, or a path hits where another has already gone, they will be eliminated. This will repeat until either the destination is reached by one path or all are dead-ended.

This may sound complicated, but it may be easier than it appears. This will only be done once per time that the unit is directed to a new destination, so it won''t slow down the game significantly. I''ll do a one-step-at-a-time procedure if it runs into another unit or building.

Any comments or suggestions?

~BenDilts( void );

### #4bogdanontanu  Members

Posted 19 May 2000 - 09:43 AM

I know a MUCH BETTER algorithm then A* one....

but cant tell you much because its secret...as it will be incorporated in may new release of a RTS...

All i can tell is that is a better algorithm...(but not faster than yours...
yours above is the fastest...but also has some problems in a labirnth

I may be able to speak after game release...

### #5BeanDog  Members

Posted 19 May 2000 - 12:31 PM

Well, thanks a TON for the info, retard. I was all excited that I got a message, and it was just you bragging your cajones off. Get a life.

### #6Andreas Jonsson  Moderators

Posted 19 May 2000 - 01:10 PM

BeanDog, your search algorithm will work. I believe it is called either depth-first search or breadth-first search depending on how you implement it. I think you should go with that so that you can get on with your game, but later on I would recommend A* as I believe it is the best for what you are doing. And no it is not overkill, it can bring down the pathfinding processing time to perhaps 10% (educated guess) maybe even less. And that in turn allows your game to build intelligent paths for goals at farther distances.

- WitchLord

Edited by - WitchLord on May 19, 2000 8:11:47 PM

### #7BeanDog  Members

Posted 20 May 2000 - 04:22 AM

OK, I''ve got a basic pathfinder working, but it is so SLOW! How am I going to get the more-complex a* to work if a simple approach works so slowly? How would I choose where the waypoints would be? I couldn''t use every block in a 128x128 grid!

### #8Kylotan  Moderators

Posted 20 May 2000 - 08:05 AM

quote:
Original post by BeanDog

OK, I''ve got a basic pathfinder working, but it is so SLOW! How am I going to get the more-complex a* to work if a simple approach works so slowly? How would I choose where the waypoints would be? I couldn''t use every block in a 128x128 grid!

A* is a more complex algorithm but the complexity helps it be more efficient. As another example, bubble-sort is a ''simple'' algorithm but quicksort will beat it nearly every time. What you save on code, you lose on processing time, mainly.

### #9BeanDog  Members

Posted 20 May 2000 - 11:46 AM

Perhaps I should define "slowly". I direct 50 units 100 squares accurately in about .5 seconds. That is still too slow for a real-time game.

### #10Andreas Jonsson  Moderators

Posted 20 May 2000 - 12:04 PM

I think you should try to implement A* and see just how much faster it is.

Another way to speed up the pathfinding might be to divide you map into small areas that contain for example 8x8 squares, then you first use the pathfinding algorithm to find the way among these. After that you use the pathfinding on the squares in each of the areas to get the exact path.

- WitchLord

### #11Kylotan  Moderators

Posted 23 May 2000 - 10:47 PM

Also, instead of trying to fulfill all pathfinding requests at once, consider doing it in 2 stages: the order to move a unit from A to B generates a Pathfinding request, which you add to a queue. Then elsewhere in your game loop, the Pathfinder picks off these requests and deals with them. You can then limit it to only dealing with 10 requests per frame, or limit it to only spending a certain number of milliseconds dealing with requests. That way, your frame rate / game speed won''t have to visibly drop. The only difference is that certain units will remain still for a little while longer, but this is rarely an issue when you have 50 moving at once.

Posted 24 May 2000 - 09:25 AM

Maybe a quadtree (or octree) is a good idea...?...!

### #13Anonymous Poster_Anonymous Poster_*  Guests

Posted 26 May 2000 - 09:41 AM

Hi

I''ve the same problem you have *g*

I have a* implemented, but it is still to slow to move ~100 untis. Putting pathfinding in a thread doesn''t work too (gameslowdown 99% (

what you have to do is ''cheating'', finding a way to speed it up.. I thougt about pre-calulated path (like aas in q3), but haven''t found a way to do it.

if you find an solution, i''d be grateful if you tell us/me how you did it )

safti@safti.de
www.safti.de

### #14Anonymous Poster_Anonymous Poster_*  Guests

Posted 28 May 2000 - 08:31 AM

You could speed it up A* by improving the efficieny of the implementation, preprocessing the seach space, and buffering paths found.

a)I dont know how you implemented it so i can''t comment, but if you search here http://www-cs-students.stanford.edu/~amitp/gameprog.html for some implentations of A* you can compare your implementations

b)You could do like one poster suggest and prune the search space down using a quad-tree approach, or if your more ambitious decompose your search space into a voronoi diagram.

c)Basiclly A* is computationally very intensive, and if you buffer paths you can take advantage of the coherency of start and goal postions. For instance if 2 entities start close to each other and their goals are close to each otehr too, you can compute A* for one, and use it for the other too. Just make sure you find the path from one''s start position to the others and the same for the goal, which should be computationlly smaller since they are closer. Depending upon your memeory liminitation, you could buffer in 100''s of paths which should give you signigicant performance improvements if there is good coherency. If not you get worse case, either way.

Good Luck

-ddn

### #15bogdanontanu  Members

Posted 29 May 2000 - 01:12 PM

Sorry i see u got it too hard...my prev message to u...

hmmm i just wanted to say that even if i cant tell u (because of contracts...not that i dont want to )
to open ur mind to diffrent approach than A* with everybody thinks is best but is not....

Now i feel like i have to help u a little so u dont get mad at me:

whatever algorithm u use....
1.First
u can use it once to find the path then store all points in a vector then use that vector to move units until eventually a obstacle is found...in this case redo the pathfind....
2.Second
Dont do "whatever algo u use" for all units at once...better do one unit at a cycle...
so if u have 50 units unit 1 will start then next cycle unit 2 will start...u get the picture....this will make units remain a little late....but ALL Realtime games make it one way or the other...

Hope this helps
Sorry again didnt wanted to make u mad....

Bogdan

### #16Hans  Members

Posted 30 May 2000 - 06:45 AM

Check out my pathfinding algorithm. Totally precalculated and definitely the worlds fastest pathfinding algorithm .

http://www.kolumbus.fi/hannes.k/tip2b.htm

Well my algorithm isn''t maybe simple to implement, but it''s hell fast. It takes only one memory read to move a unit one step towards it''s goal, using almost optimal path!

The idea behind it is quite simple though and needs lots of thinking still, but you might be interested. Dynamicy is a problem with this algorithm, because everything is precalculated. However, it IS possible to make dynamic parts but it needs some extra work if there are dynamic parts on the route..

The algo can also solve any maze and no matter how complex map, equally fast.

-Hans

### #17StrategicAlliance  Members

Posted 30 May 2000 - 08:06 AM

Hey,

Last year I did a project on this topic with a few friends for my course Datastructures & Algorithms II.

It features a state of the art report on holonomic motion planning with several basic algorithms.

There''s one drawback, the project is written in Dutch (sorry guys), but I''ve also added a Visual Basic program which should visualize what I do and the algorithms are open-source.

Let me know what you think about it!

******************************
Stefan Baert

On the day we create intelligence and consciousness, mankind becomes God.
On the day we create intelligence and consciousness, mankind becomes obsolete...
******************************

### #18StrategicAlliance  Members

Posted 30 May 2000 - 08:08 AM

Woops, you can access the page form my homepage of course, but here is the direct link:

http://www.softline.be/StrategicAlliance/RUG/MotionPlanning/

******************************
Stefan Baert

On the day we create intelligence and consciousness, mankind becomes God.
On the day we create intelligence and consciousness, mankind becomes obsolete...
******************************

### #19Anonymous Poster_Anonymous Poster_*  Guests

Posted 30 May 2000 - 09:56 AM

If you want to speed up A* a little, you can put a limit on the number of
precalculated waypoints that you can do. So if you have a very long path,
for example, from one side of the map to the another, the unit will precalculate
a couple waypoints, follow that path, and then precalculate another, etc..
until it reaches its target.

The only downside to this is that if you limit the number of waypoints too
much, the unit might not be able to get out of a tight space like a half
circle area.

Another speedup is limiting the number of directions that the unit can use.
16 directions is kinda slow, 8 directions is ok, but using only 4 directions
is much faster. It''s computationally less searching.

### #20BeanDog  Members

Posted 01 June 2000 - 05:43 AM

OK, here''s how I do it. I have a search algorithm that goes directly toward the goal until it hits something. Then it splits up into 2 searches, going opposite directions around the obstacle. As soon as a dead end is it, that search is eliminated. This is a very fast method. When you first move a creature, I calculate the first about 50 squares in the path and store them in the creature itself. When it gets to the end of that 50, I calculate the next 50, etc until the unit gets to the destination. This is pretty darn fast, but not fast enough. I will try implementing how I will just do one per frame, but that will be a problem when the units get to the end of their 50-square process and have nowhere to go.

Thanks for all the advice, and when I have time I''ll check out your super-fast algorithm, Hans. I have a feeling it will be very memory- intensive, though, especially for large maps (256x256 and up).

~BenDilts( void );

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.