These were my starting pointsHaha keep up the good work (and if possible throw a few good links into the round so I can suss them in)
http://www-cs-students.stanford.edu/...rog.html#paths
http://www.gameai.com/pathfinding.html
trying to delve into specifics now.
~~~
Thought collection
opinion.
The strategic AI can never be a challenge without either much better pathing or giving the AI very large amounts of money. If you don't like fighting the same battle over and over with multi-stacks of AI armies then you need better pathing. Hence my problem.
observations from AI-watching and map-editing with rtw and mtw2
1. moving region boundaries can change the pathing
2. moving region boundaries, even if the changes are completly within a block of impassable terrain, can effect the pathing.
3. areas of a region that are unreachable from the rest of the region can effect pathing.
4. sometimes the game doesn't seem recognize an adjacent region as adjacent (clue is when the AI will land an army by ship from an adjacent region)
5. the AI seems to move across long distances fine but has problems when it gets close but still further than one turn away.
6. sometimes an AI stack will move to a region and stall on the edge of, or the first tile of the final region.
7. changing something on the map in one area can effect the pathing in a completely different area.
8. On a complex map the AI will often (but not always) stall when moving from region A to region B if the path clips across a region C that is mutually adjacent to both A and B via passable terrain. Doesn't seem to happen at all on my simplified map.
9. the AI has a preference for attacking cities from the south-west.
10. changing movement potential effects the pathing, either via adding movement points or by effectively decreasing movement by adding more difficult terrain to the map.
11. orthogonality matters somehow
12. In rtw an AI would often have problems when they were close to their target in a straight line but an obstacle made their actual path take them further away. seems very rare in mtw2
13. Pathing problems seem to only happen to stacks with a city target. (Possibly i don't notice other times.)
14. AI supporting armies often seem to be happy to get within (roughly) two tiles from the city itself.
15. sometimes a stack will be given a target and not move at all. this is most noticeable at game start.
16. an AI army will often stall after a battle, especially after a retreat from a siege assault. this happens a lot less on a simplified map. it seems to only effect stacks that have a city target. it seems at least partially related to pathing.
17. an AI army will sometimes move only one tile. happened a lot in rtw, especially over fords. can happen at other times. haven't noticed it so much in mtw2
18. There are potentially many hundreds of AIs that need to have their path calculated in the AI turn.
19. Most importantly, the pathfinding code itself works perfectly. When a player selects a unit to move and right clicks on the map the game displays the movement arrow of least movement cost and that's where the stack goes. It never goes wrong in any circumstances. When you select a unit the green overlay shows all the movement paths. It never goes wrong.
~~~
AI pathfinding stuff from Google.
1. There are algorithms that will always return a best path on a map like MTW2 or RTW.
2. These algorithms are computationally expensive.
3. Games have to use multiple pathfinding mechanisms to tweak the computational cost.
4. One tweak is to weaken what is called the heuristic of the algorithm so it doesn't look for the best path, just a close path.
5. Another is to artifially tweak the movement costs of tiles so the algorithm spends less time looking for the best path.
6. A third tweak involves how you treat diagonal moves. calculating the square root of the dx,dy squared being the most expensive and therefore least used for mass AI moves.
6. A common technique (apparently) is to use regions as a kind of macro-tile. With a table of regions, region centre points and their adjacency, an AI can navigate long distances without having to search the whole map for their goal. they first use the regions table to get a path of regions A->C->F then use the expensive tile pathfinding algorithm to find the (much shorter distance) path between the hub points of those regions. Switching back to the tile algorithm when they reach the goal region for the final move to the target.
7. The pages mentioning this technique imply the standard method for doing this involves breaking the regions into convex polygons.
~~~
Current conclusions.
1. When it is the player's move the game knows there is only one stack/agent being moved at a time so it can use the full strength pathing which won't fail.
2. Observations 1-7 (and maybe 8) lead me to think the game is using regions somehow as a macro pathfinder. If it does then that may be part of what it is doing when it generates the map.rwn. However, there's no way TW regions are ever going to be all convex ploygons except on the most simplified maps. There may be a cleverer algorithm i haven't come across that would generate a distance table for regions such as those in a TW game. That algorithm will still have rules though and figuring them out and editing the map accordingly will improve the AI pathing. Alternatively they may just use the full-strength pathing algorithm to generate a region table. Currently tweaking my much-edited vanilla map along the lines of making the region boundaries convex in the directions of travel until i get a better idea.
This system requires each region to have a centre point for the AI to aim at. If the game uses the regions as a macro pathfinder how does it calculate the centre? If it a simple average of the x,y co-ords of the tiles in the region then could it be glitched by some coastline shapes and those little islands that are part of the land regions? The "goal" setting on these long range moves may be weaker i.e not reaching the "centre" tile of a midway region but getting within 2-3 tiles maybe as i think this would be cheaper to compute.
3. Pathing algorithms have a start tile and a "goal" tile. Observation 9 makes me think the goal tile for a city is maybe not the city itself but the sentry spot for a city (usually the bottom left of the tiles around the city depending on terrain). Making sure there is a clear path to this tile for each city may help.
4. Observations 10-12 all look like the kind of things that could happen with "weakening" tweaks to the pathing algorithm. So basically certain combinations of terrain might cause the algorithm to not return a valid path under certain combinations of movement cost and movement points.
5. Observations 13-14 make me think stacks with a city target have a stricter "goal" setting which in combination with the algorithm weakening tweaks makes them more prone to getting stuck.
6. When building the regions distance table (if they do) and using the terrain tiles to calculate it, if they used the full strength algorthm to generate the table but used the weakened algorithm when actually moving the AIs that might be behind some of the glitches. this might relate to observation 15.
7. the retreat/post-battle stall could (and probably is imo) be caused by more than one thing. in some cases it is simply the AI retreating to a tile with a pathing problem.
8. observation 17. dunno. more googling
9. observation 18.
a)The meaning of convex in the context of a TW map. With all fertile tiles and no obstacles the best region shape may be a convex polygon but is that the correct shape when the varying movement costs of tiles is taken into account.
b)If the AI is using tile based pathing from A to B why should it care if it finds itself in C for part of the route?
c)Why doesn't the AI care about crossing a mutually adjacent region when the regions are convex polygons on a simplified map (or is it the movement cost/terrain)
10. Game may give AI stacks with a city target a first sweep with the full strength algorithm for up to one turn of movement. If it finds the goal it moves, if it doesn't it cuts off and uses the weakened algorithm. This would explain the one turn move effect.
11. "might" not be possible to get perfect pathing on a large realistic map
12. "might" not be possible to get perfect pathing on a large realistic map without very long end turns
13. definitely possible to get perfect pathing on a small simplistic map (apart from retreat stalls)
14. "might" be a cut-off point where you can get perfect pathing on a quite large, quite realistic map.
~~~
another pointer to the game using a region distance/adjaceny table is the low number of regions they have in the vanilla game. these tables require the region number squared records of however many bytes. so 60 regions require 3600 times x bytes and 200 regions require 40000 times x bytes.
AI end turn slows down a lot as you add more regions. mods with large maps might want to consider agent limits and more expensive units to cut down on the total number of moving AIs.
Bookmarks