Pathfinding in city builders. Store the paths?

Started by
5 comments, last by IADaveMark 6 years, 8 months ago

Hi

In a game like stronghold with many workers going back and forth from a workplace to a dropoff-point for example, would I store the path and then use it backwards to not have to redo pathfinding all the time? If the moving units in the city doesnt block movement, very often I could just reuse the old path. Only if i run into a wall (if the player constructs a new building in the path of the old workers) will I recalculate the path.

Workers in old age of empires for example, do they pathfind every time they go back to drop off gold in the storage?

Thanks!
Erik

Advertisement

Normally, it depends on the algorithm you're using (you can alter those in whatever way you want though)
Let's take Flow Fields as an example.
For a single path, the Grid is only calculated once. That is, as long as you don't need a different path, you just don't need to update the grid.

23 minutes ago, suliman said:

would I store the path and then use it backwards to not have to redo pathfinding all the time?

Sure, why not? The worst case is that the path becomes invalidated and then you have to redo the pathfinding - just like you would have had to anyway.

 

Note that if your rate of path searching is relatively low, you don't even need to cache paths. Cache invalidation can be tricky, so if you're not doing hundreds of path plans per game tick, you can totally get away with not caching at all and just recomputing paths from scratch every time you need to.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

7 hours ago, ApochPiQ said:

if you're not doing hundreds of path plans per game tick, you can totally get away with not caching at all

Yeah i've already got a system for cueing pathfinding so I plan on starting like this (allowing max 10 or whatever pathfinds per tick) and see if that works out (no noticable impact on performance). Just wanted to ask the forum anyway to see if I was planning this correctly.

Thanks guys!
Erik

And if you environment isn't that dense and fairly regular, the complexity of your paths is going to be small. Not like you are plowing through 1000 node paths.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
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!"

This topic is closed to new replies.

Advertisement