Operational Warfare Developer's Blog

Developer's blog for the Operational Art of War series

About the author

Ralph Trickey maintains TOAW III
I set this Blog up for fun, and for my own edication! Nothing is guaranteed, it's for my own use primarily, so even if I say that something may happen with the next release, please understand that it may not. I plan to post random thoughts and other things like that at random times here. I don't have a specific plan for what will be here.
E-mail me Send mail

Recent posts

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Pathfinding and Supply

I'm posting this so taht people can understand what was, and what it's changing to.  It's mainly for the people that are looking at what features may/may not fit into future releases, so that they can understand a bit of the mecahnics, and why some things aren't as diffucult as they might seem.

The 'old' way of finding your way from point a to point b was to try to go in a straight line, then look for a different line, etc. Then do special processing for roads, etc. It was extremely slow, but worked well enough on small maps.

The 'new' way is something called A*. It works differently.

A* works by figuring the distnace from the source to the destination, and then starting at the source, calculates the cost to move into the 6 hexes around it. It marks these as 'open' and the starting hex as 'closed'. It them looks through the map and finds the hex where the cost to move into that hex + the remaining distance is the lowest. Once it's foind that hex, it looks at the 6 hexes that are adjacent to that hex, and figures the cost to move into each of those hexes.. If the cost is less, it sets that hex to 'open'. If it's more (like the starting hex would be) it leaves the hex alone.

By doing this, A* will snake a path towards the ending hex. If there's a path to the target, A* is very fast, The only problem with A* is that it will potentially look at every possible hex trying to find a solution if there isn't one. Even on a 300x300 size map, that hasn't been a major problem so far, but if we go to 700x700, it's going to be about 5 times as many hexes.

There are ways to fix this problem by prepopulating a grid, and numbering each hex with a number 1 through N that represents a contiguous region of land or sea. I'll wait and see if I need to do that. That would at least cut down on the search space for 'impassible' paths

It's also possbile to make this allow for trains, planes and ships for Elmer's use, but I haven't tried using these yet. It's probably going to break some scenarios, so it has to wait. Once the program is modified to allow for pathfinding through multiple transportation means, that should help Emler, especially in places like the Pacific.

One very interesting feature about A* is that it's possible to modify it to be useful when you have more tha one source/destination. For example, when retreating, you could use that same algorithm, and stop once you'd reached a command or HQ unit. It would be a little better than what currently works, but probalby not noticeably different in most situations.

Another interesting applicaiton would be for things like supply. It's possible to 'seed' the map with all the supply points, and then to move outward from all of them at the same time , filling in the supply map. This is a LOT faster than the current method, it's also a lot more flexible. The old method made 4 passes through the map. Once for Rail, Roads, etc. The new methid doesn't need to hard code those levels, and can be a lot more flexible, and easier to modify. If we want to allow for supply to travel through friendly owned ports, that's possible, if we want to attentuate by distance instead of doing 4 levels, that's possible. Heck, if we wanted to allow for supply points to provide different levels of supply, that may be possible too.

It's also going to (eventually) provide some perfomance boosts for Elmer. Most of the Elmer code still uses a brute force method of determing his next target. We can do faster/better than that.

I probalby did a poor job of explaing how A* works. There are a lot of tutorials about it on the Net now. The important thing to remember is that is kind of flows out like water, looking for the low spots, and is very fast for a lot of things, and is very improtant for this game going forwards. The fact that is handles multiple sources/destinations makes it very useful for a lot of things.

 

 

 


Posted by Ralph Trickey on Sunday, July 13, 2008 4:50 PM
Permalink | Comments (3) | Post RSSRSS comment feed

Comments

Jeff United States

Monday, July 21, 2008 8:58 PM

Jeff

Would assigning each terrain type a value simplify the procedure? The overlay method sounds like this type of fix.

So, what Elmer uses now is far more 'clunky', apposed to what more modern systems use to determine path, supply, LOS, etc?

And, the follow up question - how much does this code impact the rest of the system? It would seem alot, since path, supply, lOS, etc are the major elements of the system.

Ralph Trickey United States

Sunday, August 03, 2008 8:24 PM

Ralph Trickey

The big problem with that approach is that hexes don't have costs, there's a different cost depending on which edge you go through. The overlay isn't that clumsy.

What I mean by clunky for Elmer is that it does a loot of loops, one for all the radii from 1 to N, one for all the possible x and y coordinates within that radius looking for hexes with that radius. Using A* instead for most of these would be less computationally expensive. This isn't a huge deal for most things, it just makes things slower. For the monsters thtat people want to do (700x700 with 5K units/side, that becomes a bit unwieldly, expecially as the movement points increase with the smaller scale. It's also painful for the Africa and any seaborne scenarios.

Norm wrote pretty good code. Elmer's completely isolated from everything else, Pathing was more involved, but still pretty isolated, supply is going to be the worst, but it's still failry isolated. At some point, I'm probably going to switch to floating point numbers, which is going to be extremely intrusive, but is going to fix a number of issues with the MPs and turn system, etc.

Ralph

jmlima United Kingdom

Monday, August 11, 2008 2:31 PM

jmlima

When you say: 'If we want to allow for supply to travel through friendly owned ports, that's possible, if we want to attentuate by distance instead of doing 4 levels, that's possible. Heck, if we wanted to allow for supply points to provide different levels of supply, that may be possible too.'

YES. We want it. That's about the most need thing to take the game a gigantic step further in the right direction.

Comments are closed