Pathfinding

For code related discussions and questions
Post Reply
raycast
Trained
Trained
Posts: 131
Joined: 12 Sep 2012, 19:16

Pathfinding

Post by raycast »

Traffic jams probably are one of the most often mentioned issues here in the forum. I'd like to get some improvements done on this side, is there any documentation around to get me started (beyond looking at the code)? In particular, as this can take the fun out of AI games when the AIs just get stuck in "traffic jams" and give you a loong break.

I have a rough idea of how we could improve this. But I can't tell how much slowdown it causes. Basically, I want to buid a "flow" map. Maybe at a reduced resolution to the main map, for performance reasons. So for every 2x2 cells, count the directions the units there want to travel. If there are multiple units going one way, going against the flow gets a penalty in the pathfinding code. The hope is that in typical choke points 2-4 tiles wide, the pathfinding will establish a "two way lane" of preferred travelling tiles just by chance. Or at least, some units might wait on one side letting the other pass through, instead of pushing from both sides until everything comes to a halt.

Alternatively, units that are blocked could in turn mark their tiles als blocked, or at least add a penalty to paths going through there, to encourage other units to use alternate routes.

But before starting on that, I first need to understand some details of how the pathfinding is used in warzone. Is there any documentation available? I know A* quite well, and I have the impression that the pathfinding code could be sped up with some of the newer approaches here (HPA* for example). There are some things in the pathfinding code that probably cause a lot of unneccessary exploration: any tile that is known to be in enemy sensor range gets a penalty factor of 5. Assuming that the sensor range is 10, and you order your units to attack an enemy unit, the A* code currently probably explores a radius of 5*10 into non-enemy territorium trying to find a way to sneak up to the enemy unit without going into this radius (which of course won't work). The problem is that the A* heuristic essentially assumes a flat, unthratened as-the-bird-flies path from any unexplored tile to the destination (unless someone comes up with a better admissible heuristic).

A two-way A* search might be possible to improve here, or the mentioned HPA* approach. HPA* offers also an interesting possibility: approximate the latter half of the path, and only compute the first part in detail. When reaching the end of the refined path, recompute. As the order might be canceled before that, it does save some computations.

Anyway, if we can get the pathfinding faster, it might free up enough resources to add these per-team flow fields, for example, to avoid traffic jams.

Anyone knows whether WZ currently does "steering" (in particular for fast units on hover and VTOL) or assumes that units follow a path on a tile-to-tile basis? There is an interesting framework called OpenSteer. I don't think we should use it in WZ, but it might be good to look at some of the behaviors and add some to WZ. See
http://www.youtube.com/watch?v=dKW-psERFGA

It may be desireable to e.g. use the leader pattern for commanders (except that actually his +x tiles waypoint could serve as a fake leader while he is not targeting an object). Constructor droids on hover should do the arrival behavior to not shoot past a construction site at high speed. Or flocking for group behaviour. We might even want VTOLs to instead of going straight at the target (then slowly turning around) to instead try to do a "fly by shooting", i.e. come in at an angle to pass enemy territory at maximum speed. Or if multiple targets are given, choose a path that attacks them in sequence at max speed. Right now, they would attack the first, turn around, attack it again until its down, then attack the next (just like regular units do). And VTOLs turning around in the range of AA usually means they're down before they get a second attack.

I havn't tried it in some time, I wonder how a fast hover unit goes around a 90° corner. Does it overshoot, or does it step out of the line slightly, then cut the corner tightly? Because the fastest way around a corner at high velocity often looks like this.

Code: Select all

Fast:          Slow:
    ,-._         .._
   /    ->       |  -->
  / +----        |+----
 |  |####        ||####
  \ |####        ||####
   ||####        ||####
   ^|####        ^|####
User avatar
dak180
Trained
Trained
Posts: 288
Joined: 01 Nov 2009, 23:58
Location: Keeper of the Mac Builds

Re: Pathfinding

Post by dak180 »

The person most likely to have the answers you seek is Per, I would also suggest joining [url=irc://irc.freenode.net/warzone2100-dev]#warzone2100-dev[/url] in order to talk to the other devs about it.
User:dak180
Keeper of the Mac Builds
User avatar
vexed
Inactive
Inactive
Posts: 2538
Joined: 27 Jul 2010, 02:07

Re: Pathfinding

Post by vexed »

Nope, no real documentation for anything Warzone related (Pumpkin never handed over the design docs), that you can't find on the wiki.
Most of the time, there are some comments in the code, that may (or may not) apply.

As for pathfinding, this is a thorny issue, while we might be able to use some external libraries, the issue is that they must be deterministic, and also, they have to use floats very carefully, because they can generate different values on different platforms.
/facepalm ...Grinch stole Warzone🙈🙉🙊 contra principia negantem non est disputandum
Super busy, don't expect a timely reply back.
Post Reply