PDA

View Full Version : Game AI stuff (1.5)



nikolai1962
04-15-2006, 00:30
10th anniversary update post

A lot of my earlier posts are only semi-correct as they mostly revolve around observed symptoms of the problem rather than the root cause. I don't want to delete them but to avoid confusion it's best to skip to the most recent update post which is currently post #97, link below.

https://forums.totalwar.org/vb/showthread.php?63614-Game-AI-stuff-%281-5%29&p=2053771349&viewfull=1#post2053771349


######

(Edit: This thread gets gradually more accurate as it goes on. Condensed the map path-finding results so far here: https://forums.totalwar.org/vb/showthread.php?p=1485851#post1485851 Will make a seperate condensed post for the non-map related stuff later.)

######

Tested out with a slightly modded vanilla 1.5 and then seemingly confirmed (as much as is possible) in an un-modded vanilla 1.5


At the start of the game the AI will target one or more regions adjacent to one of its starting provinces. The number of targets depends on its starting armies and positions.

It will always go for a rebel target first even if you set the faction's core_attitude to rebels to be lower than to a neighbouring faction (maybe not true if it is really far away and has a much larger garrison than best available faction region but very heavily weighted towards preferring rebel regions). In some cases if a faction starts at war with an adjacent faction it may *also* target a faction-held city but it's first target seems to be always rebel and usually the second target also if there is one. Generally, if a faction has a land border with a rebel region and isn't at war with another faction it will always go for the rebel region regardless of core attitudes and starting neutral to rebels.

The initial target selection seems to be based on the number of ai stacks that have spare units after leaving behind a garrison. So each large enough stack will move to a target. If the moving units are deemed too small for a target then they move towards one of the settlements that has been targeted by a big enough stack (even if on other side of faction terriotory). The original targets are *always* the same for the same starting conditions. If none of the starting moveable stacks are deemed big enough the faction waits while it builds units. The ai rarely seems to join existing armies first and then attack. If a bunch of starting stacks move towards a target they will stop and re-assess the situation when the first one reachs and besieges it.

If another faction targets the same province and reachs and besieges it first then if the moving faction is hostile they will often attack the besieger and start a faction war. If they are allied/non-hostile they usually sit and wait for the outcome of the siege. Sometimes the whole faction stalls at this point. Mostly the faction doesn't stall but often/usually the stack that moved to the target will stall, even if the the other faction loses its assault and the target becomes free to attack later. The stack will eventually unstick but it may take many turns. This can cripple a faction if it is a small faction's main force.

Also if the attacking stack reaches its target and loses its assault then that stack will often stall until something else happens to unstick it. Small factions with only one initial moving army will then be stuck until they build a new force or another force that was already moving to the target sieges it. Small factions can be completely stalled by this too.


The determinants of target regions:

1) Size of ai stack after leaving behind a garrison
2) Distance
3) Target garrison
4) AI attitude to faction_creator specified in descr_strat e.g can make ai switch choice between intiial target if faction is allied to faction-creator of one target and hostile to faction_creator of a another.
5) Clear line of sight between settlement/stack and target settlement. This doesn't mean FOW, spies etc *seeing* the settlement. It seems to require an unblocked straight line between stack/settlement and settlement. Hills, mountains, wonders block this, maybe woodland too.

How the determinants balance against each other is too hard to work out i.e how important faction_creator is compared to garrison size etc. All i can be sure of is one ai faction would always go for the closer of two rebel settlements (with the exact same garrison) if both targets had the same faction_creator but would always target the further one if i made the faction_creator of that city a faction they were more hostile to.


The factor that outwieghs all the others is LOS. If there are low hills etc between a target city and all the adjacent faction regions/stacks then they will ignore it completely at game start. This is not surprising when you consider that unconquerable settlement mods do it by surrounding the settlement with hills. (Didn't occur to me until i saw it though.)


Palmyra on the vanilla map is an example of this. Factions don't seem to target it unless they already have arabia or bostra. The hills between palmyra and the starting positions in the other adjacent regions seem to prevent it being targeted.

The vanilla seleucids are a good example of how this effects the game. They don't attack the obvious targets of Halicarnasus or Palmyra early on. Halicarnasus because the nearby stack isn't big enough, Palmyra because they don't have a clear LOS (placing spies at start does't help this). So the region they select as their first target is dumatha/arabia because it is closest (in a straight line not in the amount of time it takes to reach) from their stack in seleucia. Because it is so far away from the start location of the seleucid units by the time they get a stack close to attacking it Parthia has usually already got there and egypt, pontus and armenia have already expanded and started to look for new targets.

This initial target selection cripples the seleucids from the start and makes the big yellow steamroller almost certain every game. Re-arranging the initial seleucid start location to either make the garrison at sardis big enough to move against halicarnasus or placing some seleucid units on the other side of the hills so they see and target palmyra makes sure the seleucids have a good chance of grabbing those two regions before the inevitable multiple attacks start. Usually you still get a big yellow steam roller but it takes a lot longer and isn't a foregone conclusion.


Anyway, from a general modding point of view some suggestions.

1) Always have an island or remote faction somewhere for testing how the ai performs.
2) Run the game with FOW off and find each factions starting targets, then watch for:

a) Factions picking a target very far away because of LOS issues.
b) Starting stack just big enough to target a rebel city but too small to consistently win the siege. Small factions may stall here.
c) Small starting stacks that set off for a target city regularly hitting rebel stacks that are too big to defeat or which cause too many casualties. Sometimes the ai stack will stall here, sometimes it may go on to lose the siege (cos of casualties from rebel battle) and then bounce off and stall.
d) Two factions picking the same initial target and then getting into an early war because of it.
e) Generally, small (and possibly all) factions will start off better if set up with one main army and several small garrisons rather than lots of small armies as they seem to decide what to do on a per stack basis and lots of small armies will assault, lose and stall a lot.

The other big ai problem is path-finding.

After fixing any problems with the ai faction's initial targeting run some long games with your island test faction where you just click end turn a lot and watch for those regions the AI has trouble reaching. Any kind of impassable terrain can cause the ai problems often depending on what direction they are expanding from, river crossings, mountains, hills, wonders etc. Sometimes it will be fine from the region to the west of a target but not the south etc. Simple map tweaks can often fix these. Eventually you'll get a situation where the AI stalls far less often which will make the game a lot more challenging i think.

A seemingly surefire way to know a faction has a path-finding problem is if you see a large cluster of single-unit stacks not moving over a number of turns. Working out why it is stuck is another question :) Sometimes it is obvious though.

Core-attitudes, "prefers naval invasion" etc

These seem to have limited (or very limited) effect. The reason seems to be that initially the ai will target rebel regions. Eventually they'll run out (though you can deliberately make them ignore some regions by moving the settlement far away) and then they'll decide to attack somewhere else. Core attitudes etc may play a part here although the main determinant seems to be relative strength/weakness. However once a war starts between two factions both sides seem to give massive weight to any adjacent enemy region until the war ends. At that point core-attitudes etc may briefly come back into play again until the next war starts. (Maybe if a core-attitude is set to be 600 i.e the same as being at war it will have more effect).

In other words the core attitudes have an effect but only really when the ai faction is at peace and thinking about its next move.

The ai will mostly make naval invasions when it doesn't have an available land target. This happens mostly when they are blocked in by allies/protectorates that they don't want to attack. In this case they'll land quite far away if neccessary. Some landings never seem to take place from certain directions (LOS again i think) e.g factions holding greece never seem to land on crete, though they will on cyrene occasionally, whereas egypt will land on crete sometimes if they get blocked in by alliances. Again, i *think* it is to do with the hills/mountains from different angles. One settlement will have a clear LOS to a region while another won't so only a faction holding the right regions will consider it. There does seem to be a distinction here between whether the region is rebel-held or faction-held. Rebel regions with no clear LOS from anywhere (like the original iberian capital if it goes rebel) can remain rebel the rest of the game, whereas if it is faction-held it is less likely.

The presence of the senate over-rides some of these problems in the vanilla game. Also the 3-family split makes the romans consider naval landings more because the scipii and brutii are blocked in from the start by their roman allies. A unified roman faction has more problems because it is not blocked in unless it makes an ally/protectorate of the gauls.

(I haven't got BI as none of my fave mods use it yet but i wonder if they've simplified the LOS between regions and that is what improves the ai.)


Some simple regions/settlements modding stuff that works.

1) Make a huge sahara that touchs the sea between egypt and carthage terriotory so their border region lies along the sahara edge. Then move the sahara settlement so that it is a long way west but close to its northern border with the coastal african regions. The distance between settlements east/west makes carthage/egypt ignore each other completely but the settlement is still close enough to the coast for any faction that holds one of the coastal regions to target sahara (or move it to bottom left corner so both carthage and egypt ignore it and let it stay rebel).

2) Have long vertical steppe regions with the settlements in the far north. The short distance between settlements east/west makes the steppe factions fight over them but the large distance north/south makes the armenians (for example) ignore them and expand south instead. The steppe factions will still come south when they run out of targets and the settled factions will still come north if they conquer all the southern regions but not until they have no closer alternative targets. Otherwise factions like the armenians waste their time (imo) sending infantry armies (very very slowly) way up north instead of fighting over richer southern terriotory.

3) After watching where the ai gets stuck with rivers, add a ford.


General things:
Read somewhere the ai never moves its capital. It does in 1.5

The settlements of regions specified in the victory conditions are visible when playing that faction (which is neat imo).

Makanyane
04-15-2006, 19:53
Great research, :2thumbsup: thanks for this.

Hadn't realised importance of faction_creator, will have to re-look at our descr_strat!

Re: pathfinding, do you know if there tend to be more problems with large blocks of impassable terrain or with scattered obstacles?

Re: BI, unforunately can't remember vanilla results but have since been playing with adapted Icetorques/Bare Bones map (which is much larger than vanilla) map and AI factions don't seem to target rebel provinces in Norway/Sweden peninsula or Ireland (200 turns plus & all other provinces occupied).

shaggy1973
04-15-2006, 22:11
faction creator is in the descr_regions - the faction creator in the strat just takes care of the way the province looks on the strat map/battle map - i have been using a combination of victory conditions and region creator yo guide the ai into where i want it to attack from the start. it works very well (i dont have any rebel provinces in at the moment to make things complicated)

works well :)

nikolai1962
04-16-2006, 10:32
Great research, :2thumbsup: thanks for this.

Hadn't realised importance of faction_creator, will have to re-look at our descr_strat!

Re: pathfinding, do you know if there tend to be more problems with large blocks of impassable terrain or with scattered obstacles?

Re: BI, unforunately can't remember vanilla results but have since been playing with adapted Icetorques/Bare Bones map (which is much larger than vanilla) map and AI factions don't seem to target rebel provinces in Norway/Sweden peninsula or Ireland (200 turns plus & all other provinces occupied).

I'm going to experiment more both with the path-finding and the target selection but at the moment it seems like the ai tries to figure a straight line path and doesn't like situations where they have to move away from a target to reach it e.g going round a big block of dense forest or moving along a river to a ford if it means getting further from the target.

Some rebel regions can stay rebel for sure. All the ones I've seen so far are either islands or have some other path-finding issue. Garrison size and distance must be (?) taken into account too but i think the anti-rebel priority is quite high so the distance/garrison need to be large to outweigh this.

nikolai1962
04-16-2006, 10:34
faction creator is in the descr_regions - the faction creator in the strat just takes care of the way the province looks on the strat map/battle map - i have been using a combination of victory conditions and region creator yo guide the ai into where i want it to attack from the start. it works very well (i dont have any rebel provinces in at the moment to make things complicated)

works well :)


I'll check this again as i have a habit of changing the creator in both regions and strat so they match.

Tittils
04-16-2006, 16:29
Great research!
This will be very useful:)
Thaanks

shaggy1973
04-17-2006, 01:32
the ai isnt obsessed with rebels. ive put alot of rebel factions along the border of gaul and they still come for italy. need to use province owner/creator and victory stats and they still go where you want them to. oh and the rebel garrisons are all really strong.

nikolai1962
04-17-2006, 10:03
the ai isnt obsessed with rebels. ive put alot of rebel factions along the border of gaul and they still come for italy. need to use province owner/creator and victory stats and they still go where you want them to. oh and the rebel garrisons are all really strong.

I was wrong in the first post saying the ai *always* goes for rebels first. It is more complicated than that but at the start the rebel garrison needs to be really strong (stronger than the entire starting army of the faction they are at war with?) or very far away/on an island/in a region the ai has a problem path-finding to, for the ai to ignore them. In some cases if the ai has only one choice between a very strong rebel region and starting a war they sit and build troops then eventually their stacks start moving to the rebel region.

~~~

This is turning into more of a WIP than a guide as i keep seeing new things. For now I'll add stuff that was wrong in new posts and then edit the first post when it is all confirmed.

Update:

Forgeting islands for a bit (I'll go back to them later) the problem between two adjacent land regions isn't that they have no clear LOS exactly. Roads are the clue. The game picks a route for a road between any two regions that share a border. The exceptions are when they only connect at a corner or when the entire border is impassable e.g river with no ford. The game seems to pick the route with the least movement cost from A to B. Hence why hills are avoided where possible. The path of least movement cost is rarely a straight line between the two settlements. The problem seems to be when the path of least movement cost doubles back on itself to some degree so that an army moving along that path would at one point on its journey be moving away from its target.

The mods I'd made when i first noticed how often the ai got stuck included much more expensive roads which is why it wasn't as obvious but if you look at the roads to palmyra from damascus, antioch and hatra they all have a 90 degree bend at one point. I think having a "least movement cost" path between two settlements with a 90 degree bend or more causes the ai to glitch. You can alter the path in various ways: changing the ground type, moving fords, moving settlements, rivers etc.

My updated tip for any new map (or vanilla map for that matter) is to test by adding roads to every region in the strat file. Then look over the map for any roads between two regions that have a sharp bend between two settlements and try to make the path between each pair of adjacent regions go roughly in the right direction along its whole length. The road layout isn't 100% the same as the path the ai would choose without roads as the network tries to link up with other nearby roads going to different regions but it is a good start. When you do edit the paths this way the ai gets stuck much less often and wastes far less time. I've only changed part of the eastern vanilla map so far but you can see when watching the ai how nearly all their armies are moving with some kind of purpose now when fighting in that area.

Main thing is core attitudes and diplomatic stance aren't enough on their own to stop the ai prioritizing rebels.

~~~

Other factors that influence initial ai moves.

The ai likes to leave a larger garrison in settlements with no barracks.
The ai likes to have stronger garrisons in regions with a lot of adjacent regions.

So if you had an initial setup with mostly garrions and one large army that you thought was big enough to target a nearby region the ai may leave more of that army behind than you thought it would.

~~~

Previous post mentioned Cyrene as a consistent naval landing, it was rebellions not landings.

Monkwarrior
04-20-2006, 00:51
Nice research work, nikolai.

As this is WIP thread, perhaps you will be interested in our own experience.

Our main problem in ITW campaign was to simulate the historical situation before the second punic war, and we focused on romans.
We wanted that they forget the gauls and try to land in Iberia (of course with naval_invasions yes). We wanted also that the carthaginians tried to expand towards north Iberia, and even trying to reach Italy.

These are some of our observations:

- We observed the attraction for the rebel regions... even if the first senate mission was an enemy region. The two regions (rebel and enemy) were in the limit of the roman territories. The mission was canceled in the second turn, and substituted by the conquest of the rebel region.

- Considering important the LOS of the faction, we put from the beginning a roman fort in Iberia, with a full stack garrison.
The owner of the region was neutral, but there were rebel regions near there. However, the AI didn't make any movement with that powerful army during 50 turns.:no:
But the owner of the region didn't attack either the roman garrison. Only garrisoned the settlement with also a full stack army (just in case, I suppose).

- The situation changed dramatically if romans are the owner of an Iberian region. In that case, they send naval invasions. Thus it is not only the LOS, but it is necessary that the faction owns the corresponding region.

- Another attempt was to surround the faction with allies. This method was not useful, as sometimes the allies became enemies in the second turn and sometimes the faction stayed peaceful for many turns.

- We also tried the idea of "super-alliances", including the option of superfaction. This system gave some unexpected results.:inquisitive:
First, two superalliances were built, one with romans as superfaction and the other with the carthaginians. Instead of a more agressive behaviour, both factions remained peaceful, with impressive large garrisons and full stack armies in fields.:wall:
After the first surprise, this behavior is not so strange, as the superfaction takes the role of senate in the vanilla campaign, without expansionist behaviour.
The other way round seems to be better:idea2: . If the gauls are the superfaction, then the romans are surrounded by their superfaction, and they try to expand by sea.


These are not final conclusions (we are also working on this aspect), but they can help to future research (I hope).

nikolai1962
04-20-2006, 02:59
Monkwarrior,

Very interesting stuff. The situation you are working toward is similar to me wanting the roman ai (on whatever map) to at least sometimes expand against carthage and spain. As your post says it needs two things, first to make the gauls and romans less likely to fight and second to make the romans look toward carthage/spain and carthage to look towards spain. Somehow i'm sure it is possible and some of the stuff at the end of this post may be relevant to you :)

~~~

I worked out how to take screenshots so this new update may get messy as i work out how to insert them.

https://img154.imageshack.us/img154/7630/stall25cv.th.jpg (https://img154.imageshack.us/my.php?image=stall25cv.jpg)

Ok, images work.

As working this all out on a standard map was too tricky with so many things going on at once i decided to make a simplified test map to get more definite answers (thanks to Myrdaal's great map-making guide). The idea being to create a setup for testing more definitively the effect of core attitudes, distance garrison etc with the ai targeting. As before though, when trying to test this with the vanilla map, it soon becomes apparent that map path-finding glitchs > all.

The strat file was et up with britons (on an island) and the romans with one city and a very simple layout of square regions with a settlement in the centre, all flat, fertile terrain etc. The first image shows the first path-finding glitch. In this setup what the roman ai does is first build a spy, who sets off, then start building units. When they have 2-3 they target an adjacent city. Rome keeps producing small stacks and sending them off to new targets while the original stacks move on once they've taken their target. What you see is a path-finding glitch that happens when the shortest route to a target is a direct diagonal line. Just past halfway to the target the stack stops and stalls permanently. Not only does that stack stall but the ai doesn't send another stack to the same target (at least not against rebel cities with no garrison, it does under some other other circumstances) so in this test the romans stalled entirely at this point as the only adjacent land regions were targeted by stuck armies.

https://img154.imageshack.us/img154/7630/stall25cv.th.jpg (https://img154.imageshack.us/my.php?image=stall25cv.jpg)

The second image shows exactly the same thing on a different test and is posintless but i linked it anyway :)

Now obviously this is a very weird map but i bet most modded maps have at least one pair of settlements where the least-movement-cost path (gonna call it the LMC path from now on) is a diagonal line. This might even be the effect i saw on the vanilla map with palmyra. The seleucid ai *had* sent an army against it but they'd got stuck and therefore not only did the seleucids not send another army to palmyra they also didn't target any others. Either way it shows how the ai can stall when stacks get stuck on the way to thir targets and how, if there are only a few targets available, the whole faction can stall.

Just to emphasise the problem even more

https://img163.imageshack.us/img163/7725/stall44jj.th.jpg (https://img163.imageshack.us/my.php?image=stall44jj.jpg)

Even if the ai ends up with another army right next to an empty rebel city (for example through chasing rebels) that stack won't attack because that city already has a stack supposedly on its way. The roman stack left of the city stayed there until the next random rebel spawn when it went off to chase. (The swamp was my first attempt to make the ai pick a different route, failed attempt obviously).


Next thing.

https://img110.imageshack.us/img110/2323/stall55yd.th.jpg (https://img110.imageshack.us/my.php?image=stall55yd.jpg)

This shows two things, first is how those blocks of dense forest got round the diagonal bug. I'm guessing this may be something to do with roads not being able to go diagonally while units can so the LMC path for a stack is maybe calculated differently than from the settlement, if the settlments are somehow used to claculate valid targets through calculating the distance between settlements. Who knows, either way it is hard-coded so only thing is to find the spots where it happens and fiddle with the map until it is fixed. Another thing is i noticed when trying to figure this out with the vanilla map that stacks often seemed to stall after fighting rebels but not always. The diagonal thing may be at play here too as they advance/retreat to tiles after the battle and that messes up their path. It may be something completely different though. We shall see.

The second thing the image shows is another (less serious?) stalling issue. In this case the romans have targeted ariminum but the rebels keep building units there so the romans keep adding more units to the stack waiting to attack it even though they have other adjacent regions that could be attacked easily. This stall gets broken when they have a full stack and produce one more unit. The ai must re-assess at that point because both the big and small stacks move off (not neccessarily at ariminum either). Main thing here i think is if a mod had very expensive units/buildings and started a faction off next to a single adjacent region that had a large rebel garrison or a rebel city that the rebel ai picked to build units in. The ai faction might keep building units until they bankrupted themselves. The original reb garrison might have been small but just coincidentally that city is picked by the rebels to produce units in.

note: In this setup I had all except the roman and briton starting cities unspecified in the strat file which made them all rebel villages. There were no starting rebel armies. The rebel ai in this setup *only* built units in the regions that started off adjacent to faction cities i.e the four regions adjacent to rome. I've played mods where this didn't seem to be true but maybe it was because they gave the rebs so much money they ended up having built everything possible and therefore built units? Dunno, but in this setup, whether initially garrioned or not the rebels only built units in those four regions adjacent to rome at the start.

https://img69.imageshack.us/img69/359/strat13ok.th.jpg (https://img69.imageshack.us/my.php?image=strat13ok.jpg)

~~~

After the big diagonal glitch the next thing was the bridge to the mega region. Obviosly this is a silly and unrealistic map but the solution will maybe be relevant to people with a similar problem on a more sensible map.

https://img56.imageshack.us/img56/5295/stall67hv.th.jpg (https://img56.imageshack.us/my.php?image=stall67hv.jpg)

https://img153.imageshack.us/img153/319/stall74bp.th.jpg (https://img153.imageshack.us/my.php?image=stall74bp.jpg)

https://img56.imageshack.us/img56/1319/stall86zd.th.jpg (https://img56.imageshack.us/my.php?image=stall86zd.jpg)

Another (?) case of the problem when there is a 90 degree angle between starting settlement and target settlement (maybe). Either way what happened every test was the romans would send out an army to tribus sakae soon after they took the region with the bridge. It would reach the bridge but not cross and instead would move one tile south one turn then back up again to the tile just west of the bridge on the next and repeat indefinitely. I tried various things but the thing that worked is in image below. Basically you isolate the tile the stuck army moves to in a situation like this and put some impassable terrain on it. After this the romans would move to tribus sakae without a hitch.

https://img56.imageshack.us/img56/7750/stall95ud.th.jpg (https://img56.imageshack.us/my.php?image=stall95ud.jpg)

note: Once they'd taken the region roman stacks chasing rebels that spawned on that side of the river crossed the bridge with no problems. It seems to be only when the path is a 90 degree angle exactly. (I know this because for a while i just used the move_character command to get the tribus sakae stack over the river before i thought of using forest.)

~~~

Islands.

There were some other (more random) glitchs i'll come to in a bit but the next big thing was the islands. Once the roman ai had all the land regions it stopped. They never even built a ship. oddly though the britons ai (when i played the roman side to compare how fast i could get the land regions compared to the roman ai) would take the two islands but not invade the mainland. The original map was like this:

https://img153.imageshack.us/img153/8955/port32aj.th.jpg (https://img153.imageshack.us/my.php?image=port32aj.jpg)

I tried a lot of things but what worked was this:

https://img87.imageshack.us/img87/6856/port44bq.th.jpg (https://img87.imageshack.us/my.php?image=port44bq.jpg)

I have no idea why that little bump of land made the difference but it did. The britons would take the north island first then land on the mainland. Once on the mainland with adjacent land regions they didn't go for the second island until it was the last region left (had to move romans there temporarily to check this). Why the ai didn't go for the shortest distance region first is a mystery. I think the ai is a bit odd on the first turn sometimes.

The romans would take all the adjacent land regions first. Then the middle island closest to the bump, then north and finally south.

https://img88.imageshack.us/img88/4421/stall105po.th.jpg (https://img88.imageshack.us/my.php?image=stall105po.jpg)


Note: The romans only ever build ships in the port on the bump. Maybe the ai only builds ships in a region that can *see* a potential naval target region?


Semi-related topic. Before i temporarily gave up tinkering with the vanilla map i got the britons (starting with just one province on britain) to finally land on hibernia by moving the port location. They'd take rebel deva and Eburacum, then Hibernia, then finally when no reb targets left they'd invade the mainland.

https://img87.imageshack.us/img87/608/vanhibernia8ez.th.jpg (https://img87.imageshack.us/my.php?image=vanhibernia8ez.jpg)

This is just another example of how some regions just aren't *seen*, in some sense, by the ai but when you tweak the map in some way they suddenly become visiable. It seems to me that most of the naval invasion problems are caused by this. Although the ai always seems to prefer adjacent land regions under some circumstances they will mount a naval invasion but it still won't happen unless the map is right.

~~~

After this experience with my simple map i think the way to test your map (as a modder) is...

Make a dummy strat file with one faction on a remote island (or sealed off with a river) and a second faction with one decent-sized city (no population/unrest problems to confuse things) and leave all other settlements unspecified so they are all rebel villages with no garrisons.

Reduce brigands/pirates as much as possible ( i set it to 200 but still got a few)

Start your testing faction in different locations or start each faction one at a time in their capital region and watch it expand.

Spot the places where it gets stuck. (This will be easy with all rebel villages as the ai only sends one stack for each settlement.)

Work out how to fix where it gets stuck. Some places will only be a problem from certain directions so best to start the testing faction in various places.

You can test whether it can *see* naval landing targets by sealing off a set of regions with fordless rivers so that it quickly takes all the available land regions. If it doesn't mount a naval invasion after doing that it means it can't see an available target. Some islands may only be targets from certain regions and not others because of the layout. i am pretty sure now you can tweak the map to make the romans island hop from italy-sicily-carthage and italy-sardinia-palma-spain without any land bridges. Just a question of figuring out what the map glitch is for each step. The ai will still follow adjacent land regions if they're rebel or if they get in a war with a neighbour faction but if somehow the core-attitudes/relative strenghts are set right it seems likely that, at least sometimes, factions will expand more like players.

One way to test if the romans can path-find their way to carthage or spain would be to use this test strat file method but with a test version of your map with a fordless river between the romans and gauls. If the romans don't land on sicily/sardinia then you know their is a map problem. Once they get past that obstacle see if they find their way to the next stop etc.

~~~

There was a bunch of ai strategy related stuff i saw that i have forgotten now. No doubt it will show again when i finally get to test what i originally started which was how core attitudes affected things.

Anyway, apart from path-finding problems the ai has a number of other big disadvantages vis a vis the player.

1) Unrest. When i compared my speed (in game turns) with the romans the biggest difference was caused by how many rebellions they had. The ai doesn't destroy buildings so it couldn't reduce the culture penalty in the way i did (all the regions except rome and the four around it was faction creator britons) so it had lots of rebellions and had to take the settlement two or three times. Seems to me one way to even that handicap out would be if it was possible to mod a happiness bonus that only the ai got as most human players will very rarely get a rebellion. Not sure how though.

2) Brigands.

https://img53.imageshack.us/img53/1449/strat40ec.th.jpg (https://img53.imageshack.us/my.php?image=strat40ec.jpg)

https://img53.imageshack.us/img53/9186/strat37dl.th.jpg (https://img53.imageshack.us/my.php?image=strat37dl.jpg)

Basically, the ai stacks are always moving with a few exceptions (mostly cos they're stuck but a couple of other cases too). When they have no settlement target all spare stacks go chasing after rebels or enemy armies even if they are far away or if there are other closer stacks chasing the same guys. They even break off sieges sometimes to chase rebs on the other side of their empire. On the one hand brigands seem to be a major cause of the randomness in the game (which is good) but they handicap the ai a lot too. Dunno. Will compare the ai expansion on my simple map with brigands at a higher level and see how much it effects the time it takes for the romans to fill the map.

3) There seems to be another case where an ai stack gets stuck that doesn't seem to be map related. Normally when i saw an untaken region and a non-moving stack i could use the move_character command and then the stack would carry on to its target. Some stacks still wouldn't move after this. It seems random and will have to check it out more now the map glitchs seem to be fixed. i assumed it was due to losing battles with brigands but not sure now. Current theory is it *might* have something to do with names and epithets. We shall see.

Anyway, modding map path-finding, unrest and brigands will make the ai a lot more scary imo especially with the improved battle ai.


That was tiring.

Monkwarrior
04-20-2006, 08:22
Woh!
Impressive work.~:cheers:

Keep this thread alive and probably the campaign AI will be improved in many mods. :2thumbsup:

nikolai1962
04-20-2006, 09:45
Thanks :)

It is quite tedious in some ways but the end results could be worth the effort i think.

SigniferOne
04-20-2006, 15:38
Awesome stuff Nicolai, keep up the excellent job! Really impressive.

nikolai1962
04-21-2006, 06:21
Ty

~~~

One of the other places stalls happen semi-often because of how the simple map is set up is shown here.

https://img213.imageshack.us/img213/1917/stallsiegeloss17qn.th.jpg (https://img213.imageshack.us/my.php?image=stallsiegeloss17qn.jpg)

A stack seems to head off from Rome with Damme as its target while Ariminum is under siege. The stack sieging Ariminum assaults, loses and retreats but it fine. However the moving stack changes its orders and sieges the now open Ariminum. *If* that stack then later assaults and loses it will retreat to the spot shown in the image. If no-one else sieges Ariminum i think it just goes back (doesn't happen every time so hard to be sure) but if another stack takes over the siege then the original Damme stack goes back to trying to get to Damme from the retreated spot but stalls.

The second image (despite my poor graphical skills) is an attempt to show my theory of why it might stall here. If the game tries to path find by comparing the distance from target from the tile the stack is on to the distance from one of the tiles the stack could move to, and *if* the path is sort of sideways like it is here then the distance will only be reduced a tiny amount. Maybe there is some kind of rounding error that makes the distances equal so the stack can't find a tile to move to that reduces the distance?

Path-finding will be hard-coded so doesn't really matter much why it happens but anyway :)

https://img213.imageshack.us/img213/724/stallsiegeloss26gr.th.jpg (https://img213.imageshack.us/my.php?image=stallsiegeloss26gr.jpg)

So anytime an ai stack has a target settlement but breaks off on the way to fight a battle or take over a siege it then has to find a new path to its original target. This is probably what i noticed before while watching the vanilla map. Only occcasionally would an ai stack seem to stall after fighting a battle. The ones that were on rebel/enemy chasing duty are generally fine but the ones that have a specific target can occasionally be messed up. On a normal map there may be other things happen that clear the stall but i'm sure in some situations it causes the faction to stall as it does with this map. Damme is targeted but unreachable by the stack ordered to take it so the ai doesn't send another stack.

Third image was meant to be something else but just shows my current attempt to get past this by making the blocking terrain more rounded with woods instead of forest at the corners.

https://img519.imageshack.us/img519/5550/stallsiegeloss32lg.th.jpg (https://img519.imageshack.us/my.php?image=stallsiegeloss32lg.jpg)

I think i saw this happen on the vanilla map when ai stacks lost an assault against halicarnasus and retreated east but hard to be sure as so many thinhs happening at once on a normal map. Now i know what to look for when i go back to it maybe it will be easier.

This "retreat" stall (happens mostly with long retreats) is the biggest cause of the ai getting stuck once the general path-finding problems between settlements are fixed.

The preceding image was meant to show the other semi-regular type of stall that happens. I have no real idea what causes this one. Here a stack moves out of a city to the "sentry" position. Usually the stack then either moves off next turn or waits while it gets more units from the city but in some cases they just stall. If you use move_character the stacks goes off to a target settlement (didn't work here as there were two Captain Aulus) which seems to imply that stack was given a target settlement to attack and it is a path-finding bug again but it happens when there is almost a straight line to the target (Damme again in this case).

Maybe it is waiting for a unit from the city but the city is too far down the queue for unit-building so it never gets built? Dunno.

There's a 3rd type that happens too inconsistently to have much clue what causes it. In that case the stack doesn't seem to have a target settlement it just stalls. move_character doesn't unstick armies like this. Only current theory is that it is somehow caused by man-of the-hour events as the ai gets a ton of those with all its captain-led armies? These don't stall the faction though as the stacks don't seem to have a target settlement.

Next step is to add more rebel garrisons so the ai loses more sieges so i can see a consistent way to fix the "retreat" stall and then go back to the other two afterwards.

~~~

Brigands

Image shows what happens on first turn when you have brigand spawn rate set to zero :)

https://img519.imageshack.us/img519/3967/brig11we.th.jpg (https://img519.imageshack.us/my.php?image=brig11we.jpg)

Ai never expands more than one region with that many brigands. Obviously this is an extreme case though.

As the brigands are so random you'd need to test a lot of times to be sure and i only did it three times with brigands set to 28 and 99. The roman ai fills the land part of the map a bit faster with brigands on 99 but not as much as i thought. That makes unrest move up to the 2nd spot after path-finding as the biggest AI handicap (imo).

Playing on other maps I got the feeling there were more brigands with the same setting but higher difficulty levels but watching this smaller, simpler map that doesn't seem to be true so the extra cash the ai gets on hard and very hard makes it fill the map slightly faster too. (i'm guessing that is the reason.) So i think hard and very hard counter-balances the brigand handicap (on this map).

As the ai consistently only uses one ship to transport their armies, and pirate fleets can be so strong, the speed of getting the islands varies massively. I gave up on that and only tested the land expansion speed. AI naval expansion needs less or weaker pirates imo because the AI doesn't build proper fleets often enough.

~~~

I think CA needs to move to hexagons :)

nikolai1962
04-21-2006, 08:17
Monkwarrior,

I started looking at the carth-roman thing on the vanilla map before i got side-tracked onto my simple one. There were a bunch of things i thought needed to be done to the map to make it work right (from the carth side) which i'll point out here. Your map is probably different but it may have some of the same problems. I only changed the first one (sahara) as i didn't know how to edit the other map files then.

1) The AI prioritizes adjacent land regions. For carth this means they spend a lot of time in the desert both south and east and especially if they get into a war with egypt, which they nearly always do. This is a big waste of time imo and stops carthage ever seeming like the regional superpower it is supposed to be. My solution as shown in the image was to make a huge sahara that touched the sea so it was the border region with egypt. Siwa and nepte were too far away from each other for egypt and carthage to ever fight whereas nepte was close to the coastal regions so carthage could take it without a long trak into the desert. I also made nepte low population/fertility and made desert regions (hidden-resource) unable to build lots of pop growth stuff like farm upgrades. This meant it wouldn't keep rebelling, as that was another distraction for the carthage ai.

https://img83.imageshack.us/img83/7332/carth28ka.th.jpg (https://img83.imageshack.us/my.php?image=carth28ka.jpg)

With the carthage ai undistracted to the east and south all it needs to do to become land-locked and therefore naval-orientated is to finish expanding west along the coast.


On the vanilla map it seemed the cartage ai sometimes (not always) had a problem getting to Tingi. The bends in the road shown in the second image are the reason (i think).

https://img381.imageshack.us/img381/5628/carth31cx.th.jpg (https://img381.imageshack.us/my.php?image=carth31cx.jpg)

I added a region between Tingi and Cirta because at first i thought it was a distance problem but it still happened some of the time so now i think it is a path-finding glitch related to bends. You need Carthage to take Tingi as Tingi-Corduba works as a naval expansion path to Iberia. I know now that moving Tingi, that ford to the east or something else should clear the path-finding glitch and let carthage target Tingi properly every game without stalling

With Tingi taken, and the huge sahara blocking expansion eastwards, Carthage becomes a naval expansion faction (ignore sicily for a minute). Its closest naval expansion target is Iberia and so once these things are done Carthage should always fight hard to expand in iberia.

There is another map glitch here though. When carthage has been pushed out of iberia and is re-invading from Tingi they sometimes land near where i placed the carthage army in the picture. These stacks sometimes seemed to get stalled. After my tinkering with the simple map I'd bet it is because of those mountains between the landing zone and corduba.

So I'd say to make carthage act like carthage on any map you'd need:

1) A huge sahara (or something) blocking egypt and carthage
2) Smaller/closer desert regions to let carthage take them without long slow journeys.
3) Make sure those inland desert regions don't rebel too much by fixing the pop growth.
4) Make sure there is clear path-finding along the coast.
5) Make sure there is clear path-finding between the African and Iberian regions that are closest together.

Lastly i saw a glitch on Siclily once where carthage had lilybeum and syracuse and got stalled moving to messana. I think it is the bendy road shown in picture below.

https://img83.imageshack.us/img83/3849/carth13ug.th.jpg (https://img83.imageshack.us/my.php?image=carth13ug.jpg)

When i get back to tinkering with the vanilla map i think i'll make sicily more triangle shaped with the mountains in the centre so there are three straight-ish roads between lillybeum-syracuse, lilybeum-messana and messana-syracuse. I think this will make sure the ai doesn't glitch here.

Apart from making messana-italy have a clear naval expansion path (or a land-bridge) i think fixing these things (or the equivalent on other maps) will make the carthage ai much better.

I think it will be much trickier to get the roman ai acting like historical romans though.

Duke John
04-21-2006, 09:33
Good stuff!

Months ago I also looked at the strategic AI and particularly at how it didn't merge its armies. I found that a small amount of movement points was bad as it meant that an army could not reach its target friendly army. Increasing the movement points greatly reduced the amount of armies as the AI armies could reach each other within a single turn. I would advise to give AI character a standard increase in MP by the use traits.

There is also the problem of armies not merging when the total of 2 armies is greater than 20. So complete stacks are rare.

All of this was tested on 1.2 so things might have changed.

nikolai,
have you tested wether lots of movement points (MP) decreases pathfinding problems? If so you might want to test giving AI characters a movement bonus trait when they have not used any MP for a few turns and are not in a settlement; they are stuck. The sudden increase in MP might open a different path.

Monkwarrior
04-21-2006, 12:29
Hi again.

Fortunately we are working in complementary aspects of the AI, so I think we will advance faster sharing our experiences.

This post is to illustrate the findings reported before.

1- Behavior of a superfaction (different from the senate)

In this experiment, julii were superfaction of other factions, such as greek_cities and this is the result.
https://img161.imageshack.us/img161/8883/cobardes6sv.th.jpg (https://img161.imageshack.us/my.php?image=cobardes6sv.jpg)

I had never seen so large concentration of armies, and julii were unable to attack the gauls on the north. Their only expansion was Liguria, that started as rebel region.

In the next experiments we changed the system, and dacia (cisalpine gauls) were the superfaction of julii. In this way the romans have no room for expansion by land, and they are more prone to sail.

2- The need for a strong motivation

As I said before, the presence of a roman fort with a full stack army was completely useless to attract the romans to Iberia.
But we tried to make the same giving the romans a single settlement in Iberia.
In that case, romans are able to send troops by sea.
https://img149.imageshack.us/img149/5355/desembarco14qp.th.jpg (https://img149.imageshack.us/my.php?image=desembarco14qp.jpg)

Then, the romans begin a war against the surrounding faction (illergetes), which is at the same time the creator and the culture tag of that region.
This is complemented with expeditions by land, as some roman army was able to cross the gauls territory, including the Alps, without attacking or being attacked, just to arrive to Iberia to fight against the illergetes.

3- The expansion

Once that faction has disappeared, romans turn south, to the zone controlled by carthaginians (probably due to path finding questions), and they meet in Saguntum (as it happened historically).
https://img162.imageshack.us/img162/5089/guerraefectiva8ld.th.jpg (https://img162.imageshack.us/my.php?image=guerraefectiva8ld.jpg)

However, the expansion of turdetani (white) was too far, in comparison with the historical behavior. They are included as allies of the carthaginians, and limit their expansion to the coast (which is also correct).

In the last experiment (for the moment), the turdetani were considered as the superfactions of carthaginians. The starting position served as shield against lusitanians, and at the same time drove the carthaginian expansion to the coast.
The result was nearly the same, but with the limitation in the turdetani expansion.
https://img213.imageshack.us/img213/3439/pruebapunica54fg.th.jpg (https://img213.imageshack.us/my.php?image=pruebapunica54fg.jpg)

In some days, I will post the new experiments with superfactions, alliances and "motivations".

@Duke John
In those experiments MP are 95, but they are increased by large amounts for admirals, spies, diplomats and generals through traits.
I knew some days ago that the limit of 100 is no more working in RTW 1.5, and I will try with higher MP also for captains, just to see if there is any difference.

Cheers.

Coldfish
04-21-2006, 12:56
Impresive Work ! nikolai1962

I think you need an award for all your help given here on these forums:2thumbsup:

Can you upload that mod please ? I like it alot !! especially the removing of the britons from the mainland...and Sahara as a single region

Again.NICE WORK

p.s. What are the Thracians doing in the Alps mate ? ~:) But I'm guessing that Is just a temporary "training" map

nikolai1962
04-21-2006, 19:09
Good stuff!

Months ago I also looked at the strategic AI and particularly at how it didn't merge its armies. I found that a small amount of movement points was bad as it meant that an army could not reach its target friendly army. Increasing the movement points greatly reduced the amount of armies as the AI armies could reach each other within a single turn. I would advise to give AI character a standard increase in MP by the use traits.

There is also the problem of armies not merging when the total of 2 armies is greater than 20. So complete stacks are rare.

All of this was tested on 1.2 so things might have changed.

nikolai,
have you tested wether lots of movement points (MP) decreases pathfinding problems? If so you might want to test giving AI characters a movement bonus trait when they have not used any MP for a few turns and are not in a settlement; they are stuck. The sudden increase in MP might open a different path.

That sounds like a good idea :)

nikolai1962
04-21-2006, 19:22
Monkwarrior,

Using superfactions is definitely something i wouldn't have thought of. Seems likely it could work well in the right circumstances.

The AI always seems to prioritize adjacent land regions so it is hard to make it go to sea. One thing i tried once was make a saguntum equivalent town in iberia have romans as the faction creator so it sometimes rebelled to the romans. I want them to sail there though :)

The other thing you could try to control expansion is tweak the regions to make sure the closest one is the one is in the direction you want the AI to move or have a starting army on the border of where you want them to move. Once they are at war with someone they will follow that route mostly so if there was historically a coastal tribe and you made them closest to the carthies then that might work out. Doesn't help with the romans though.


edit: looking at your images again i'd say the first one would work best if the map was tweaked so rome could path-find to sardinia/corsica then on to palma then spain. I'm sure that is possible after my experiments. Big problem (apart from finding which tweak worked) would be making it so they saw palma but not carthage itself as carthage is closer.


I couldn't resist trying out the idea of a stripped down strat file on the vanilla map to test path-finding for carthage. I'll post the results once I've uploaded all the images. Some of it may be useful.

nikolai1962
04-21-2006, 19:26
Impresive Work ! nikolai1962

I think you need an award for all your help given here on these forums:2thumbsup:

Can you upload that mod please ? I like it alot !! especially the removing of the britons from the mainland...and Sahara as a single region

Again.NICE WORK

p.s. What are the Thracians doing in the Alps mate ? ~:) But I'm guessing that Is just a temporary "training" map

Ty. The map files are in a permanent state of experimenting at the moment but if i ever get all the pathing right i'll probably upload for sure :)

Lol, the thracians are being the arverni as i was originally trying out variations for extending the government idea in EB so i'd started to make the factions match the EB ones. As i was testing with FOW off instead of playing i started to notice all this weird AI stuff.

Deep breath, long post coming up.

Coldfish
04-21-2006, 21:21
I see..well thanks! I can't wait:2thumbsup:

nikolai1962
04-21-2006, 21:56
After getting the idea of a stripped down strat file to test path-finding i had to try it out on the vanilla map.

Made a provincial campaign.
Removed senate, scipii, brutii and numidia (as i was going to look at carthage path-finding first).
Gave each faction their original capital as their only settlement, same size, buildings etc.
Starting leader with thier cavalry as only army.
Brigands and pirates set to 99.
10 happiness bonus on governor buildings to stop distractions caused by rebellions.
Resources, landmarks, diplomatic attitudes etc all gone.

Might be a better way to set this up to test the path-finding but the above was what i tried this time.

Only changes i made to the base map at first were extending sahara to the west and moving the briton port as i'd sort of tested them before.

The result was this.

https://img106.imageshack.us/img106/7171/vantest11ab.th.jpg (https://img106.imageshack.us/my.php?image=vantest11ab.jpg)

Running it for just a few turns you start to see some places that probably have problems straight away.

https://img106.imageshack.us/img106/2064/vantest21qs.th.jpg (https://img106.imageshack.us/my.php?image=vantest21qs.jpg)

The AI likes to go for the closest adjacent land target (modified by garrison, owner etc) which should have meant Chersonesus, Bordesholm and one of the two near the armenian capital would have gone pretty quick but they didn't. This was a consistent thing when i ran the first few turns a few times. The armenians always went south to hatra. The germans never found their way to bordesholm from south or west, only from the east. Chersonesus is generally messed up from all directions.

https://img71.imageshack.us/img71/4195/vantest30ub.th.jpg (https://img71.imageshack.us/my.php?image=vantest30ub.jpg)

I'll go back to them another time as this was mostly about carthage.

The carthage AI starts fine, build a small army, sends it to nearest target (Thapsus), takes it. That army leaves a garrison behind and heads for next nearest (not neccessarily nearest to thapsus). Depending on how i'd changed the map over the course of this testing it either went to lepcis or Cirta. Meanwhile carthage has build a second army that goes to whichever of lepcis or cirta hasn't been targeted by the first. After those first 4 are taken it all goes wrong.

The pathing from carthage to dimmidi and nepte goes a very weird way round with stacks getting lost on the way.

https://img106.imageshack.us/img106/7161/vantest44ej.th.jpg (https://img106.imageshack.us/my.php?image=vantest44ej.jpg)

(nb those two carth stacks had been stuck there since near the beginning.)

All the time it takes is time the iberians have (in the normal game) to kick carthage out of iberia. Some stacks seem to get lost during this journey too and end up wandering around lepcis permanently. They get constantly re-inforced from lepcis but do nothing. Ai stacks are nearly always doing something unless they or the faction is stuck in some way. If they're not moving or if they're moving back and forth in a repeating loop then they are usually messed up. Not always but if you watch it enough you learn to see when it isn't so.

When the small starting stacks finally reach dimmidi they assault and lose a lot and bounce off. Most of them seem to not be able to find their path back anywhere so when dimmidi is finally taken they sit around dimmidi getting re-inforced from there and the stacks will get bigger but don't do anything. They'll attack nearby rebels but won't chase them if they are outside the dimmidi region.

https://img407.imageshack.us/img407/2492/vantest59gp.th.jpg (https://img407.imageshack.us/my.php?image=vantest59gp.jpg)

This shows the same thing but earlier before the stacks got huge but i drew pretty lines on it so i uploaded it anyway.

https://img407.imageshack.us/img407/6018/vantest65eb.th.jpg (https://img407.imageshack.us/my.php?image=vantest65eb.jpg)


Not all of this will apply to the normal game, though the pathing to dimmidi and nepte will be, in the normal setup the ai may send bigger initial stacks and so end up with less lost ones. Really meant as an illustration of how the path-finding can be so critical to the ai, especially compared to a human player who has zero path-finding problems unless they're playing with their eyes shut.

This was all too painful to watch and also i found out the distance from siwa to nepte didn't stop the egyptians targeting it when it was still rebel, only if the carthies had it. Which they didn't as they kept getting lost.

So time to mess with the map :)

(I wasnt going for realism or aesthetics here just trying to see if simple map changes would make the ai perform to its best (which i actually think could be pretty scary with path-finding fixed)

So i lost gaetulia/dimmidi and extended the sahara over their old terriotory and moved nepte close to cirta hoping the ai would target it from there and not go the long way round. Also moved cirta/thapsus a bit to smooth out bendy roads, moved a ford etc, added some hills to push roads in certain directions to make them more rounded with less sharp bends etc. All of this is trial and error and often makes things worse but eventually it works.

https://img486.imageshack.us/img486/931/vantest75ce.th.jpg (https://img486.imageshack.us/my.php?image=vantest75ce.jpg)

https://img407.imageshack.us/img407/4199/vantest86xa.th.jpg (https://img407.imageshack.us/my.php?image=vantest86xa.jpg)

Once this worked the land expansion went smoothly. A human player would still do it faster but not by as big a margin (imo)

As you can see on the minimap of one of those they then landed on sardinia.

Note. It seems that the ai doesn't build ships unless one of its regions can see a naval expansion target. It also doesn't seem to build them *until* it needs a new expansion target. None of the ai factions who weren't land-blocked (sort of) built a ship apart from the iberians who built one and landed a small army by tingi during a brief cease-fire. The ceasefire broke soon after and they never built another. They may not actually land an army but they never built a ship unless they had a target for a moment when they were temporarily blocked.

Carthage can *see* sardinia and built a ship and off they went. One of the images also shows one of the times the ai will have a lot of stacks hanging around. I thought it was because they were stuck because of either path-finding round that mountain (as the ai will move stacks to the capital when they have nothing to do) or the carthage ai couldn't see another naval expansion target and were therefore stalled.

https://img481.imageshack.us/img481/4881/vantest99vh.th.jpg (https://img481.imageshack.us/my.php?image=vantest99vh.jpg)

What it actually was was them waiting for a ship. An odd place to wait admittedly (probably because of my mountains, might be better to have a path through them to thapsus). The holdup was the ****ing pirate fleets. Carthage would build a ship every turn and move it to its "waiting for an army" spot and they'd be constantly wiped out or retreated by the swarms of pirates. Again, the pirates wouldn't have been such a big problem if all the factions had their starting fleets but it still shows how important they are at messing up the ai naval expansion. This stage of the testing got too annoying as 10-20 turns went by before carthage managed to get a ship off to next target. The pirates get too strong even set at 99 because the ai uses small fleets and loses a lot.

I went and changed the EDU so carth ships started out as exp 9 but even then it took a while before they cleared a space (mainly because carthage got big enough to build the bigger ships i think). AI naval expansion needs weaker pirates badly imo. Setting the chance to 100 in the rebel_factions file seemed to help a bit (deleting the pirates section causes a ctd).

Anyway all the changes gradually made the pirates less of a barrier and i could see where carthage would go next.

Carthage was the only place yet with a port so it would only be places Carthage could *see*. (A large part of this was to see which regions could be seen as a naval expansion target from different places.)

https://img481.imageshack.us/img481/9070/vantest101xm.th.jpg (https://img481.imageshack.us/my.php?image=vantest101xm.jpg)

So Carthage can see Lilybeum and Caralis and sees Caralis as closest (i am assuming that is why they went there first as caralis had a full rebel stack).
They only go by see when they are blocked on land in some way but at least the routes are there. Oh yes, i put a fordless river between egypt and carthage for this just in case the far north-western nepte wasn't enough to keep the peace with this odd strat file setup. I was only interested in what path-finding glitchs would make carthage the pushover it usually is.

Once on sicily they have adjacent land regions so that is it for naval expansion until sicily is taken (or in a normal game if they were at peace with another faction on sicily). The path to syracuse was no problem.

https://img481.imageshack.us/img481/7311/vantest113ju.th.jpg (https://img481.imageshack.us/my.php?image=vantest113ju.jpg)

(notice on minimap the regions the ai factions are having problems finding. no-one ever finds tribus sakae it seems. I wasn't watching those areas as i clicked end turn but if those regions are targeted but the attacking stacks are lost/stuck the whole faction might be stalled.)

After this is all went wrong again.

https://img481.imageshack.us/img481/4939/vantest124hd.th.jpg (https://img481.imageshack.us/my.php?image=vantest124hd.jpg)

The army that took syracuse attacked and lost the battle for messana. Syracuse-messana can see each other and lilybeum-syracuse can see each other (when i say see i mean find the path) but lilybeum-messana can't, so once the first army retreated that was it for the carthage ai. If this was the normal vanilla game and carthage had been pushed out of sicily and spain because it was lost in the desert, and then made a come-back this is where the faction would stall again.

This was painful to watch too but i did for a bit and it was quite funny in the end. The carthage ai kept sending re-inforcements by ship. The re-inforcements were just as stuck as the others. They landed more stacks and began to fill up all the available coast tiles. Bit by bit they got closer and closer to messana as new stacks were landed and bumped previous ones up the road. Finally they hit the jackpot and a bumped stack got round a bend or something and sieged messana. (going by the date on the images i think that took the AI about 40 turns.)

https://img518.imageshack.us/img518/6882/vantest130bl.th.jpg (https://img518.imageshack.us/my.php?image=vantest130bl.jpg)

Made me laugh anyway.

Short-lived though as they lost and retreated back to syracuse and stalled too.

Pointless image but i added it anyway. I tried to move a bunch of them next to messana but only one of those stacks (maybe more) is the prime attacker. The rest are supporters and back up if attack fails so i needed to guess which was the right one. Gave up after three.

https://img181.imageshack.us/img181/6282/vantest147tm.th.jpg (https://img181.imageshack.us/my.php?image=vantest147tm.jpg)

Sicily needs to be fixed for the ai to work. I think given the shape any small scale sicily needs to be triangular with the cities at the apexs(?) and straight-ish roads between the cities. I slapped a lot of mountains down in the middle and made the edges of the islands have at least two pixels of clear land for the road to go down.

Not very pretty but would it work?

https://img172.imageshack.us/img172/6979/vantest151ot.th.jpg (https://img172.imageshack.us/my.php?image=vantest151ot.jpg)

No was the short answer. Needs to be tinkered with more but better to do that with a strat file set up with carth (or another faction) just on sicily so you can change the map and test it straight away. My current one sort of works in that carth now sees messana from lilybeum but i messed up their path to syracuse. But as messana sees syracuse as i hadn't changed that side of the map and as the carth armies are coming from lilybeum they don't get stuck as they go to syracuse via messana. So that was good enough for now to carry on testing the carth stuff.

https://img171.imageshack.us/img171/8059/vantest166fi.th.jpg (https://img171.imageshack.us/my.php?image=vantest166fi.jpg)

None of the cities on sicily can see italy and vice versa (though i intend to try and make messana and croton see each other eventually) so no more landings here. If there was a land-bridge carthage would now start going into italy (i prefer the naval option though when it can be made possible). So next stop palma.

https://img172.imageshack.us/img172/4186/vantest176yh.th.jpg (https://img172.imageshack.us/my.php?image=vantest176yh.jpg)

I wasn't paying attention here and didn't see where the ship was built that took this army to palma (that is the region that can *see* it). I *think* it was caralis as there was a port there now and i've seen the vanilla julii jump to palma as long as the senate had already got them to sardinia. Will check sometime by starting carthage on sardinia.

Then it stalled for a bit. Not sure if that means they had no more naval expansion targets from theor current position or if they iberia was already picked and they were waiting for tingi to finish its port. Either way an army moved up to tingi and waited. A few turns later the port was done. Next turn a ship appeared. Then off to spain.

https://img172.imageshack.us/img172/6348/vantest180ha.th.jpg (https://img172.imageshack.us/my.php?image=vantest180ha.jpg)

With no desert distractions the ai was doing a good job focusing its forces.

https://img507.imageshack.us/img507/2905/vantest194xe.th.jpg (https://img507.imageshack.us/my.php?image=vantest194xe.jpg)

Then it all went wrong. Not at all surprising now i look at iberia after tinkering with the path-finding. I think it happened when a carth stack lost a siege against numantia and retreated behind a mountain. There were too many roman and carth stacks moving and fighting to spot the glitch but whatever it was the faction stalled and it stopped sending armies to iberia.

https://img507.imageshack.us/img507/6861/vantest209zi.th.jpg (https://img507.imageshack.us/my.php?image=vantest209zi.jpg)

(This is an exception to the rule about capitals. The ai only congregates around its capital when it has no targets.)

I gave up here as testing the path-finding in iberia is going to take a while and it will be better done by starting carthage in corduba without any other factions so it is easier to seperate the general map glitchs from battle glitchs.

As an indication of how messed up the ai can get in iberia:

https://img176.imageshack.us/img176/9318/vantest237fc.th.jpg (https://img176.imageshack.us/my.php?image=vantest237fc.jpg)

All but one of those (8 or 9) roman stacks are stuck (including the garrison in scallabis). The romans can't find the way to the last carth city and the carth garrison there is stuck too. The whole faction wasn't stuck because it had got big enough to have multiple targets which included ones in the east of their empire. A quick scan of the map showed that was about half the roman army.


Couple of other things i saw before closing down.

https://img507.imageshack.us/img507/7624/vantest216so.th.jpg (https://img507.imageshack.us/my.php?image=vantest216so.jpg)

https://img507.imageshack.us/img507/4361/vantest225xp.th.jpg (https://img507.imageshack.us/my.php?image=vantest225xp.jpg)


~~~

Anyway i think this all shows.

1) The AI factions are massively handicapped by path-finding problems which can be found and fixed.
2) Naval invasions work fine but only in certain specific directions which need to be found by testing (and only when the faction is land-blocked physically or by alliances).
3) This is quite a good way of testing the path-finding (though probably much improvable).
4) I like linking images a bit too much :)

Coldfish
04-21-2006, 22:58
Impressive work!

offtopic: nikolai1962 I tryed to change the ownership of Samarbrovia from Britons To the Gauls I cut/paste the settlement from britons to the gauls...I moved the briton general to the gauls also I changed the coordonates x y with one or two ...I changed the unit type in the specific galic unit...deleted the map.rwm
added -show_err to the shorcut rtw tab...and STILL KICK TO MENU!...the error says that Belenus (the moved general) is to old to be a parent 36<30:inquisitive:

I think has something to do with the families...must be relatives or something:help:
Can you please try it yourself if you want ? maybe you will succeed and if so...please post it here or upload the file :bow:

p.s. some pics are funny ~:)

shaggy1973
04-22-2006, 01:47
wow who would have thought that beinds in roads could mess the ai up :(

i think there is now a need for more functionaly maps rather than 100% historical maps. any trick to make the roads straight (like lakes, mountains) will surely make the game more enjoyable

nikolai1962
04-22-2006, 02:08
offtopic: nikolai1962 I tryed to change the ownership of Samarbrovia from Britons To the Gauls I cut/paste the settlement from britons to the gauls...I moved the briton general to the gauls also I changed the coordonates x y with one or two ...I changed the unit type in the specific galic unit...deleted the map.rwm
added -show_err to the shorcut rtw tab...and STILL KICK TO MENU!...the error says that Belenus (the moved general) is to old to be a parent 36<30:inquisitive:

I think has something to do with the families...must be relatives or something:help:
Can you please try it yourself if you want ? maybe you will succeed and if so...please post it here or upload the file :bow:

p.s. some pics are funny ~:)

The steps are

1) Copy the settlement for belgica to the gauls
2) delete captain caradog and his army
3) move belenus to the island. I moved him above Londinium (IIRC) which was x 55, y 132

Everything should work then. There won't be a starting gaul garrison but they'll build a unit there.

(Though personally when i play for enjoyment rather than testing out modding stuff i play EB or RTR. vanilla 1.5 is way better as a game than 1.2 but i miss the historical feel of those other mods after a while)

I hope this is helpful enough. Problem I have is nearly every Rome folder on my machine (apart from EB and RTR) is messed up in some way through trying out different stuff. I don't even remember what half the RTW icons are for.

nikolai1962
04-22-2006, 02:18
wow who would have thought that beinds in roads could mess the ai up :(

Its only really sharp bends and in a way it isn't even the roads themselves. What it is is that the roads show you how the underlying terrain makes the ai decide to move because the path of the road will (mostly) be the path of least movement cost. The ai will still glitch moving over the same terrain without a road. But if you can get the roads between settlements gradually curving with no sharp bends and no cutting back on itself then the ai will glitch much less.



i think there is now a need for more functionaly maps rather than 100% historical maps. any trick to make the roads straight (like lakes, mountains) will surely make the game more enjoyable

I think the game ai will never be as good as it could be unless map makers find and fix these glitchs. Someone with a lot of patience could make a glitch free and accurate map probably. Just take a lot of tiny terrain changes, testing and patience. (I think)

Coldfish
04-22-2006, 05:58
IT WORKED !! A HEARTY THANK TO YOU nikolai1962

I hope those britons will not invade the mainland:laugh4:

alpaca
04-23-2006, 10:36
Very interesting thread, you made some fine observations that'll surely help us make the AI at least do a bit better ;)
I thought a bit about some of the things you mention about stalling and I have a theory that the AI decides to issue movement orders on a stack-per-stack tile-per-tile method which means it seeks a target for a stack and then only moves the stack to a tile if this tile decreases the (euclidian) distance to the target to the next integer (rounded).
This would explain your example where the stacks got stalled after an unsuccessful siege south of the forest (distance would be 7, if the stack moved right, still 7)
It would also explain the problem with 90 degree bends in roads that lead in a straight line to the target after the bend because the distance (in integers) wouldn't become smaller and they can't move diagonally because it'd take more movement points thus increasing the distance again.

nikolai1962
04-23-2006, 14:57
Very interesting thread, you made some fine observations that'll surely help us make the AI at least do a bit better ;)
I thought a bit about some of the things you mention about stalling and I have a theory that the AI decides to issue movement orders on a stack-per-stack tile-per-tile method which means it seeks a target for a stack and then only moves the stack to a tile if this tile decreases the (euclidian) distance to the target to the next integer (rounded).
This would explain your example where the stacks got stalled after an unsuccessful siege south of the forest (distance would be 7, if the stack moved right, still 7)
It would also explain the problem with 90 degree bends in roads that lead in a straight line to the target after the bend because the distance (in integers) wouldn't become smaller and they can't move diagonally because it'd take more movement points thus increasing the distance again.


My thoughts exactly :)

A move might make them go from say 60 pixels away from their target (in a straight line tile-centre to tile-centre) to 59.6 which gets rounded up to 60 therefore they don't move as (to them) they are not moving closer. *If* the distance is calculated on a pixel basis then you could expect to see less path-finding glitchs with higher screen resolutions (i think). It would also explain why armies moving to chersonesus from the east end up on that little bump of land that is closest to the target in a straight line.

I'm pretty sure that is what is happening. The tweaks i am making to the vanilla map are being based now on trying to make a path between the settlements of adjacent regions where each tile moved decreases the straight line distance. It is proving quite tricky to get it to work in all cases from all adjacent directions though.

nikolai1962
04-23-2006, 14:59
IT WORKED !! A HEARTY THANK TO YOU nikolai1962

I hope those britons will not invade the mainland:laugh4:

Good :)

nikolai1962
04-23-2006, 15:33
Some general things

1) Happy AI

This is what Iberia should look like after a faction has conquered it all and moved on.

https://img76.imageshack.us/img76/2694/goodiberia4ov.th.jpg (https://img76.imageshack.us/my.php?image=goodiberia4ov.jpg)

Minimal garrisons (which is why they need help with unrest imo) and no stationary stacks hanging round. They have close adjacent land regions on the other side of their empire so all their armies head there. Might see a stack chasing rebels but that should be it.

General how AI should look away from war zone pics:

https://img198.imageshack.us/img198/2326/peace14jj.th.jpg (https://img198.imageshack.us/my.php?image=peace14jj.jpg)

https://img76.imageshack.us/img76/9362/peace21ns.th.jpg (https://img76.imageshack.us/my.php?image=peace21ns.jpg)


2) Stationary stacks

As mentioned before the AI stacks shouldn't be stationary except under limited conditions.

a) No targets/rebels so hanging round capital region
b) Waiting for a ship mode
c) Sentry position outside city waiting for extra units (sometimes bugged i think. hard to be sure)

Another exception is guard mode.

When a faction neighbours another who they are at peace with they often move stacks to what i am calling guard positions which are spots on the LMC path on the border of the adjacent region. They can sit in these spots or move between different ones while the ceasefire lasts. Some examples in the images where Rome had made Iberia a protectorate and the carths didn't want to attack.

https://img198.imageshack.us/img198/246/guard18qz.th.jpg (https://img198.imageshack.us/my.php?image=guard18qz.jpg)

https://img76.imageshack.us/img76/8312/guard21xe.th.jpg (https://img76.imageshack.us/my.php?image=guard21xe.jpg)

3) Unusual stall

This is sort of related to path-finding.

Carthage was fighting the gauls for Iberia. They'd been pushed out but were sending stacks west and shipping them over fine to continue the war. Sicily had the normal AI minimal garrisons but was otherwise empty. The gauls were also fighting the romans for Italy. When the gauls finished the romans off by taking croton the carth AI seemed to switch priorities to Italy because they were already at war with the gauls from spain. Unfortunately there is noi naval landing path (yet) between Croton and Messana so what happened was this:

https://img76.imageshack.us/img76/3715/oddstall11rm.th.jpg (https://img76.imageshack.us/my.php?image=oddstall11rm.jpg)

This would actually be pretty cool AI if there was a path tween italy and sicily. But on the vanilla map it basically made carthage stall as the ever-increasing armies on sicily couldn't get to croton which reduced the armies they were sending to iberia. Also even when the stalemate battle in iberia was broken temporarily by a carth victory the stacks in iberia didn't attack corduba. They'd land and fight endless battles with gaul reinforcements but not advance beyond the coast.


https://img198.imageshack.us/img198/1972/oddstall24cg.th.jpg (https://img198.imageshack.us/my.php?image=oddstall24cg.jpg)

I saw this once before and thought it was path-finding problem caused by the mountain but i now think it was this same situation caused by wanting to attack italy but not being able to.

Just another way for carthage to stall :(

be good to see them land on italy when i eventually work out how to make messana-croton see each other.


4) Name bug?

This is weird. Not even sure if it is a bug but i think it must be.

AI builds units, sends them to sentry position in readiness to attack somewhere.

https://img76.imageshack.us/img76/1153/namebug12ml.th.jpg (https://img76.imageshack.us/my.php?image=namebug12ml.jpg)

Some times (often in my setup with only one family member) the captain in command gets promoted.

https://img76.imageshack.us/img76/4091/namebug28tj.th.jpg (https://img76.imageshack.us/my.php?image=namebug28tj.jpg)

Then what happens is, nothing. They just sit there. It seems different from the stall where a target settlement keeps building new units as these stacks don't get a new unit every turn, just now and then. There is definitely at least a bug with the move_character command in these situations:

https://img86.imageshack.us/img86/7162/namebug38yo.th.jpg (https://img86.imageshack.us/my.php?image=namebug38yo.jpg)

but that doesn't neccessarily mean it is a bug overall?

It was very erratic with the romans but happens all the time with barbs. The reason i think it may be a bug is the surname-less scythians don't seem to have this problem at all. The only difference i can see with the (non-scythian) barbs vs romans is the multi-part surnames "of arvernum", "the turdetani" etc.

Will need more investigation to narrow it down. Weird though.

Teleklos Archelaou
04-23-2006, 16:10
Very interesting work indeed nikolai! And a big benefit to the community also.

nikolai1962
04-23-2006, 16:21
Ty. It is my current obsession :)

Question: When you have gaul path-finding set up so that starting in Alesia the gaul ai can very rapidly take all its core regions. Then if you're a bit bored and start slapping woods round the place for fun. Could that possibly completely and totally screw the gaul path-finding?

Answer: Yes

:wall:

alpaca
04-23-2006, 17:05
About this name stuff: Maybe this bug causes the game not to update its internal name and the character is still called just Bingen
Anyways, I'm not sure why you think that a screen resolution change would change pathfinding, I guess it'd be the tile distance on the map file. But anyways I'll run a few tests of your ideas to get my stacks in chivalry moving finally.

nikolai1962
04-23-2006, 20:22
About this name stuff: Maybe this bug causes the game not to update its internal name and the character is still called just Bingen.

That's what i was thinking. May just be a side-effect of how i have the factions set up with no proper family tree. Time will tell.



I'm not sure why you think that a screen resolution change would change pathfinding, I guess it'd be the tile distance on the map file. But anyways I'll run a few tests of your ideas to get my stacks in chivalry moving finally.

I'm not sure myself if it makes sense.

Simplified example.

Screen resolution A: straight line distance to target of a potential move goes from 60 (pixels) to 59.6 -> rounds up to 60 -> stack stalls

Screen resolution B (double resolution): straight line distance to target of a potential move goes from 120 (pixels) to 119.2 -> rounds down to 119 -> stack doesn't stall.

Dunno. Just a vague theory that popped into my head thinking about my old programming days where bugs could get past testing by the developers cos we had higer spec pcs than a lot of users. I could just imagine the CA devs all testing on massive monitors with max screen resolution. Probably a red herring :)

alpaca
04-23-2006, 21:34
Measuring the distance in screen pixels wouldn't make sense really, it'd not be immediately accessible to the AI (because it's very much an engine thing) - differently to the tile distance.
So implementing it that way would actually be more complex and thus probably not be done ;)

nikolai1962
04-24-2006, 01:18
I'll forget that theory then.

nikolai1962
04-25-2006, 21:36
Name Bug

Not related to surnames per se. Scythians do get it, just not on first turn like some of the other barbs and therefore less noticeable. Partially related to path-finding, not sure how yet (scythian cavalry armies i.e more movement points may be behind its better path-finding as Duke John theorized).

I think i've seen this name bug happen rarely after battles too (Man of the Hour promotion?) In a normal setup with good path-finding most factions will only get this a few times (i think). Factions that start with many provinces and few family members might get it a lot.


edit: removed some stuff that was probably wrong

nikolai1962
04-30-2006, 23:22
Bit of a recap/update.

Brigands/Pirates

I've seen posts elsewhere about what value in the strat file stops brigands/pirates. My testing shows:

0 = most
50 = rare
99 = still get some

It may be related to region size (number of fertile tiles?), hence why lower values may seem to work for some people. On the simple map my 15x15 tile regions still get them occasionally with a spawn value of 99. The 5x5 tile island regions never get them.


Pirates

Pirates are critical to ai naval expansion as the ai only seems to target overseas regions if they have no available land targets. (Availability includes ceasefires/alliances making adjacent land regions temporarily unavailable.) There is usually only a short window where the peace holds and naval expansion is an option. The ai,

1) Often builds ships specifically for naval expansion and often only one ship.
2) Once built moves the ship to its waiting-for-an-army spot (outside the safety of a harbour).

This means they are often attacked and retreated by pirates and often sunk with the invading army on board. So basically, because of pirates, new wars usually break out between factions faster than they can mount a successful naval attack and so the faction drops the naval expansion option and goes back to land expansion.


Slave faction building units

I said above that in my simple map the only rebel regions that built units were the ones adjacent to a faction region at the start. This was a coincidence. What happens on my simple map is the slave faction only builds units in the regions with romans as the faction creator. Possibly unit size/cost? (edit: on my simple map the faction creator in the regions file is either romans or britons.)


Name bug.

Pretty sure now there are two separate problems.

What definitely happens in my testing setups is if a faction can't find its target region then the first stack they produce will not move once it moves out of the city to that settlement's sentry spot. If the captain of that stack then gets promoted you get the name bug (where the console says "error name not found" when trying to use move-character) but this won't happen if every region on a map can path-find to the settlements of each of its adjacent regions. Or at least the settlement it picks as its first target. Another faction taking the settlement breaks this stall.

Separate to this there is definitely a stall that can happen after fighting a battle. After looking for this specifically on my simple map it can happen to a stack that is general-led and not only to captains i.e it is not a man-of-the hour version of the name problem, not always anyway. (There may be a problem with names as well as some other after-battle bug as very occasionally you get the name error when trying to move a stack stalled by a battle.) Otherwise this stall seems to be broken by any kind of movement, including using move_character or an advance/retreat from a subsequent battle.

It is only critical to the ai faction when the stack involved has been given a settlement to target as the ai designates one stack as the primary attacker and will not siege the settlement while the primary attacker is stuck. Also the ai only targets adjacent regions so if the targeted region is the only target available the whole faction stalls apart from chasing brigands. They won't target available naval expansion regions either when stuck like this.

There may be a way to fix some of this but it will not be easy as the stalls happen too inconsistently to find out what might be the common elements.

On my simple map, starting the britons/romans in the same region, the britons do consistently get more of these stalls. Without me moving the stuck armies the britons usually fail to get all the land regions (on average they get stuck on 1-3) whereas the romans only occasionally fail to get all of them and usually the most they are stuck on is one region. So maybe some clue in that.


Edges

The ai seems to have problems with map edges, at least the right hand and bottom edges. If enemies (brigands) are close to the edge the ai will send stacks that seem to get stuck as they approach. Sometimes the enemy stack will be far enough away from the edge to be attacked once but when it retreats the ai army can't seem to follow. In an extreme case a brigand army retreated right back to the right hand edge and the ai army stalled. I moved the ai army to the tile directly to the left of the brigands and the ai army didn't attack. However when i moved the ai army also to the map edge, one tile below the brigands, they did attack and then carried on. Will test whether having some impassable terrain on the edges cures this.

Region size may effect this.


Region Boundaries

I had chunks of the vanilla map working well with the ai expanding without any hitchs until i accidentally messed it up completely. I thought originally it was because of all the woodland i scattered around out of boredom but i don't think it was now. I'd changed some region boundaries not thinking they would effect the path-finding but they do, sometimes in very weird ways. The strangest was armies moving to Tingi suddenly deciding to not cross one of the bridges any more and instead to make a V shapped detour around the river source back to the road on the other side of the bridge. Will need more testing but two things to look out for specifically are:

1) Parts of a region that can't be reached from that region i.e an army needs to move into another region first then back into unreachable part.

2) Shared boundaries over impassable terrain e.g mountains. if you have two regions whose border is mountains then the path-finding seems to change depending on whether one region has all of it inside its region, the other does, or they share it.

The first in particular seems to be able to mess up path-finding between regions. Will try and create a clear example with my simple map if i can do it deliberately (very easy to do accidentally :) )

professorspatula
05-01-2006, 01:51
Very fascinating and indepth research. Well done. How you have the patience, I don't know, but we're all grateful for your efforts for sure!

The thing that bugs me is that all this research is the work of one person. Now surely CA had a whole load of people doing the same kind of tedious testing? I assume they also had a bunch of extra console commands which could tell the programmer/tester the current status/goal of a stack, so if the stack was stuck, they'd have an indication why. With such resources how did some of these AI problems make it into the game, and still not be resolved? You don't even need to go into the depth you did to notice how the AI never targets some settlements (Tribus Sakae) and gets stuck in the desert with stacks it doesn't know what to do with. Obviously the AI will never be perfect, but obvious problems have been around with every version of RTW.

I've long been a believer of adjusting the campaign map to provide 'stepping-stones' for the AI armies by adjusting the position of settlements and adding/removing regions to increase their expansion potential, but I never really put much effort into it, and with the 1.5 patch assumed many of the existing problems were long gone, and to be fair, some are. I think realistically, unless CA decide to release another patch to improve the AI to something resembling acceptable, spending hours and hours tweaking maps hoping it will make all the difference could in some cases just not be worth it. The player's own actions will affect how some of the AI factions expand, and even though say Carthage expands well, there's still a lack of sea invasion from other factions in the maps you show. The AI is too rigid in structure and it clearly needs a kick up the toga. It's inability to deal will multiple threats and targets is probably why, in part, CA separated the Romans into 3 competing factions (and the Senate) so collectively the Roman empire would expand in all directions and not just get stuck in Gaul for the next 100 years.

Good luck with your continuing research.

Lets hope CA have improved things greatly with MTW2, or it'll be another reminder to us all that the AI isn't up to the job of coping with a non-Risk style map.

nikolai1962
05-01-2006, 23:15
Ty,

I don't really have the patience unfortunately. I get totally sick of it very fast but i have developed a "need to know" whether the campaign ai is capable of dramatic improvement by following some simple map rules and maybe a bit of minor modding. I think it is but working out specifically what those rules are rather than my current vague ones keeps bugging me to come back to this. I'd much rather be playing :wall:

I think the reason CA didn't pick up a lot of these is partly because they are really hard to spot on a normal map if you are actually play-testing instead of sitting on an island clicking end turn and watching other factions move. On the other hand it seems to me they badly need to have a very simple test map and people doing what i did. I bet a lot of these bugs are very minor rounding error type things.

With the vast improvement in battle ai of 1.5, the battle and immersion improvements of various mod teams, that only leaves good campaign ai as the big hurdle to a scary immersive strategy game.

It is very tedious though.

shaggy1973
05-02-2006, 00:11
dont want to teach a good modder to suck eggs but you know about the -ai command dont you. In your shortcut properties add -ai at the end of the line to have the game play itself. makes it easier to just sit back and watch the game unfold.

nikolai1962
05-02-2006, 00:54
dont want to teach a good modder to suck eggs but you know about the -ai command dont you. In your shortcut properties add -ai at the end of the line to have the game play itself. makes it easier to just sit back and watch the game unfold.

I'm not a good modder at all I just randomly change stuff to see what happens. If anything works it is sheer luck :wall: So ty for that, i will try it :laugh4: (had heard of the -ai switch once but forgot)



have you tested wether lots of movement points (MP) decreases pathfinding problems? If so you might want to test giving AI characters a movement bonus trait when they have not used any MP for a few turns and are not in a settlement; they are stuck. The sudden increase in MP might open a different path

Comment from duke john i just re-read. Originally i wanted to see what caused the stalls so i didn't want to just increase movement distances in case it worked (if that makes sense). However now i know for sure that some ai stacks stall for some reason after some battles and that the ai stacks should nearly always be moving if they are at war with anyone then messing somehow with the traits of generals who are outside a settlement with full MP for a number of consecutive turns might very well prove to be a solution somehow. Hmmm :book:

nikolai1962
05-02-2006, 06:11
Hands Duke john a balloon :balloon2:


Update in a bit when i have worked out how to make a new trait :2thumbsup:

nikolai1962
05-03-2006, 00:57
A partial solution to the post-battle stall that effects the AI so badly and some other stuff. A lot of the images are unneccessary to the conclusions but they are useful to me to look back on to remind myself of things to look into more.

Post-Battle Stall

I wanted to clear up a few of the things I'd been noticing to reduce the size of the list of things that need further investigation. The post-battle stall was the most confusing so i started with that. On my simple map I set the romans up in Tarentum where they had just one available adjacent target region. This time i gave them a small starting stack as i wanted them to attack on the first turn a small stack of rebels i placed just to the west. The idea being to see how often they stalled and if it was just after losing or if it also happened when they won and if there were any common elements on the occasions when they stalled. The idea for setting them up with just one available target was to (hopefully) ensure their first stack had orders to attack Rome as it seemed to be only stacks with orders to attack settlements that stalled if they got into a battle before reaching their target.

https://img266.imageshack.us/img266/5236/battlestall13ci.th.jpg (https://img266.imageshack.us/my.php?image=battlestall13ci.jpg)

The consistent pattern over a few test runs was the starting hastati would attack and win.

https://img132.imageshack.us/img132/2662/battlestall29iq.th.jpg (https://img132.imageshack.us/my.php?image=battlestall29iq.jpg)

On the end turn their captain would be promoted.

https://img132.imageshack.us/img132/5111/battlestall30ve.th.jpg (https://img132.imageshack.us/my.php?image=battlestall30ve.jpg)

And then they'd stall. The original stack would remain stationary while the roman ai produced a few more units. Those units would move to Tarentum's sentry spot.

https://img266.imageshack.us/img266/407/battlestall41li.th.jpg (https://img266.imageshack.us/my.php?image=battlestall41li.jpg)

On the next end turn the second stack's captain was promoted.

https://img266.imageshack.us/img266/2382/battlestall57ff.th.jpg (https://img266.imageshack.us/my.php?image=battlestall57ff.jpg)

The turn after the second stack was *ready* the stalled stack moved to Rome.

https://img132.imageshack.us/img132/8656/battlestall60qh.th.jpg (https://img132.imageshack.us/my.php?image=battlestall60qh.jpg)

This happened consistently 3-4 times and wasn't what i'd been expecting. Neither the always stalling, stalling after a win or captain's stalling. I wish i'd thought of testing it like this before instead of trying to guess what was happening when dozens of stacks were on the move making it too confusing.

This led me to thinking (wrongly) that maybe the stall was something to do with the ai re-assessing all it's stacks movement orders when a new stack was formed and that the permanent stalls i'd seen were some side-effect of that going wrong sometimes

I moved the starting rebels left into the rebel region to see if things were different if the romans had a general led army (because if the rebels were outside roman terriotory the roman ai wouldn't attack first turn and instead would move their starting hastati out of the city and then promote the captain before moving). This didn't work as the romans bypassed the rebels on the way to rome and then attacked afterwards.

Next step was to try to set up the starting armies so the romans would lose the first battle a lot to see if that made a difference. So the rebel stack got a general and 9 exp warbands.

https://img266.imageshack.us/img266/7924/battlestallb16dw.th.jpg (https://img266.imageshack.us/my.php?image=battlestallb16dw.jpg)

This made the romans lose a lot and retreat to rome but they never stalled here. They just attacked and won the next turn in a second battle.

https://img266.imageshack.us/img266/2420/battlestallb21yx.th.jpg (https://img266.imageshack.us/my.php?image=battlestallb21yx.jpg)

The next end turn the captain was promoted.

https://img266.imageshack.us/img266/8938/battlestallb36oe.th.jpg (https://img266.imageshack.us/my.php?image=battlestallb36oe.jpg)

On the first test of this setup the same thing happened as before. After their victory the fist stack stalled until a second stack had been built.

https://img266.imageshack.us/img266/2684/battlestallb49pm.th.jpg (https://img266.imageshack.us/my.php?image=battlestallb49pm.jpg)

The turn after they moved to Rome.

https://img266.imageshack.us/img266/2820/battlestallb59ey.th.jpg (https://img266.imageshack.us/my.php?image=battlestallb59ey.jpg)

Except on the next test it wasn't the turn after the new stack had been built (note dates).

https://img266.imageshack.us/img266/9389/battlestallb69bz.th.jpg (https://img266.imageshack.us/my.php?image=battlestallb69bz.jpg)

Ran it a few times and got a semi-random number of turns before the first stack moved (between 1-4).

Then thanks to Duke John making me think about movement points instead of focusing on names i spotted the common element that made both this setup and the previous one make sense. The first stack moved after its stall the turn after the slave faction built roads in the rome region. It was just coincidence that this mostly coincided with the roman ai building its second stack.

To double-check i made basic roads cost 40000. The slave faction didn't build roads in the rome region and the roman ai never got unstalled. (Which may explain why the ai problems were more pronounced when i was first trying out building mods that included much more expensive roads.)

https://img132.imageshack.us/img132/5010/battlestallb75qc.th.jpg (https://img132.imageshack.us/my.php?image=battlestallb75qc.jpg)

Following Duke John's suggestion I added a trigger for a trait that gave extra movement points (Energetic it think) that fired if a general ended his turn outside a settlement with full MP.

https://img266.imageshack.us/img266/5374/battlestallc15hx.th.jpg (https://img266.imageshack.us/my.php?image=battlestallc15hx.jpg)

This unblocked the stall (in this case). I wanted to check if it was somehow the change in their movement potential that unstalled them or something else so I then changed the base MP in the descr-character.txt from 80 to 100. This stopped them stalling too (in this case).

Lastly, as this seemed a bit weird, I added a load of swamp between rome and tarentum to increase the movement cost. In this test the stack remained stalled even with the extra base movement points plus the added 10% when the trait was triggered. They only unstalled when the rome region built roads (i'd changed the cost back to 400).

https://img266.imageshack.us/img266/6/battlestallc27vz.th.jpg (https://img266.imageshack.us/my.php?image=battlestallc27vz.jpg)

So i think this post-battle stall gets unblocked when the stack can reach its target in one turn's worth of MP If it takes multiple turns they stall. So if any combination of factors, roads, extra MP, advancing one tile after a second battle etc, brings the stack within one turn of its target then they get unstalled.

Increasing MP overall may be a good thing in itself and help a lot of these problems but regardless of whether you want to do that in your mod or not i think to greatly reduce the number of post-battle stalls all mods need something like:

A trait (preferably AI only) with incremental levels all giving +10% MP, so the first level they get +10%. The second level they get +20% etc and it keeps going up until they get unstuck. (nb I don't think i've ever seen this happen a long way from a target settlement. The way you can tell which is the stalled attacking stack for an untaken settlement is that it is the one that is close by but not moving.) The trigger being an ai stack ending its turn outside a settlement with 100% MP firong evry turn they are still stationary and increasing the trait every turn. (May be better if slave faction was excluded as otherwise brigands might be retreating for ten minutes.)

Then, and this is the bit i don't know how to do, preferably the trait is reset to zero when they end their turn with less than 100% MP.

There are some cases when the ai has a reason for being outside a settlement and stationary (like guard mode or waiting for a ship) but i don't think them getting a few extra MP in those situations will unbalance things.

This MP solution also explained why the britons stalled on up to 3 (of the 18) land regions on my simple map whereas the romans on average only stalled on 1, if any. Nothing to do with names but to do with the fact that the roman faction gets more traits with extra MP.

I don't think this will stop all stalls, especially the path-finding type ones from retreating behind mountains etc, and i *think* there may be other types of glitch related to battles too but i'll finish my incremental MP trait and see if the britons can consistently take all the land regions in my simple map with that trait in place.


Brigand spawns.

While i had my swamp there i wanted to test another idea.

Brigands only spawn on faction owned terriotory and a spawn "event" only occurs on the rebel turn if there aren't any rebel stacks in that region. (An event may include multiple spawns in the same region though.) i wanted to see if it was related to the number of fertile tiles. I set the brigand spawn rate to 0. None spawned until the roman ai killed the placed stack. (Otherwise brigands always spawn the first rebel turn if the rate is et to 0.)

https://img132.imageshack.us/img132/702/rebel17hy.th.jpg (https://img132.imageshack.us/my.php?image=rebel17hy.jpg)

When the roman ai killed that stack the tarentum region got 3 spawns. It was consistently 3-4 spawns every "event" after the romans had cleared the previous stacks.

https://img132.imageshack.us/img132/440/rebel23mj.th.jpg (https://img132.imageshack.us/my.php?image=rebel23mj.jpg)

When eventually they took the mostly swampless rome region it was consistently 6-7 spawns per event. (Something I'd noticed previously when testing the effect of different spawn rates on the ai expansion speed.)

https://img132.imageshack.us/img132/5569/battlestallc35av.th.jpg (https://img132.imageshack.us/my.php?image=battlestallc35av.jpg)

So I'm pretty convinced brigand spawning is related to a combination of the spawn rate and the quantity of fertile tiles in a region.

What i was actually hoping was that brigands would only spawn on or near fertile tiles in the hope that i could use that in large desert/steppe regions to make them spawn closer to roads/settlements and therefore make it easier for the ai to chase them but they seemed to spawn in the middle of the swamp just as much.


Minor map glitch.

In one of the earlier posts i mentioned a stall that happened on completely diagonal paths from attacker to settlement (possibly just a side-effect of square regions). Attacking the region SW of capua, from capua, a stack will head diagonally until it hits the forest.

https://img132.imageshack.us/img132/1256/corner9cc.th.jpg (https://img132.imageshack.us/my.php?image=corner9cc.jpg)

Then the next turn it will move only one tile (west) then carry on normally. I just mention it as if you watch your map and ever see a stack only move one tile on its path it is a sign that the path-finding ai is almost stuck and in some cases there might be something you can do to fix it. Not all.


New river bug

This illustrates a stall that won't be solved by an extra MP trait. Originally the ai had a problem crossing the bridge to attack the settlement of my mega-region. I fixed it by adding some dense forest to the tile it kept moving back and forth onto instead of moving onto the bridge. However in the case shown below a brigand stack had spawned in the mega region in a spot that made the roman army chasing it need to move in a sharp upside-down V path with the apex at the bridge. The roman stack looped between the position shown, up to the tile west of the bridge, onto the bridge, and then back down to the original position.

https://img266.imageshack.us/img266/7554/newfordbug6wv.th.jpg (https://img266.imageshack.us/my.php?image=newfordbug6wv.jpg)

You see this occasionally where an ai stack is looping between 2 or 3 positions. I don't know if a general increase in MP would help this sort of thing in all cases but the triggered trait would never fire as stacks like this aren't stationary.

Now i know more about path-finding i'll have to see if i can find a better solution than the dense forest.

Odd naval thing.

I've seen this a few times in games where a faction would land a small stack by sea and then not attack.

https://img266.imageshack.us/img266/3502/naval14fh.th.jpg (https://img266.imageshack.us/my.php?image=naval14fh.jpg)

The Iberians do it on palma a lot. I'm not sure if it is an explorer stack or a supporting army stack that somehow got to the island first before the designated attacking stack arrived.

https://img132.imageshack.us/img132/7034/naval24pm.th.jpg (https://img132.imageshack.us/my.php?image=naval24pm.jpg)

Just an odd thing i may look at again sometime.

~~~

The main thing is the post-battle stall. After fixing path-finding between settlements and reducing rebellions this is the third biggest cause of the ai under-performing I've seen in my testing.

~~~

Finally, a complete pointless thing but it made me happy lol. From before i messed up the path-finding changes I'd made on the vanilla map.

https://img359.imageshack.us/img359/6958/carth7xz.th.jpg (https://img359.imageshack.us/my.php?image=carth7xz.jpg)

(It took them a while though)

Monkwarrior
05-08-2006, 09:41
Just to complement this excellent research about the geographic limitations of the AI, we think that it is interesting for the community to share our own findings about the AI behaviour. These are the conclusions of a long research work done by Asdrubal, one new member of the ITW team, with the aim to improve the AI behaviour in the ITW campaigns, closer to the historical facts.

In the next picture you can see the initial distribution of regions, with two great super-powers: romans and Carthaginians.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/comportamiento_preinvest.jpg
White arrows show the normal advance of romans, expanding to the north in detriment of the padane gauls, then to the east to capture the rebel regions of Dalmatia and Illyria, and to the west against the transalpine gauls. In some cases, Africa is invaded from Sicily when land expansion is not evident. Yellow arrows show the advances of Carthaginians, involved in different fronts, one in Africa against numidians and other in Iberia, together with important rebellions in the mother land. In both fronts Carthaginians are stuck and they don’t progress too much. Romans do not show any interest for Iberia, even if the win_conditions include mainly Iberian settlements. These behaviours were nearly independent of the core attitudes, starting diplomatic stances or any other evident parameters. Thus we decided to perform some research about this question.

Parameters influencing the advance of the AI: sea vs land advance, agressive vs passive

1- Land limits to expand and suitable navy

a) As told in other posts, the AI tends to expand always by land routes, with special tendency to attack first the rebel regions in the neighbourhood and after that the rest of factions. Thus, if sea advances must be promoted, it is necessary to close the possibilities of land expansion.

b) First of all it is necessary to establish an impassable limit through the inclusion of another faction, preferably ally, eliminating all the possibilities of war between them (we will see how in the next points). But this is not enough, given that if land expansion is not possible, but there is not a driving force to sea expansion, the faction will remain stuck in its homeland until the conditions are suitable to declare war against the allied neighbour.

To illustrate this point, here you can see our initial set-up for a campaign starting just before the II Punic War. We wanted to start hostilities in Iberia, with reinforcements arriving by sea.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/planteamiento.jpg
A second roman faction (blue) blocks the possible advance in north Italy. In this way, the active Romans (red) have no land expansion possibilities.

c) In order to force the sea invasion, it is necessary to provide the faction with a small region in the zone where we want to promote landing. This territory will act as the driving force. This is due to the land limits of that region, which are the only possibilities of land expansion for this faction. As it is a small territory, the AI will send reinforcements from the mainland in a constant way. One important requirement is that this region must have coast to facilitate landing. If the region is an inland territory, the AI doesn’t find the way to send reinforcements and gets stuck.

In the previous image, you can see how Carthage had already some territories in south Iberia, but it is necessary to include one roman region in the north.
We tried to put an inland region as the driving force, but it didn’t work.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/th_IakkaLiguriaNo.jpg (https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/IakkaLiguriaNo.jpg)
We tried also to put a Carthaginian region in north Italy (Liguria), but it had no effect on the Carthaginian AI, as they have a closer destiny in Iberia.

This is the only method we have found to really promote sea invasions where we want. However, one important disadvantage of this system is that the driving force disappears if the settlement falls in hands of the enemy (conquest or rebellion). I that case the AI has no “historical memory”, and it suddenly forgets its interest in that zone. Even we have observed how ships loaded with troops in the way to that region returns to the mainland just after the lost of the far territory.

d) One additional requirement for sea invasions is that the AI must have ships in the suitable positions, preferably one float near the boarding zone and one near the landing zone. The preferred boarding zone seems to be the region with the X coordinate closer to the landing zone. In this map you can see how Etruria is the preferred one for romans, but if it is lost, Lylibaeum (in Sicily) is then used for boarding and in case they don’t own this city, troops board in Latium. It seems that for good development of boarding-landing operations, it is important the synchrony between trips of the floats and troops creation. If ships are delayed and the troops are ready, they start to move trying to find a land route to the target. In our case the target is so far that they don’t find a way and return to the boarding point, although boarding is then delayed.

Here you can see the three boarding zones we have observed in the preferred order.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/posibles_embarques.jpg
and in these three images you can see how it works, depending on the owner of the different regions.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/th_rutaLiguriaIberia.jpg (https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/rutaLiguriaIberia.jpg) https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/th_rutaSiciliaIberia.jpg (https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/rutaSiciliaIberia.jpg) https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/th_rutaLacioIberia.jpg (https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/rutaLacioIberia.jpg)
And here you can see the simultaneous arrival of reinforcements for Carthaginians and Romans to Iberia.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/th_refuerzos_simultaneos.jpg (https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/refuerzos_simultaneos.jpg)


2- Superfactions

a) We have observed that all the factions, even rebels, can be considered as superfactions, either of the other faction or even of itself. When a faction is considered as superfaction, it assumes the behaviour of senate in RTW, with an extremely defensive attitude, without expansion, but recruiting a big amount of defensive troops. This type of behaviour can be used to simulate factions that historically were not expansionists, but that presented strong resistance to conquest, for example the Celts in the Iberian peninsula.

b) One problem, if rebels are considered as superfaction, is that in case of a rebellion in a settlement of another faction, this faction will find great difficulties to recover the settlement. We have observed this problem in Carthage.

c) In spite of being superfaction, the core attitude between this faction with its “vassal” can be of any type, even clearly hostile, and the starting diplomatic stance may not be allied.
The best way to establish a limit for land expansion is to give the limit regions to an allied superfaction. This will act as shield against possible invasions and won’t attack to its vassal faction. However, this is not enough to prevent attacks from the vassal to the superfaction.

3- Economical-military dissuasion

a) This is an important parameter to establish stable and durable limits. If one faction has not simple ways for land advance and it is blocked by a weak superfaction, it will decide to attack this superfaction as it considers this solution easier than the sea expansion.
It is necessary then to equilibrate the starting situation, in treasury, starting troops and settlement development, to prevent this attack.

We can see again the set-up.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/planteamiento.jpg
The blue romans are superfaction of the red ones, but they must have enough troops to dissuade the red romans from a possible attack. In the same way, Numidia (dark blue) is superfaction of Carthage, preventing in this way the fight in Africa.

b) This parameter is also important in the landing zone. If the factions surrounding this zone are extremely strong, they act as dissuasion powers for landing. Even worse, they can decide to attack the settlement, disappearing in this way the driving force for sea invasion. If those factions are too weak, the first reinforcements will be enough to destroy them.

With all those equilibria well-established, the AI is forced to the required situation, as in this case: Romans and Carthaginians will converge to Saguntum to begin the conflict.
https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/th_ReconquistadeSagunto.jpg (https://i67.photobucket.com/albums/h292/Monkwarrior/research_AI/ReconquistadeSagunto.jpg)

c) Another important dissuasion factors are walls. Their widespread presence dramatically reduces the aggressiveness of the AI. For a more dynamic campaign, it is necessary to limit walls, both at the beginning (descr_strat) and along the campaign (higher settlement requirements and prices).

4- Behaviour parameters

Finally this parameter seems to have an influence more important than expected. One faction limited by an allied superfaction cannot have the attributes “Caesar”, “Genghis” or “Napoleon” because it will attack to the neighbour superfaction. It seems that parameters such as “smith” or “stalin” are more suitable, as better equilibrium between economy and aggressiveness is obtained. The parameter “sailor” is devoted to ship building, but it doesn’t promote sea invasions.

I hope this long post will be useful for the design of new exciting campaigns.:book:

Monkwarrior
05-10-2006, 11:41
I see that this subject was less interesting than I thought.:hide: :shame:

shaggy1973
05-10-2006, 13:26
I think many people knew some portions of your post already, although I learnt a few more tips and tricks as was unaware of. Thanks monk warrior :)

It is certainly good that it has been set out in b&w though, and a good idea to collect it into one thread. I am certainly referring back to all the posts here when setting up my own little campaign, and will be making use of your superfactions work, as well as the more general AI stuff from nikolai.

Thanks guys

Myrddraal
05-13-2006, 01:58
The detail in which this research is being carried out is outstanding. Many thanks for the info.

DimeBagHo
05-13-2006, 13:17
This is great stuff. I'm in the middle of redesigning the XGM campaign, and the research in this thread has been immensely useful.

Quintilianus
08-23-2006, 13:43
Hi everybody, I'm new in this forum. I'd like to know whether there are any discussions about the AI behaviour with diplomacy...:help:

DVK901
09-11-2006, 20:42
Just a '2 cents' worth on my part, and a thanks to all those who contributed to this thread.....one of the things I really 'took up on' from the ideas in here was the problem of the AI factions being able to 'see' the target they were interested in, and their ability to continue 'seeing' it. I've been working on a Mod for quite some time, on the Mundus Magnus3 map, and was not happy with the way the AI was building hundreds of little stack of armies, sending them off somewhere, and then stranding them all there forever. This was particularly evident in Egypt's case, as they tried going after the few Rebel settlements in Arabia after they too Petra. They build close to 40 little 1/3 to half stack armies, sent them off into Arabia, and stranded so many there they had to move around to make room for each other. Not one ever continued on to a target.
I corrected this by changing the 'starting_action_points' in descr_character.txt from the default 80 to 160. This one small change eliminated all the little stacks and impressed upon me that the AI was originally 'seeing' it's target from a settlement across the Red Sea...a short distant....but when the stacks got up and just past Petra, they lost 'sight' of whatever it was they were sent to attack.
Oddly enough (and I had always wondered about this, the doubled distance had no adverse affect on anything. The AI could move further, but they still had 'objectives' and didn't pass them up because they could. Also, I saw a tremendous increase in creation of FULL stacks. This leads me to believe that all the 'stuck' little stacks are actually 'destroyed' as far as the AI knows, which explains why they never merge into bigger stacks.
So I would advise that at the very least, this single value should be increased greatly, especially on the very large maps. I currently have a setting of 200 on the Europa270 map, and it works fine...the AI even manages to get past the 'bendy' roads without too much difficulty.

DaVinci
10-24-2006, 07:57
Hi nikolai, you're leading (and has initiated) a great AI behaviour thread, keep it up.
Monkwarriors threads/observations are as well very true.

I still can remember as we discussed a few similar things, as you played my RTR submod MRR, and i always was searchin' out ways to balancing + AI-finding its historical preferred targets on the campaign map.

So i give as little addition my 2 cents atm. only as short hints (as i have not the time to discuss/describe in a full length, or give examples).

I'm pretty convinced that the AI behaviour has still more parameters/influences to decide where it goes, than the one mentioned in all above threads.

- One of them is, that you can lure the AI into certain regions (to have interest to conquer), if they get certain advantages through the tech-tree codes (requirements) plus in addition with hidden_resources, ie. exp boni, moral boni, especially any kind of income boni, or just the possible recruitment of units/buildings that would give a significant advantage or disadvantage to potencial enemies, and also to provoke wars in this relation or a rather peaceful behaviour.

- Second, with descr_regions codes, just due to these hidden_resources, and due to the initial farming income, with the possible harvest codes.

- In this relation, the start setting of descr_strat, available buildings per region with the possible or impossible recruitment of certain units and the start money, influences the expansion-ability immense (just an important balancing campain part).

- And i just think, the different AI characters have an, not decisive, but quite important influence, initially rather or especially with the diplomatic behaviour.

... maybe i have more thoughts, but not atm., brain-dead :dizzy2: due to modding burn-out syndrome.

nikolai1962
11-28-2006, 06:55
Apologies for not replying to these posts--especially Monkwarriors very detailed one. I accidentally over-wrote the folder I had all my test stuff and my (2/3 perfectly working) vanilla map in and gave up Rome modding for a bit from the shock :wall:

Very interesting posts.

I did have two conclusions from this earlier experience, one of which mirrors shaggy's, for things you can do which are relatively easy and yet help the AI a great deal in many cases.

1) Region Boundaries.
The AI often has path-finding problems when a region has traversable terrain that can't be reached without leaving the region. For example some fertile tiles on the other side of a river without a ford. Simply changing region boundaries can fix a lot of situations where the AI gets stuck through path-finding problems.

As I'm back modding RTR to suit my preferences I've started doing simple map fixes like this as i see them, (can't stand the thought of all the hours fixing the harder ones lol), and it definitely works without taking too much time.

I'll take and post some example screenshots of the sort of situations I mean in a bit. It can really make the game much better when the AI is operating as intended and it doesn't take long.

~~~

There are much more tricky ones that involve the situation where somewhere along it's path an AI stack would have to move further away from it's target than where it currently is e.g it is close to a city but with some impassable terrain in the way so it would have to move away from the target to get round the impassable terrain. A good example of this is the bit of land approaching the chersonesus area from the east. AI armies tend to get stuck in that corner instead of going backwards to cross the ford. These problems take a lot of trial and error making terrain changes and testing and are a total pain in the arse. However the region change mentioned above could improve a map by about 50% with minimal effort.


2) Movement Bugs
There is definitely a bug where if an AI stack loses a battle and retreats they can sometimes get stuck in that spot. This is related to path-finding in some cases but not all. They can definitely get unstuck in many cases when their movement potential changes e.g if the target region builds roads or they get a movement bonus trait.

This bug effects roman and greek culture factions less than others because they get a movement trait that triggers from being outside a city (which a stuck army often is).

Either the problem is related to the total movement points they have, or the AI re-calculates the stack's movement when it's movement potential changes, possibly both. There are two things, either or both of which are definitely worth doing if you are creating or trying to improve AI performance on your map.

a) Try different amounts of movement points. Personally i don't think higher movement points is the solution as such to the post-retreat bug--I think it depends on the scale of your map. In some cases higher movement points will just mean the AI armies get stuck further away from their target (as they'll retreat further). However I think it will fix other path-finding problems as the AI seems to have less problems when it can reach it's target in one turn.

As DVK's post mentions if you see the AI with a lot of small stacks clustered together and not moving much then it is always a sign that the faction has a path-finding problem or a stuck army problem. If the faction gets over the problem the AI will combine those stacks and move them to their next target. In his case I think the higher movement points fixed some normally recurring path-finding problem so that the faction didn't get stuck in their normal place. (The multi-stack thing is a symptom rather than a problem in itself.)

(There are two semi-exceptions to the always. One is if they are land-blocked and have no naval expansion route. In this case they have the same problem. They are stuck. And the same symptom--lots of small stacks standing around. But in this case they cluster around their capital and not around the problem region. The second semi-exception is when they are land-blocked and have a naval expansion route but no ships. In this case the small stacks cluster near the region they'd launch their invasion from if they had a ship.)


b) Have a trait that adds and removes movement points regularly e.g a winter/summer trait. The constant changing of their movement potential each turn (or each season if you are using 4TPY) may unstick them if indeed the AI re-calculates stuck stacks when their movement changes. Either way it will help in some cases as the extra summer movement points will fix some stuck armies if it means they can then reach their target in one turn.


I'm not very good with traits personally so if anyone knows of a mod that adds movement in summer turns and subtracts in winter turns I'd be pleased to know of it (so I can steal the code for my mod :) )

Apologies again for not replying for so long.

nikolai1962
11-28-2006, 07:20
Hi everybody, I'm new in this forum. I'd like to know whether there are any discussions about the AI behaviour with diplomacy

I don't know of any discussions as such. The AI diplomacy is not very good imo. One thing that seems to be true when i play is that the stronger you are militarily the more reluctant the AI is to attack you. The other thing is if you have enough cash you can get the AI to agree to anything. The second however is semi-pointless as if you have that much money then you could probably bribe all their cities/armies. You can't really use diplomacy as an *alternative* strategy as the amount of cash it requires would enable you to blitz the map anyway.

If you see what I mean.

nikolai1962
12-17-2006, 09:07
Forgotten how to take screenshots, so some other AI stuff



d) One additional requirement for sea invasions is that the AI must have ships in the suitable positions, preferably one float near the boarding zone and one near the landing zone... ...it is important the synchrony between trips of the floats and troops creation. If ships are delayed and the troops are ready, they start to move trying to find a land route to the target. In our case the target is so far that they don’t find a way and return to the boarding point, although boarding is then delayed.

This can cause permanent stalls too where the armies and fleets are permenently out of step e.g armies in carthage looking for ships while the ships are by icosium waiting for the armies, then after a turn the armies move to icosium and the ships move to carthage. Then back and forth like that for ages.

I wanted to create a free upkeep ship and spawn one every 20 turns or so to see if it got round this bug. Not sure if you can spawn ships though.


~~~


c) Another important dissuasion factors are walls. Their widespread presence dramatically reduces the aggressiveness of the AI. For a more dynamic campaign, it is necessary to limit walls, both at the beginning (descr_strat) and along the campaign (higher settlement requirements and prices).

This works the other way too. *Lack* of walls makes the AI more aggressive. So, for example, if you mod a faction to not be able to build walls then the other factions are much more aggressive to them.

Walls, or the lack of them also effects the size of garrison the AI leaves behind (especially at game start it seems). So if you remove walls from a faction the AI will want to leave a much larger higher percentage of it's starting units behind on the first few turns.

~~~


4- Behaviour parameters

Finally this parameter seems to have an influence more important than expected. One faction limited by an allied superfaction cannot have the attributes “Caesar”, “Genghis” or “Napoleon” because it will attack to the neighbour superfaction. It seems that parameters such as “smith” or “stalin” are more suitable, as better equilibrium between economy and aggressiveness is obtained. The parameter “sailor” is devoted to ship building, but it doesn’t promote sea invasions.

I need to look at this more. I thought they only effected build priorities.

(May however be an indirect side-effect of what type of units they build--see "AI and cavalry" below)

~~~

Some new stuff from trying to make the sarmatians less passive in RTRPE.


AI and cavalry

I always thought the AI wouldn't siege if they had an all-cavalry stack but they do. They even build siege equipment although they never use it as they can't assault. They will wait out the siege instead. They very rarely do it because of the way the AI calculates the strength of stacks.

Numbers count for a lot. Large units are important and cav units are generally smaller. Also it seems high missile attack ratings are wieghted much lower than high melee attack ratings. What this means is that horse archer type factions have a huge differential between how strong their stacks are for auto-calc compared with how strong they are when a player uses them in a battle.

This doesn't only affect their chances in auto-calc though--it also decides their expansion behaviour. They won't initally attack a target if they calculate the garrison to be too strong for them. (This seems to be initially only. Once they have decided to attack a settlement they'll keep attacking with very weak armies but initially the relative strength of the garrison and their own armies affects them.)

So cavalry-heavy armies and especially horse-archer factions will be extremely passive unless you give them infantry units too or make the cavalry units much larger etc.

If you want to set up a faction as primarily horse archer with few or no native infantry units then one thing you can do is create a second version of their standard horse archer unit. Make them unbuildable, max size and zero upkeep and then spawn a bunch of them with a campaign script for AI only. Tweak the number of units until a starting army moves to attack a nearby rebel settlement. (If there's enough of them they will siege.) As they are unbuildable the AI won't get any more and as they lose men taking the rebel settlements they don't unbalance the faction long-term. Eventually they'll take some regions with AOR type infantry so they'll have a chance to expand normally after that.

This way you can have a very interesting faction for the player, with a very different style (as at the start they have tiny all-cavalry armies) but at the same time the AI version of the faction isn't totally passive.


~~~

Creating campaign timers.

Inspired by a thread on the EB forum and Monkwarriors stuff on superfactions.

1) As mentioned the AI is influenced by the strength of garrisons/walls etc whether or not to attack. The strength calculation is very influenced by sheer numbers of enemy soldiers and their melee attack rating.

2) A number of mods set up immoveable rebel garrisons by having a starting general with a trait that prevents movement.

3) Normally, if a rebel garrison is very large and their movement is not inhibited by a general's trait they'll move out of the city leaving only a small contingent behind.

So, by having a very large immobile rebel garrison and tweaking the starting general's age you can create a kind of timer to influence AI expansion.

For example, you could have some rebel cities where the general is 16 and others where he is 50. If the stack is huge enough to guarantee the AI won't attack then that region will remain as a buffer zone for a very long time. If the starting general's age is set to 50 then it will be shorter.

I was thinking if you had Messana and Saguntum for example set up as rebel with a strong garrisons, romans as faction creator and a high unrest setting (the "chance" field in descr_rebel_factions.txt), you could set the two general's ages to x number of years before the historical roman intervention in Sicily/Iberia. The general would die at some randon time close to this date, the army would move out of the city meaning nearby factions were more likely to target it. Eventually they'd take it and the unrest number would make a revolt to romans likely. Hence providing the reason for naval re-inforcements.

(probably easier ways to do this with script)

outkast
01-06-2007, 11:51
@nikolai and monk

Really great work. Really hats off for all this work. My old username doesn't work for some reason and I can't get it back so I've re-registered just to say- respect.

With all this great work has anyone made any progress on a map for vanilla total war that you can plug in and play easily enough (perhaps with a new desc_strat).

The work on this community is great but I wish there were more minimods that fiddle with minor things to improve playability rather than huge mods that change the game completely.

nikolai1962
03-13-2007, 21:09
Real life dragged me away from modding again but i did say i was going to illustrate the most important thing from i got from all this with some screenshots. The most important thing is "convex" shapes. I tried to explain it in text before but a screenshot is better.


Jerome Grasdyke posted this info about map-making ages ago:

A few other caveats about regions:
- they should be 'convex' (one landmass, no inaccessible areas)*- they should have only one settlement and only one port
- all land tiles should be part of a known region
- each non-sea region should contain at least some fertile tiles
- continuous sea surfaces should form one region
- the maximum number of regions supported is 200
- the distance between the centres of any two adjacent regions should not exceed 50 tiles*

*: not doing these things shouldn't cause a crash, but it may cause the AI to mess up.

I had no idea what the first caveat meant when i read it as i think the average person has a different definition of "convex" to how it is used here. I think convex means something speciifc in whatever branch of mathematics is used with figuring out the AI movement in regions. (probably called something star trakkish like n-space topology.)

What i think it means now is illustrated by this.

https://img443.imageshack.us/img443/2273/convexexpoxe4.th.jpg (https://img443.imageshack.us/my.php?image=convexexpoxe4.jpg)

I used MTW2 as the problem still exists in MTW2 and this example is so clear. I'm guessing the guy who originally did the code has moved on and no-one there knows what he meant by convex either as the MTW2 map is littered with examples.

A slightly harder to spot example is:

https://img443.imageshack.us/img443/2379/convexexpo2zd9.th.jpg (https://img443.imageshack.us/my.php?image=convexexpo2zd9.jpg)

~~~

As a quick test i started a new campaign as Russia ten times with fow off and hit end turn 20 times. Then moved the border to the river and repeated.

Without the fix:
Rennes not taken by turn 20: 4 times
Taken by Portugal 2 times (turns 11 and 13) (gogo naval landings at last :) )
Taken by England 3 times (turns 8, 10, 19)
Taken by France 1 time (turn 19)

With the fix:
Not taken 2 times.
Taken by Portugal 2 times (turns 10 and 11)
Taken by England 3 times (turns 8, 16, 17)
Taken by France 3 times (turns 15, 16, 17)


This fits in with previous experience where the problem was often more pronounced in particular directions e.g the AI had a problem path-finding to a region from the region to the north but not from the region to the south.

Given all the random elements in each game ten iterations isn't really enough to count as conclusive proof but i got bored and i've seen the dramatic effects so often with both the vanilla RTW and the RTR map that i can't be arsed to do more :)

The rennes region example is such an easy one to test that if you're a map modder you can convince yourself if you like.

This is relevant to both RTW and MTW2 modders as the problem has carried over. I don't think CA realizes it is a problem as the MTW2 map has dozens of these.

There are other map/path-finding problems but this one is often the easiest to fix and has the most dramatic results.


~~~

@outkast

sorry for late reply


With all this great work has anyone made any progress on a map for vanilla total war that you can plug in and play easily enough (perhaps with a new desc_strat).

I did the vanilla RTW map first but lost it out of carelessness. Does take a lot of re-balancing the descr_strat as the starting armies are completely unbalanced once the AI is moving properly. For example in the part-finished RTR map i had (and also lost through the same thing) the seleucids got eaten alive by the surrounding factions once I fixed the map.

professorspatula
03-14-2007, 16:28
I've been following this thread from the beginning and I have to say hats off to Nikolai and everyone else who's contributed to the discussion. Some of it I've noticed myself before, and other things I've since been made aware of because of this thread. And time and time again you see where the AI is going wrong and you just want to shake your head in disbelief. I think the entire strategic AI needs to be redone from scratch. It's clearly deeply flawed. AI factions have very little awareness of their surroundings, they have no long term goals and everything seems to be done on the spur of the moment and recklessly. You never think you're going up against an enemy that has built a war machine for a specific purpose. Occasionally the AI blunders into your borders with a couple of armies, but once they're disposed of, the AI gets confused and has no real answers what to do, other than send the occasional other stack your way. It's a shame massive improvements weren't made with M2TW. What the genre needs is another historical RTS game of a similar ilk that trounces TW's efforts, or at least enough to make CA wake up and improve the AI's competence.

In the meantime, you can make adjustments to regions borders etc, but it's a heck of an effort, and far from perfect. You're also fighting an uphill battle when it comes to the AI's basic lack of defensive knowledge when it comes to islands. Because as previously mentioned the AI will start gathering armies around the capital when it isn't sure what to do, it will happily leave all it's islands unguarded, even if they're prime targets for neighbouring enemies. Case in point: Carthage and Sicily/Sardinia/Palma etc. Upon thwarting the enemy advance in those places, Carthage will remove all its garrisons and move them into the pauper lands of North Africa, giving the Romans ample chance to take the islands with little effort. Pursuing a town in a desert isn't worth sacrificing your rich island provinces for, but the AI isn't aware of this enough. I had a heavily modified campaign where Carthage was strong enough to see off waves of Romans, and finally put up a worthy challenge in what could be interesting Punic wars. But then they abandon their islands and the joy turns to despair as they gradually lose their cities and their armies because they're nothing short of stupid. A shame for sure.


What amazes me is CA never noticed/did anything about the AI when it came to BI and Tribus Sakae. Seldom attacked in standard RTW, surely it must have been obvious to testers it still isn't a target in BI, and yet nothing was done about it. If a settlement is ignored by the AI (even if its an immensely powerful one like the Sassanids, surely something is wrong with the AI.

nikolai1962
03-15-2007, 08:32
I must admit i was pretty surprised to see the MTW map was so full of the same problems and to see the AI still stalling after retreats etc. As you say some of these flaws (like Tribus Sakae) should be so obvious it's baffling they weren't looked at. I guess it all comes down to the strategic aspect of the TW games being designed more as battle generators than a strategy game. It seems it is not a priority compared to the tactical side.

Admittedly it is a an uphill struggle to turn the strategy map side of the game into something good.

Monkwarrior
03-15-2007, 16:12
Only a brief comment about the AI behaviour in campaign.

We have observed (disappointed I must say :furious3: ) that the behavior of the same factions, with the same core attitudes, the same diplomatic stances, the same armies, the same regions, etc, is completely different when run over RTW engine or when run with BI.exe.

We had optimized the AI behavior en different provincial campaigns, to adjust it to history (up to the possibilities of the engine), but all this work is completely useless if we use BI.exe.:shame:

Makanyane
03-15-2007, 19:55
Monkwarrior, that's very interesting to know, I know a lot of people have theories about one .exe being better but hadn't seen much in the way of examples of differences. Is either .exe behaving more logically in relation to diplomacy or campaign strategy? Or do you think it is that things have been done in the .exe for the path finding for armies that have lead to the differences in the way your campaign plays out?

Only thing I've noticed as distinct difference in BI is that rebels tend to move to 'capture' watchtowers, whereas in RTW I think they stand on road more - if that sort of thing changed there could well be other 'priority' changes for AI movements.

If nikolai still has some of earlier test set-ups maybe we could persuade him to lend them out so we can see if they behave same way under RTW and BI?

Monkwarrior
03-16-2007, 00:25
Monkwarrior, that's very interesting to know, I know a lot of people have theories about one .exe being better but hadn't seen much in the way of examples of differences. Is either .exe behaving more logically in relation to diplomacy or campaign strategy? Or do you think it is that things have been done in the .exe for the path finding for armies that have lead to the differences in the way your campaign plays out?

Only thing I've noticed as distinct difference in BI is that rebels tend to move to 'capture' watchtowers, whereas in RTW I think they stand on road more - if that sort of thing changed there could well be other 'priority' changes for AI movements.

If nikolai still has some of earlier test set-ups maybe we could persuade him to lend them out so we can see if they behave same way under RTW and BI?
Well, it is difficult to answer to such questions. I don't know if it is more logical or not, but it seems to me that in BI the AI has different "triggers" or "objectives".
As I explained some posts before, we wanted to simulate the real expansion of the historical factions. In that way we stablished "barriers" made by superfactions or faction (not slave) limits. The landings and troop transports by sea were also triggered by opening a second land expansion front, and hiding the corresponding culture in the surrounding regions.

But with BI the same configuration doesn't produce the same results. Now the second land front is not interesting for the AI, and it seems more interested in close targets, even in case they are separated by sea. Even the faction parameters (bureaucrat and so on) don't seem to code the same behavior.

Sorry but we have not studied more systemathically the AI. Just some observations to see that our previous work was useless in BI.

nikolai1962
03-17-2007, 05:07
We had optimized the AI behavior en different provincial campaigns, to adjust it to history (up to the possibilities of the engine), but all this work is completely useless if we use BI.exe.

Ouch.



If nikolai still has some of earlier test set-ups maybe we could persuade him to lend them out so we can see if they behave same way under RTW and BI?

I lost my beautiful little test map by accidental deletion many moons ago sadly and i could never bring myself to make another one. Tragic really as it was so useful. I should have uploaded it somewhere before i trashed it.



I don't know if it is more logical or not, but it seems to me that in BI the AI has different "triggers" or "objectives".

I got MTW2 recently and have been looking at how the AI is coded. The AI has a list of potential attack and defend responses it calculates for each opposing faction. Seems quite possible the list was revised for BI.


and it seems more interested in close targets, even in case they are separated by sea

Sounds like they fixed the naval path-finding a bit too which would effect it.


Can easily block factions in now with the AI modding in MTW2. Could create a blocking "northern roman" faction with a passive AI and the "main roman" faction could be set to never attack it. No roman units in MTW2 though :((

Roman_Man#3
03-17-2007, 05:11
I think the work you guys are doing here is tremendous and very noteworthy. Any chance you could start condensing it, because it is very hard to follow unless you were following the thread from the beginning.


thanks, and keep up the good work,
RM3

nikolai1962
03-19-2007, 03:22
New thing proving to be significant with AI pathfinding. If a stack in region A wants to attack a target in adjacent region B but the fastest route for the stack takes it through a mutually adjacent region C then it gets stuck.

https://img180.imageshack.us/img180/7930/shortcutsp1.th.jpg (https://img180.imageshack.us/my.php?image=shortcutsp1.jpg)

Screenshot shows an example (using MTW2 but i'll bet it is the same in RTW). The old route in yellow was the fastest path for a stack near Budapest that had Zagreb as it's target. As armies can go diagonal but roads can't, the path cut across the corner of the vienna region on the way. This caused that particular stack to be stuck and it didn't move until someone else took zagreb and it got it's orders cancelled. By removing the ford across the river the new fastest route followed the road and didn't cut across the Vienna region and the stack started moving to zagreb on it's first turn thereafter.

So far it is proving to be a major cause of AI stacks not moving on game start.


(edit: I think this may be why making region boundaries follow the natural obstacles often, but not always, improves the path-finding.)

~~~


I think the work you guys are doing here is tremendous and very noteworthy. Any chance you could start condensing it, because it is very hard to follow unless you were following the thread from the beginning.

I will eventually. Though I'm pretty sure now of a lot of the general mechanics of the AI (mostly confirmed by the newly moddable bits in MTW2) I'm still not 100% about the path-finding. The "convex" regions only fixes about a 1/3 of the AI movement problems in a map. Currently this new one is looking like it might be behind another big chunk. Some bits like the retreat bug you can't mod out but when i'm nearer to 80% sure of the path-finding probs i'll try and condense it.


~~~

Naval landings.

Comment from Dimebagho on another thread makes me think the "convex" problem may apply to the sea region too. From testing with MTW2 i don't think the code is much different and i suspect the big improvement in naval AI in MTW2 is *possibly* the result of having seperate sea regions for seas that don't connect e.g the red sea. Haven't tried it yet though.


edit: this is the thread

https://forums.totalwar.org/vb/showthread.php?p=1469701#post1469701


~~~

One thing confirmed from the MTW2 AI files is that relative military strength, including that of allies, is hugely significant in determining the AI's actions towards other players and diplomacy is pretty much all about buying factions off so they leave you alone temporarily and very little else. Which is ok as long as you know that's how it is designed i guess.

Also the AI is coded to hate the human more than the other AI factions. Though you can mod that out now.

nikolai1962
03-20-2007, 07:08
Remembered something I always forget which is that one way to make regions non-attackable by the AI is to completly surround the region's city with hills. This has the same effect when partial i.e if the only route from region A to the city of region B is completely blocked by hill tiles. (Stops scotland attacking york by land in MTW2 for example).

Armed with these three pieces of the jigsaw,

1) Convex regions
2) Pathing from one adjacent region to another through a *mutually* adjacent region.
3) Hill blocking

I started editing the vanilla MTW2 map again from scratch. This time instead of previous method of fixing the non-convex bits followed by loads of trial and error editing I just looked for those three possible causes for each of the places where the AI gets stuck in the early game vs rebel regions. Between them they were the cause of 2/3 to 3/4 of the problems and the process was *vastly* quicker than the previous method.

Still a few places where the cause is not apparent so still at least one more piece of the jigsaw to find. However, apart from the times the retreat bug bites the AI is eating up the rebs much better.

~~~

Number 2) is so far proving to be the biggest cause of the path-finding probs. The non-convex regions seem more inclined to make the AI take weird routes from A to B rather than to make the AI stacks stall directly. (Though the weird paths often indirectly cause the stall, sometimes it is the other way round and a direct path causes it. Knowing the actual cause now means these cases can be fixed.)

nikolai1962
03-25-2007, 02:30
1) Convex regions
2) Pathing from one adjacent region to another through a *mutually* adjacent region.
3) Hill blocking

Spoke too soon. This isn't directly true as none of these will *neccessarily* fix the path-finding problems, although they all have seemingly fixed problems in the past.

The map isn't a map it's a collection of x,y co-ordinates arbitrarily grouped together into regions. This data then gets applied to an algorithm which will produce viable pathways *if* all the data is properly formed according to the rules of the algorithm. Whatever those rules may be.

Any change to the map will change the potential pathways.

The *regions* data aren't independent of each other and a change in one part of the map may have an odd side-effect elsewhwere (literally you can change the border of yerevan and an army in scotland that previously moved on game start is suddenly stuck again).

Even if the three rules above are correct then changing the map to conform to those rules can actually make the path-finding worse as the map will already contain workaround fixes for the lack of data conformity. That is, if the original map was made without conforming to whatever the rules are then the original map-editor will have made trial and error changes to get the AI moving. Those original *fixes* can then become new problems to find when you make the data conform.

This is very frustrating.

nikolai1962
03-26-2007, 01:12
Back to the drawing board - apologies while i use this thread as a thinking pad :)

Case Study

Sticking to one theory at a time - non-convex regions. Just make the map fully convex first before trying out other things.


Testing with.

1)All factions set to a created AI profile that only lets them attack rebel regions.
2)Brigands/pirates greatly reduced.
3)Starting rebel garrisons removed.
4)Initial faction standings taken out so AI only dislikes rebels.


Benchmark - Vanilla map problems.

(There are more but these were the first i noticed)

England.
1) Attacks Caernavon, gets stuck in mountains two tiles away.
2) Builds army outside nottingham, (hidden in trees), also stuck.
3) Attack Rennes, if lose and retreat can end up taking a weird path behind Caen and getting stuck behind some forest.


Scotland.
1) Northern army takes inverness.
2) Southern army set to target York but stuck.


France.

1) Toulouse army set to target zaragoza but stuck.
2) None of initial french regions seems to see bordeaux.
3) Paris/Rheims seem to target Bruges after the initial french targets are taken but stuck.


Spain

1) General Vaasco targeting zaragoza but stuck.
2) Generally target along west coast instead of closer regions - not exactly a problem but odd.


Portugal.

Prioritize west coast of europe instead of closer rebel regions.


HRE

Bologna stack targeting Florence but stuck (a guess as it doesn't leave city).


Hungary

Starting stack targeting Zagreb is stuck.


Russia

Starting armies find way to first two targets but new army built in novgorod targets smolensk and stuck.


(some of these won't happen with rebel garrisons removed - just reminding myself to check later)

~~~

So re-loading vanilla map files and starting again doing only these things.

1. Making the impassable terrain more blocky. Compacting mountain/dense forest and making the passes through them more distinct. Replacing stray pixels with woods/hills.
2. Making sure impassable desert and deep ocean don't have traversable terrain buried inside.
3. Making sure all lakes/internal water is the specific red the game generally uses for such.
4. Making sure the islands you can't land on are 100% impassable pixels, just in case.
5. Trying to find and edit all instances of non-convex regions.


~~~

Stage 1.

Started with scotland and worked across russia, the steppe and back round in a loop to hungary/vienna region - roughly a third of the regions checked. Thought i'd run a quick test to see what had changed so far.


The Good.

1) England now fine. Take Caernavon, York with no hitch.
2) France now sees and takes bruges.
3) HRE now takes Florence.
4) Stuck Hungarian army now moves.


The Bad.

1) Scotland now completely stuck - both northern and southern armies won't move.
2) France still can't see Bordeaux or Zaragoza
3) Spain/Portugal no change
4) Russia->Smolensk unchanged.
5) Hungary now can't find Iasi anymore.
6) New problem - egypt no longer sees Jerusalem
7) Possible new problem with both breslau and magdeburg - may just be AI has switched priority of taking settlements. Both taken but later and by different factions coming from different directions to vanilla.


The Oddly

Hungarian army that used to move from budapest towards zagreb now heads to prague despite mountains in the way. stops then heads for zagreb

~~~

This is the sort of point where before I'd start trying to change other things according to other theories but i'll try and stop mayself until i have a fully convex map. (Assuming i can spot all the non-convex tiles.)

~~~

Notes to self.


Current thinking vis a vis region interdependency.

1. Map changes in any region can affect all adjacent land regions - (certain).
2. The sea confers adjacency when it is working correctly (highly likely to certain).
3. all region data is inter-related and any data non-conformity anywhere can affect the path-finding in any region (possible).

possibilities re the sea region conferring adjacency:
a) shared coastline
b) shared coastline within certain range
c) global

case points
a) Behaviour of spain/portugal
b) road network in gaza (sometimes map edits change the roads in gaza to the way they'd be if cairo was a land neighbour but all the cairo-gaza border was impassable, like a river with no fords.)

~~~

New theory.

Even though armies can move diagonally I think the path-finding only works orthogonally (up-down/left-right)

So a region with a border like

MF
MF
F

where M are mountain tiles and F are fertiles tiles may glitch because when the impassable tiles are taken out of the equation you end up with

XF
XF
F

If the path-finding only works orthogonally this region would then become non-convex.

(Assuming impassable tiles must be taken out of the equation because of the small unlandable islands.)

~~~

Other theories

1) Not only must the region be convex but all movement in the region from one tile to another must be within the region. Not as impossible as it may sound).

2) Movement between two adjacent regions must take place within those two regions. The path must not cross into a mutually adjacent third region.

~~~

PFEs don't occur on a regional basis but on a region to region basis. A PFE is possible between region A and region B while region A to region C is fine.

PFEs can be uni-directional e.g region A to region B may not work while region B to region A does work.

(PFE = path-finding error)

~~~

AI stacks don't seem to have problems navigating to settlements within it's own regions.

~~~

Actually three cases of PFE

1) AI faction sees a region as a neighbour, sets a stack to attack but the stack has a PFE and doesn't move.

2) AI faction sees a region as a neighbour, sets a stack to attack, the stack moves to the target but gets stuck on a certain tile along the way.

3) AI faction doesn't seem to see the region as adjacent at all.


Consequence.

Areas like central europe with a lot of small regions with a lot of borders suffer from PFEs less because if a region has a PFE with one of its neighbour regions it will be attacked soon enough from another direction. Might be worth breaking up big steppe/desert type regions in cases where they only have one neighbour.

~~~


the distance between the centres of any two adjacent regions should not exceed 50 tiles

does this mean the distance between settlements or some mathematical centre of the region's tiles. could possibly glitch if shape of region was particularly weird?

~~~

(apologies again - if/when i have this finally figured out i'll make a proper path-finding tutorial)

nikolai1962
03-26-2007, 09:28
EDIT: deleted wrong info as i re-tested map changes with wrong mod sleeper out of sleepiness. apologies to anyone who i inadvertently misinformed.

~~~

Tip for checking map pathways/convexity etc.

Double spy movement points, move them to centre of each region then click end turn so you can see the green movement overlay as in the screenie.

(Turn 10 and all but one of the non-faraway steppe rebel regions gone hehe)

https://img219.imageshack.us/img219/7969/spythingwa6.th.jpg (https://img219.imageshack.us/my.php?image=spythingwa6.jpg)

Lusted
03-26-2007, 11:29
Any chance of you uploading the fixed map files at some point?

nikolai1962
03-26-2007, 19:40
Any chance of you uploading the fixed map files at some point?

Yes, that's definitely the aim but...

I was hoping no-one had seen the last post before i could change it cos yesterday i sleepily re-tested using the wrong mod folder - so it's not all fixed yet after all - argh.

Since found a bunch more non-convex tiles that i missed on the first sweep so all is not lost :)

When i've got it figured out and have fixed files and simple rules to follow then i'll definitely be uploading and tutorializing as i found out from my previous fixed rtw map the game is vastly better when the AI is performing as intended.

nikolai1962
03-28-2007, 15:06
Case Study part 2

1. Changed a chunk of the non-convex tiles as mentioned above. A quick test showed some definite changes in AI movement.
2. Found and changed a bunch more which didn't effect things much, at least in the areas i was focused on. Starting to think the convex thing was more of a minor thing than previously. Began making individual fixes for individual region problems.
3. Noticed i'd missed the non-convex caribbean islands. Changing those seems to have messed up a few of my individual fixes so currently back to original theory.

-->Non-convex tiles add some kind of distortion into the path-finding algorithm. The distortion may be semi-benign e.g an AI army ordered to attack a settlement to the south but it heads north one turn and then back south again, or it may lead to the AI army being stuck. The non-convexity may not be the specific cause of the stalling--it may be the distorted path breaks some other rule the algorithm uses.<--

The first bunch of non-convex tiles included most of the big chunks and most of the islands. This seemed to have a noticeable effect.

The second bunch were mostly small e.g a single tile on the wrong side of a river. These changes didn't seem to have much effect.

The last bunch were all islands. This seemed to have a noticeable effect.

Makes me think the distortion is greater when there is a larger gap between the non-continous region tiles. Or possibly the sea has an effect on all regions with a coastline so islands are specifically influential. Hmm.

~~~

Starting again.

nikolai1962
03-31-2007, 01:24
Embarassing thinking aloud when you're wrong. I think wishful thinking and having too many mod folders got the better of me. Fourth attempt making sure *all* non-convex tiles were fixed and *nothing* else changed and it's not the panacea i was hoping for. It does effect path-finding but in small, localized ways and not a general distortion of the algorithm. Bugger.

Condensed what i think i've learned into a set of guidelines here

https://forums.totalwar.org/vb/showthread.php?p=1485851#post1485851

I put it in the MTW2 forum as i was using the MTW2 map to test ideas. It's the same in RTW though. The trial and error method of fixing the path-finding is a little easier with the guidelines than just using pure guesswork but it is still a very slow process.

Far easier to set the movement rate to cover the average distance between two settlements on your map. Trouble is that makes the AI armies look like Rommel. Oh well.

Roman_Man#3
03-31-2007, 05:30
Place holder type post. I plan on using this post to put some stuff I discover. I will be working on the RTW map, but it wont be as thorough as your research Nikolai


Silly question, but how do you skip to a certain date?

nikolai1962
03-31-2007, 06:36
Place holder type post. I plan on using this post to put some stuff I discover. I will be working on the RTW map, but it wont be as thorough as your research Nikolai

Cool



Silly question, but how do you skip to a certain date?

Not sure what you mean. If you mean the start date of the game it is set in the descr_strat file near the top.

Roman_Man#3
03-31-2007, 06:40
I mean a console command. like

data -189

or something like that. To skip to a certain date.

nikolai1962
04-01-2007, 04:16
I mean a console command. like

data -189

or something like that. To skip to a certain date.

Don't know, sorry.

Makanyane
04-01-2007, 19:40
@Roman_Man#3 - You can use Epistolary Richards year jump mod - but I think only if you are running under the BI.exe
https://forums.totalwar.org/vb/showthread.php?t=65109

He's set up scripts to use the slavs who don't start on map, and Sassanids. I switched it for EoD to use two factions which weren't used in campaign but in descr_strat as dead_until_resurrected (as otherwise it can hang if your faction is fighting Sassanids when it stops). You could try experimenting with it under RTW - scripts are quite short and you only need to change faction names (in scripts and advice / triggers), but I suspect it might need a dead_until_resurrected faction, in which case I'm pretty sure you'd need to run it -mod under bi.exe. If you do that for testing and your mod is designed for RTW you should note what Monkwarrior said about getting completely different results when running RTW mod under BI.

If you can get it to work for RTW please do report. Btw, I don't know of any way to do it under console command or -ai.

nikolai1962
04-05-2007, 01:14
The AI has an odd preference for attacking settlements from the SW. I didn't notice this in RTW but maybe i just didn't notice it. Definitely happens in MTW2 and the path-finding seems mostly identical. Given a choice of routes to a city the AI seems to choose the one that will lead to a SW approach. Doesn't matter in wide open regions but in mountain terrain with narrow passes it can be significant as it may make the AI avoid or run into the mutually adjacent region problem. Or, in cases with very long narrow passes an AI army may go on a very long trek around the mountains trying to reach the southern end and get lost.

This also means AI factions will expand better to the north-east.

~~~

Added a couple of examples to the condensed path-finding thread.

https://forums.totalwar.org/vb/showthread.php?p=1485851#post1485851

nikolai1962
04-10-2007, 08:04
The AI path-finding doesn't seem to like settlements completely blocking fords. Which is a shame as i like to do that a lot. No wonder my test map got suddenly worse.

Adding little border regions in between two existing regions with a problem is proving to be pretty good in terms of effectiveness/time taken. Sometimes because of bridging a long gap with a one turn move to a settlement and sometimes because it fixes a path-finding glitch somehow.

Historical path-finding must have used a similar algorithm as changes to the spain regions on the vanilla map have come out looking quite close to the regions on some maps of medieval spain i d/l ed.

nikolai1962
04-15-2007, 07:57
Wrong about more stuff. Been googling, convex means something else when related to path-finding. Something about convex polygons. Other thing about disconnected chunks of regions will be part of that somehow but not the whole thing. Will figure it out.

Also in my googling, games apparently often use multiple path-finding mechanisms to improve game speed, some for long-distance and another for short. This would fit in with my observations that the path-finding messes up mostly between one and two turns away form the target whereas it can handle long paths well. Bit of luck i may be able to figure out what the map rules are by looking at this stuff.

http://en.wikipedia.org/wiki/Convex_polygon

praise google

nikolai1962
04-25-2007, 06:58
Nice bit of progress on the path-finding that seems to be fixing a lot of AI stalls.

https://forums.totalwar.org/vb/showpost.php?p=1518295&postcount=29

scroll to bit titled "New Theory".

nikolai1962
07-02-2008, 21:34
Final recap on this map stuff on the MTW2 version of this research.

https://forums.totalwar.org/vb/showpost.php?p=1959834&postcount=56

nikolai1962
12-21-2017, 23:55
10th anniversary (ish) update post...

#

Why Bother?

There's lots of epic mods for RTW and MTW but ultimately the thing that puts me off playing them for anything but the shortest time is the game's path finding (or the very long AI turn caused by increasing base movement to fix some of the path finding). My original plan was learn how to fix the path finding using the small vanilla map and then once figured out, apply it to the bigger maps of my fave mods. This proved to be too difficult but I recently had a third attempt at the vanilla map after a (very) long break so I thought I'd post some final conclusions on what the problems are and how they can be fixed (and they can be fixed, it's just takes a lot of time) and finally what, based on my experience, is the best way to go about trying to fix a big map if anyone ever decides to do so.

(I haven't played/modded any of the games after MTW2 but I know this path finding info is the same for MTW2.)

#

Problem

Flaws in the RTW (and MTW) path finding means the AI armies constantly stall while moving to attack settlements. When the pathfinding is working properly the AI is relentless but when it's not the AI is like a baybee.

#

Causes

The path finding algorithm itself works perfectly - you can see this when you select one of your own units and hold the right mouse button down - the game calculates the best path to the tile your cursor is over. A* path finding (or similar) is guaranteed to find a path if one exists if you give it enough time (and memory) to do so - hence the underlying problem (probably).

When the player is engaged with one unit the calculation time for the path is not an issue (although memory might be - notice the game will only allow the path to be calculated for around 40 or so tiles). However during the AI turn there may be hundreds or even thousands of path calculations to be done which could lead to long AI turns if the path finding isn't constricted/optimized in some way.

One way this is commonly done is by using regions. The game map is divided into regions and the game will generate a database of connected regions (this is probably what is in the map.rwn file) and so instead of an AI path being from from tile x to tile y (maybe 40 tiles separate) it becomes:

1) my current tile is in region A and
2) my target tile is in region C so
3) look in the database for the shortest path of regions between A and C

and if that list is region A -> region B -> region C then the path finding becomes:

1) find path from current position in A to the border of A and B
2) when crossed into B find path from B to border of B and C
2) when in (or near) region C move to target tile.

Doing this divides the path finding into smaller pieces which might then only require looking a dozen tiles ahead ahead instead of forty.

However if the map isn't set up just right then this process can glitch.

#

Three Main Types of Path Finding Glitch

Path finding algorithms generally require the map grid to be "convex" which basically means when moving within a region or from one region to an adjacent region there is no clipping through another region and if the path finding is split into two stages:

1) start region to a region adjacent to target region

and

2) adjacent region to target tile

that gives two ways to glitch.

1) adjacent region to target tile

This glitch happens in many places and is relatively easy to spot. What happens is the source and target are in adjacent regions but the fastest path to the target tile clips a 3rd region.

20364

Sidon and Damascus regions are adjacent but the fastest path from Sidon and some of the other tiles in the region clips through a third region (either Judaea or Antioch) which makes the path finding glitch and the army in question gets stuck usually until another army takes Damascus.

This can also happen when the two regions are only adjacent via a diagonal move and the *equivalent* orthogonal move clips into a 3rd region.

As mentioned the cure for this is making the regions "convex" which gets the name cos when the map grid is made up of tiles with the same movement cost the regions needs to be convex polygons.

https://www.mathopenref.com/polygonconvex.html

However when you have tiles with varying movement costs I'd guess the mathematical equivalent is


the fastest path from any walkable tile in a region to any other walkable tile in that region has to be completely contained within that region


and some equivalent rule for the region to region pathing (although my guess would be if all the regions are internally convex the region to region pathing is automatically convex also).

These glitches aren't necessarily cured by more movement points as the glitch is caused by the region clipping.

These glitches are ***much*** easier to fix if you know about the "toggle_terrain choke" console command which shows you the impassable and walkable tiles.

20365

(nb some of this kind of pathing bug have been fixed in the vanilla game e.g. if you remove the impassable tile shown in the top center of the above toggle_terrain image the road shifts and makes the fastest path to Petra clip regions and the army stalls.)

#

2) region to region pathing

This is either less common or just harder to spot and I think mostly involves cases where the region to region movement database gets mixed up in some way so the game thinks 1) two regions are adjacent when they're not or 2) doesn't think they're adjacent when they are or 3) the stored fastest path along a chain of regions is messed up for some reason.

There's a possible example of this kind of region to region clipping problem here.

20363

This doesn't happen every game as it needs the army in Petra to be assigned to attack Damascus and a specific combination of roads having been built when it is assigned but when it does you get a large army in Petra which doesn't move and no other egypt armies moving to attack Damascus - which is the usual sign an AI army is stuck.

If you start a game as egypt and take Petra and then hold down the right mouse button to show the fastest path to Damascus, then without roads the path (by regions) goes Nabatea-Judea-CoeleSyria

20366

...but after various road combinations are built it can go Sinai->Nabatea->Coele-Syria or maybe even Sinai-Judea->Nabatea->Coele Syria.

No way to be sure without knowing the source code but I think the AI army in Petra glitches here because the stored region to region path and the current fastest region to region path are different i.e. it may expect the fastest path to be from Judea to Coele Syria but it's via Nabatea instead.

#

3) A bridge too far

20367

This is very common - an AI will move to (or start the game at) a certain distance more than one but less than two turns of (80 MP) movement from their target and then stall. If you use move_character to move them closer, if roads get built, if they get a trait which boosts their movement, if you increase base movement points or any other thing that gets them within one turn's movement of the target they move and attack.

As you can probably see from the image there is no obvious logical explanation why the army gets stuck which is why it's very important to test which path finding bugs can be fixed with more base movement points. If you don't you can waste hours trying to fix a problem which is either a) not related to convexity or b) it is but it's related in an indirect way which is buried out of sight, like for example the target region's borders didn't get stored properly in the map.rwn.

I can understand the clipping issue cos it's extremely difficult to get the complicated RTW regions to be mathematically convex enough for the path finding but assuming the path finding is region to region first then switching to finding the target tile when close enough then it makes no sense to stop the region to region movement where the AI isn't actually close enough for the next stage of pathing to kick in and it seems to me this would be obvious in development so as it's so common *and* these type of glitches are mostly fixed by higher base movement points *and* higher base movement makes the AI turn take longer with the player twiddling their thumbs then...

my guess is the game was developed with higher base movement and as more factions were added and more AI units were moving around the AI turn got too long so they reduced the MP to 80 and it was too late to redesign the map around the new movement base.

#

4) Small Fry

There are other issues like the pathing seems to prefer settlements near the center of the region and doesn't seem to like settlements blocking fords/bridges and a lot more but the three main categories above are the majority and my guess is many of the little ones (and maybe the entire third category) may be fixed by making the map more convex overall so should be left to the end imo.

#

Solutions

So the solutions to the path finding problem(s) are

1) make the map mathematically convex
and
2) have base movement points that suit the map

#

New Problems

The new problems resulting from the solution are

1) making the map convex is very difficult, time consuming, frustrating and easy to mess up

2) the simplest fix for a lot of path finding is increasing base movement rate but this can make the AI turn drag on too long especially on a big map with lots of regions and moving units.

#

Convexity

Complex Cases

Making regions convex is much easier since someone discovered the toggle_terrain choke command which shows you the walkable and impassable tiles but it can still be difficult.

An illustration of toggle_terrain choke showing one example of the convexity problem.

20368

If you look at the region borders around the mountains in the lower center you can see the fastest path from one border tile to the other will automatically clip into the adjacent region. One way to fix this is to pull the border back towards the center, another would be to push the border forward.

This situation illustrates the general principle of making regions convex when they contain difficult terrain shapes which is you generally need to either 1) make a region smaller so it fits snugly inside difficult terrain or 2) make them bigger so the difficult terrain is buried inside the region and not on the borders (CA tried to improve the path finding of the Barbarian Invasion map in this way imo.)

#

Simple Cases

There are also simple cases. Unreachable tiles break the convexity rule and with terrain_toggle they are relatively easy to spot and fix. The vanilla map has a bunch.

20369

(nb in this case unreachable rebels can spawn on those tiles making rebel chasing AI armies glitch)

Also if a region has walkable tiles that are reachable but not from their own region then that will automatically break the convexity rule also.

20370

There are also some cases where it seems that if tiles are connected but only by diagonals then there may be problems but that may be a function of other issues so i'd leave them till later.

#

Increasing Movement Points

The problems with this are threefold:

1) A long AI turn is a drag no matter how good the rest of the mod is.
2) It doesn't fix clipping glitches (or maybe it fixes some but not all, can't recall).
3) It needs to be proportional to region/map size - increasing region size by 50% and movement by 25% probably won't help.

Even so unless the map is perfectly convex (where increasing base movement is not necessary) then increasing base movement is probably a necessary component of a fix.

#

Best Way to fix a Big Map?

1) edit the map separately

Lots of things can effect how well an AI faction expands: unit stats, recruitment, traits, unrest etc so if you're testing path finding map edits by how well the AI expands at the same time as changing other things then your other changes may make you go round in circles - so have a separate mod folder where you only change map stuff.

2) clear the decks

I'd clear out everything like complex trait systems, scripting, events etc from your separate map editing version of the mod that could distract from the map editing, slow down the AI turn or tempt you to start playing the game instead of watching the AI. You want the AI turn as fast as possible as you'll be doing it a lot.

3) provincial campaigns

Provincial campaigns within a mod folder are a neat way you can make map edits and still switch back to the original campaign map for comparison tests. It's also a safe way to version control your map editing. Create a "mapedit01" provincial campaign (there are tutorials for this), edit the map files there, and when you think you have a solidly improved version copy the map files to a mapedit02 provincial campaign and work from them so you can go back to 01 if you screw up

4) start simple

The simplest cases of non convexity are unreachable walkable tiles and walkable tiles in regions which aren't connected. I'd suggest trying to get all of those first as your mapedit01 version before moving on.

5) do a movement point test early

The way I test at the beginning is start a game with an out of the way faction, put everything on auto manage and then watch one of the AI factions expand for say 20 turns or so making notes of where one of their armies gets stuck. (A lot of them will have armies stuck on turn one.) Then do it again with more movement points so you can see which are fixed that way. You may eventually still want to edit those spots to make pathing easier (i.e. cost fewer movement points) but as you'll be changing a lot of other stuff to fix convexity it's more efficient to worry about them later. (And judging by my test maps in the past, making the entire map convex somehow fixes a lot of these glitches as well.) The bugs left after increasing base movement will then mostly be confused regions or clipping (aka convexity).

6) alternative setup for (5)

I found the most productive way was to strip out the strat file almost completely leaving just two factions with two settlements (any settlement not specified in the strat file is created as a rebel village). Put the first faction/settlement on an island out of the way (this will be your faction) and then put the other faction/settlement where you want to test the map - say one region in Iberia - and then watch the AI's first few moves making notes of where it gets stuck. Then move the start settlement to another region in Spain and repeat (nb the AI can get stuck going between two regions in one direction but not in the other) until you have a list of bugs for Iberia.

7) alternative to step by step approach

This may seem a bit backwards to some but how I would actually go about trying to make a big map convex after past experience is I'd keep a copy of the original regions files for future reference but then i'd erase/merge most of the regions to create macro regions which are naturally convex due to terrain e.g. Iberia, and then break the macro regions down into sub-regions. It's a lot easier to spot naturally convex sub-regions within these macro regions and do them first than it is to move around lots of existing region borders in a complex and cluttered map. Once you have the naturally convex macro and micro regions done then fill in the rest.

8) In other words

It's too much work for me but if I was advising someone else on how to fix a big complex map now I'd do the opposite of how I learned to do it. Originally I watched a standard mod and then gradually cut everything out but map related stuff and fiddled with the existing regions one by one coming at convexity from the wrong direction. Much better to *start* with region convexity in mind, hence start with big convex macro regions, test that works (if possible, the macro region settlements may be too far apart), then carve out any naturally convex sub-regions within the macro regions and then finally artificially make whatever is left over into convex regions (mostly by using dense forest borders).

(If the map is reasonably accurate then historical regions should arise naturally. Exceptions to this may be needing to split some historical regions into two pieces e.g. north and south or east and west of a river.)

#

In a nutshell

The best way to learn how to spot AI path finding bugs may be the way I did it originally which was

1) watch a standard game/mod run and note where the AI gets stuck
2) see which are fixed by increasing MP and which aren't (i didn't do this but should have done)
3) try and fix each glitch separately with map edits (but not the MP related ones)
4) eventually realize that when the map edits worked it was mostly by accidentally making a region more convex
5) consciously make regions more convex one by one
6) eventually get the whole map working

but the sequence I'd actually advise now is:

1) create a separate mod folder for map editing
2) strip out scripting etc that isn't needed for map editing
3) use provincial campaign folders for version control
4) merge/erase the original regions into naturally convex macro regions
5) create artificially convex macro regions out of the rest
5) carve out naturally convex sub-regions within the macro regions
6) create artificially convex sub-regions out of the remainder
7) test each step using a two faction, two settlement setup
8) from time to time run longer test games with the -ai switch to compare the new map's performance with the original

The End

ReluctantSamurai
12-22-2017, 18:10
Excellent work! :hail:

A lot of AI behavior that I've observed is now much clearer. It seems that the difficulties created by CA in switching to a 3D map were both unexpected and ultimately too time consuming to fix given the deadlines the design team had to work with. However, when it became apparent that AI turns were taking far too long to complete due to the intense # of calculations that needed to be done, I think some limitations on the game should have been imposed (not an easy decision when you are trying to create an award-winning game with huge mass appeal).

Perhaps reducing the number of factions:

Armenia is probably superfluous; Scythia in the time frame of the game is probably ahistorical; Rome, in reality should have only two factions (Julii and Scipii); Dacia is probably excessive; and perhaps Spain. The great conflicts between Rome and Carthage, Rome and the Barbarians, Rome and the Persians, and Rome vs the Hellenic States should have been the focus, IMHO, and would still have made for a great game:shrug:

Limiting the number of stacks a faction can have (including naval). Economically, this should have already occurred, but when AI factions get economic bonuses at lower difficulty settings, this allows for recruitment beyond normal means. Limiting the number of diplomats/spies/assassins at any given time might also have helped (and I assume the same map calculations are necessary for each one of those units as it is for an army stack), and has the added benefit of reducing "game clutter", as I like to call it.

I wish I had the time to tackle the map problems, as map-making has always been a passion of mine. Ten years ago, I made a whole series of maps for a WW II game called Pacific General. I got good enough at it that campaign designers were constantly asking me to create maps for their campaigns. In a much simpler system, a single map (which included the research of topographical maps, vegetations types, cities/roads/etc) would run 80 to 100 hours to complete. A campaign of 10 scenarios, with ten new maps, nearly 1000 hours~:eek:

I can only imagine how much time a completely revised RTW map would cost:sweatdrop:

nikolai1962
12-23-2017, 04:51
It seems that the difficulties created by CA in switching to a 3D map were both unexpected and ultimately too time consuming to fix given the deadlines the design team had to work with.

I think that was it.


reducing the number of factions...Limiting the number of stacks a faction can have...Limiting the number of diplomats/spies/assassins at any given time might also have helped

yes that is a big part of it - lots of units with bad path finding or fewer units with computationally expensive path finding


A campaign of 10 scenarios, with ten new maps, nearly 1000 hours

ouch

nikolai1962
12-24-2017, 15:17
addendum to latest update post #86

scrapped latest attempt at fixing vanilla map using the bottom up method (which is):

1) watch AI to see where it gets stuck
2) try to fix each one separately

to compare that with starting from scratch with the top down method (which is):

1) assume from the start that most path finding problems are connected to non convexity
2) mentally divide the map into its most naturally convex macro regions (e.g. Iberia)
3) make map edits that reinforce the convexity of the macro regions you pick
4) within each macro region rearrange the borders of its internal sub-regions to make each region more convex

early days but so far the top down method would appear to be about an order of magnitude better/faster. if this continues i may be able to enjoy RTW/MTW again. quite pleased

ReluctantSamurai
12-25-2017, 18:05
Here's a quick question...would some judicious re-routing of roads help? Seems like a lot of path-finding problems arise when a stack has to get to Province C from Province A via Province B:shrug:

Also, how much have you looked at the naval aspect of path-finding? Carthage, in particular, suffers horribly because the AI can't seem to identify viable targets, or even if it does, it can't decide how to get there. So many times I've seen Carthage recruit units, move them onto a fleet just off-shore, and then do absolutely nothing with them, even when Carthage comes under siege. Even worse, those units just sit there when Carthage falls, and many times lost with all hands when the fleet comes under attack and sunk~:rolleyes:

nikolai1962
12-25-2017, 23:04
would some judicious re-routing of roads help?

yes. when the game creates roads it picks the fastest path to the adjacent region's settlement which *should* reinforce convexity except that when there are two roads close together the game will often merge the two roads along part of their route which can then distort the fastest path.


have you looked at the naval aspect of path-finding?

not yet this time around but IIRC from the previous occasions the biggest problem with the AI's attempts at naval landings was retreat causing attacks by enemy fleets on AI fleets waiting to pick up an army which seemed to glitch the AI. Weakening the pirate ships helped.

As the land-based path finding improves you see a lot more naval landings.


Carthage, in particular, suffers horribly

yes, Carthage being such a pushover was one of my original motivations to look at the path finding.

nikolai1962
01-01-2018, 20:48
Case Study 01

One of the useful toggle_terrain console commands is "toggle_terrain region" which puts a region overlay on the map which looks like this:

20379

As the main (or at least the main consistently fixable) cause of AI path finding glitches are cases where an AI army is ordered to attack a settlement which it believes is either in the same or an adjacent region but the fastest path to the target is through another region this can be used as a relatively quick way of finding some of the biggest issues.

With toggle_terrain region on, start each faction in turn, then select a unit in each of their starting settlements and then hold the right mouse button to show their fastest movement path to each *adjacent* region's settlement to check if the fastest path clips into a third region. This won't show every possible glitched path in the game as an AI army might get assigned to attack a settlement from any tile (plus not all regions are owned by a faction) but it's a good start and can pick up a lot of major issues.

As you can see in the image above the fastest path from Asturica to Scallabis is fine, completely contained within the start and target regions.

(nb good paths like this can still sometimes glitch during the game if the path is blocked by something and there's an alternative path that does clip into a third region but these are temporary.)

The path from Asturica to Numantia is almost okay - the tile just to the north of Numantia is fine - the fastest path is completely within the start and target regions

20380

but the fastest path to Numantia itself clips through the Scallabis region (which would make an AI army glitch).

20381

In a lot of cases the only way to make the fastest path work is to greatly re-arrange the region borders but since the fastest path is nearly okay in this case we might only need to make a slight edit to make it work. We can see the ford between Asturica and Scallabis can be pushed left a little which makes the path below the river a little longer but that was not quite enough.

Another useful toggle_terrain command for situations like this is "toggle_terrain tiletype" which shows the tiletype and looking at this

20382

we can see the path from Asturica to Numantia north of the river - the one we want the AI to take - has to cross a ford by going up to a hill tile (near mouse cursor) while the path below the river - the one that clips - is longer but has open tiles all the way. So if we move the ford down one into the open terrain the total movement cost should decrease a little, maybe just enough.

Which it was.

20383

nikolai1962
01-02-2018, 00:37
Case Study 02

Using "toggle_terrain region" the Cappadocia region is adjacent to the Antioch region but the fastest path goes through Tarsus.

20384

However "toggle_terrain choke" shows all the adjacent tiles are impassable

20385

so the regions should be marked as non adjacent and the path via Tarsus shouldn't be a problem (and doesn't appear to be in game) and this is *generally* true in situations where all the adjacent tiles are impassable however from my observation it doesn't seem to be true in 100% of cases for some reason.

On my edited map the Carthage region is blocked from the Gaetulia region by impassable terrain

20386

and in this case I have noticed the occasional odd glitch which might be related to this (i.e. where Carthage should have been attacking Gaetulia but wasn't and all its units were messed up and milling about aimlessly). It might have been a naval landing gone wrong but another possibility I recently came up with is maybe it's the distance between settlements? A CA dude mentioned at one point that the path finding may glitch if settlements are too far apart and you can see here how the path finding arrow only goes a certain distance before it stops.

20387

So maybe if settlements are too far apart the game glitches on impassable borders?

Dunno - the Carthage thing is too random a glitch to test for specifically but as a general rule it may be worth checking settlements are all within the path finding arrow distance from each other. The AI generally manages with settlements that are far apart but regions like that are often deserts or steppe without a lot of impassable obstacles so the path finding glitching on impassable borders only when the settlements are too far apart is a possibility worth considering imo.

#

If true then it's easily fixed with new regions but apart from region borders, ford placement etc I currently want the edited map to still be as vanilla as possible so I'm avoiding adding new regions for now.

Ludens
01-02-2018, 11:15
Thanks for these experiments, nikolai1962!

I've linked to them in the Game Mechanics forum (https://forums.totalwar.org/vb/showthread.php?153191-Research-AI-and-pathfinding), to make them easier to find.

ReluctantSamurai
01-02-2018, 14:38
I'm gradually getting psyched up to delve into RTW map-making/editing:yes: My work load is going to get significantly lighter in the near future, so I will have some free time. I'll have to get familiar with all the editing tools and how to manipulate them before then....so

...are all map editing commands done through the console, or are there third party tools to use?

nikolai1962
01-02-2018, 17:12
I'm gradually getting psyched up to delve into RTW map-making/editing

It's actually semi-fun now I've figured it out better. Originally I didn't know about toggle_terrain or the convexity issue so i did it all by trial and error and even a small map was a total nightmare but now it's not so bad.

I'm a short way away from finishing up on the vanilla map (as much as i can without adding extra regions) and after I've stashed that version somewhere safe so i never have to do this again I want to try a few separate experiments on a copy to see how best to deal with very mountainous regions and then after that look at the BI and MTW2 maps to see if they are equally quick (at least relative to last time).


...are all map editing commands done through the console, or are there third party tools to use?

the commands which show different map overlays (toggle_terrain region/tiletype/choke etc) are all console commands.

map editing itself is done by editing the map files: map_features.tga, map_regions.tga and map_groundtypes.tga. I use gimp for this. There may be other useful tools but if there are I should probably know but don't :)

nikolai1962
01-03-2018, 19:12
this will be the new "update" post as i think i've found the fastest way to fix AI path finding with the least effort

so ignore all the stuff i said previously, instead...

New Sequence

1. start up the game/mod you want to map-check with each faction in turn

2. bring up the regions overlay with the "toggle_terrain region" console command

3. for each settlement select a unit in the settlement and use the right mouse click to show the fastest path to the settlement in each *adjacent* region

20388


nb "adjacent" is defined as two regions having adjacent *passable* terrain. if *all* the adjacent tiles between two regions are impassable then the game *generally* seems to mark the regions as non-adjacent. there may be occasional exceptions to this where something has gone wrong but it is generally true.

4. note the cases where the fastest path between the settlements of two adjacent regions clips a third region (as it does it the above case of Sardis-Galatia) - these all need to be fixed as these are the primary cause of the AI path finding going wrong

5. also note the cases where the path finding arrow runs out before it reaches the target settlement - I think this can cause problems *sometimes* for an as-yet unfigured out reason and it's worth considering trying to fix them but not as a priority

20389

6. I said previously to fix unreachable tiles as a first step but as you sometimes change what tiles are unreachable when you change region borders this step can be left to the end.

7. only *after* fixing all of the issues found in step (4) and step (6) start the game up as a remote faction and turtle (or use the -ai command) and watch the AI move looking for additional glitches

(or don't, just assume this process fixed the majority of cases and play short campaigns with each faction for fun and see if you notice any additional AI glitches while you're playing)

This sequence is dramatically faster than my previous attempts.


nb I'm not saying the game does path find like this (fastest path from settlement to settlement). I'm saying this process will highlight places in the game where the AI will often get stuck.

#

Reasoning

the underlying principle behind this sequence is the same; it's simply much more efficient

1) the path finding works (as shown by the player's path finding arrow)

2) path finding has a computational load

3) the game reduces the load by
a) limiting the number of path finding iterations allowed (as shown by the path finding arrow stopping after a certain distance)
b) using region to region pathing first and then unit to target pathing when close enough

4) path finding glitches occur when:
a) a unit in region A tries to path to a target in region A but the fastest path clips a different region
b) a unit in region A tries to path to a target in an adjacent region B but the fastest path clips through a third region C
c) *maybe* when the game's region adjacency database gets messed up somehow
d) temporary e.g. enemy unit blocks a valid path and the alternative path glitches

5) the perfect solution is making the map 100% "convex" which in this context means


the fastest path from any passable tile in a region to any other passable tile in the region is completely contained within that region

however this is very difficult and time consuming and what this new sequence does is recognize the AI uses some paths e.g. the ones between settlements, an order of magnitude more often than others and so glitches there are much more critical - so doing it this way round means you can fix 80% of the problems with maybe 20% or less of total necessary effort and far less time.

#

As I'm trying to find the fastest way to do this I moth balled the vanilla map editing i've been working on and started again from scratch on the vanilla map to compare speeds and this method is dramatically better.

On the vanilla map i found 26 region-pairs where the pathing broke the rule (i may have missed some).

(I knew almost all of them anyway from watching the AI get stuck but this method is much faster.)

There's also at least a dozen cases of the settlements being too far apart for the path finding arrow which may or may not be important and i'll worry about later. (I think it's worth having the list so if you notice something odd happening that has no region-clipping explanation then maybe it's connected to this.)

I'll be posting up how i fixed some of the 26 region-clipping cases from the vanilla map (although i've mentioned some of them before on this and other threads).

nikolai1962
01-03-2018, 20:57
Case Study 22, Sardis-Galatia

with the region overlay on you can see the settlement to settlement path clips the Pergamon region

20390

switch to the "toggle_terrain choke" overlay to see if there is an easy fix moving region borders or rivers/fords

20391

and if not try "toggle_terrain tiletype" to see if there is an easy fix through editing terrain type.

20394

In this case the easiest solution is moving the Pergamon border back a couple of rows.

20392

nb when you change anything you need to check it hasn't caused new problems among the regions adjacent to the one you edited.

#

For a long time I thought diagonals were a problem for the game's path finding and spent hours making all the paths orthogonal but that was wrong - the problem is diagonals near region borders are often the place where this region clipping problem occurs. Anywhere on the map where 3 or 4 regions join at a single point (as in this case) are prime candidates for this path finding bug.

This type of glitch can be 100% prevented by placing an impassable tile in the right spot at the junction of 3+ regions however I'd advise you do it at the end as there's a lot of places like this and the right spot depends on where the region borders are and you'll likely be changing region borders a lot.

I did it for this case as an example (if you can see the dense forest tile).

20393

A lot of the 26 cases I've spotted from the vanilla map are a simple as this to fix (although not all).

nikolai1962
01-03-2018, 22:18
Case Study 23, Cappadocia-Galatia

fastest path clips into the Cilicia region

20395

same thing looking at in with the choke overlay

20396

bunch of ways to fix it but the simplest was nudging the upper ford down a few tiles

20397

ReluctantSamurai
01-04-2018, 13:38
so ignore all the stuff i said previously

:lost:

:laugh4:

The design team must have REALLY been pressed for time to have missed such simple fixes as these:wall:

nikolai1962
01-04-2018, 22:02
ReluctantSamurai

Yeah, I guess the people doing it were like me and either didn't know or didn't fully understand how the pathing worked so were operating on guesswork and trial and error.

#

Case Study 19, Alexandria-Petra

fastest path clips into Judea

20398

with choke you can see an impassable tile - maybe an attempt to fix a problem?

20399

the AI doesn't always get stuck here, it depends on which army gets assigned to attack Petra and where it starts from but when they do the army is generally just before the diagonal clipping move

20401

moving the impassable tile down one row forces the roads to Judea and Petra to split sooner and prevents that move

20400

nikolai1962
01-04-2018, 23:55
total number of region pairs i've found with clipping is now 30, done most of the simple ones, leaving the harder ones to last

Case Study 29, Salona-Patavium

slight clipping

20402

easily fixed by changing ownership of a couple of tiles from Illyria to Salmatia

20403

not a big deal but it makes the silver look like it's in Dalmatia so nudge that up one tile in descr_strat (moving resources in descr_strat when you change region borders is one of the few non-map file changes needed).

#

Case Study 30, Epirus-Illyria

Epirus is adjacent to Illyria (the mouse cursor is over the mountain pass that makes them adjacent) but the fastest path is through Dalmatia.

20404

looking at the map in choke view there's no obvious way to change the path so need to change the region borders instead

20405

I could block that pass (thus making Epirus-Illyria non-adjacent) by moving the Macedonia border to the left or Dalmatia to the right or I could move Illyria down or Epirus up so all the tiles along the fastest path are contained within Epirus-Illyria (so no region clipping) however wherever possible I like to make the region shape historical so in this case after looking at a few old maps I moved the Epirus border up so the fastest path is contained within Epirus.

20406

(Illyria lost an olive oil resource so i should move that)

nikolai1962
01-05-2018, 18:13
still putting off doing the bigger changes in case it messes everything up so thought i'd look at one of the cases where settlements are too far apart for the right-click path finding (which may not be important but... maybe it is)

anyway Tingi->Cirta is fine

20407

but oddly enough Cirta-Tingi is one tile short

20408

if you build roads just in the Tingi region then path finding from Cirta-Tingi can reach substantially past Tingi

20409

but if you build roads only in Cirta region the maximum path finding range is now actually a tile shorter

20410

the fastest path goes around the nearby river

20411

which if you look at it in choke view is a diagonal

20412

and roads won't form if there's a diagonal, only orthogonally, which forces the road to Tingi to detour around to the ford.

Adding a ford closer to the direct path brings the Cirta-Tingi path within path finding range

20413

alternatively, extending the Cirta region to the left brings the Cirta-Tingi path within range of the right-click pathing arrow if Cirta builds roads (as in this case more of the fastest path is along roads within Cirta region).

20414

As the game often seems to add the "wild animal" trade resource in threes and the new region border at the river is the historical border between Mauretania-Tingitana and Mauretania-Caesariensis my guess is this is how the region was originally and it was changed to try and fix something (as when you're map editing by guesswork it's very easy to fix one problem and create a new one at the same time). So in this case I'll leave the wild animals resources in the Cirta region.

#

So what does all this suggest?

1) the CA dude way back when said the path finding could sometimes go wrong if settlements were more than around 50 tiles apart. I think this shows it's not 50 tiles but some amount of path finding iterations that on average comes to around 50 tiles. In some cases it might be less.

2) movement costs may matter indirectly as finding the fastest path through difficult but not impassable terrain is an obstacle also, just not as much of one as impassable terrain - so roads and difficult terrain may have an effect there

3) also when roads form along the fastest path between two regions they reinforce convexity but when they don't, they weaken it (which happens a lot as the game likes to average out multiple roads). This may not matter in most cases but it might occasionally thus forcing roads to follow the fastest path probably helps sometimes (but maybe only occasionally).

4) From observing I used to think the path finding had a problem with diagonals generally but that's not the case. Diagonals near region borders can create paths which lead to region-clipping and diagonals elsewhere can block optimal road formation (which can occasionally lead to region clipping) but otherwise the path finding handles diagonals fine. As diagonals can prevent roads forming this means deliberately adding diagonals to force roads to go where you want might actually be a useful tool.

5) *if* settlements being too far apart can cause glitches in the formation of the map.rwn file then roads bringing settlements within range during the game won't help but if it only causes glitches during the game then settlements being close enough after roads are built may be good enough.

(I won't do it on the base version of the map as I want it to be as vanilla as possible but in the future I think i will eventually add regions where they bring settlements within range of each adjacent region, just in case it helps.)

6) a lot of modders deliberately made some settlements very far apart in the hope it would stop the AI expanding in a direction they didn't want but in my experience it mostly doesn't work and often it just makes the AI waste even more resources sending multiple armies crawling slowly over 100 tiles of desert. In cases where you don't want to use impassable terrain to block this I'm thinking a better solution may be the exact opposite and give the unwanted direction a close by region with very high unrest instead. So instead of a dozen armies crawling over the desert towards a very distant settlement the AI just has one army constantly retaking the same close by settlement.

Just a thought.

nikolai1962
01-05-2018, 23:12
Case Study 24, 25, 26, Armenia->Pontus, Armenia->Cappadocia, Armenia-Media

24: Armenia-Pontus are adjacent by one route but the fastest path clips the Colchis region

20415

25: Armenia-Cappadocia is too far to be sure what the fastest path is - it might be like this which would be okay

20416

or it might be like this which would clip Pontus

20417

if we look at the pathing arrow from Armenia to the ford

20428

and to an adjacent tile on the other route

20429

we can see both routes have very similar costs in pathing terms with the coastal route just pipping it.

looking at the tiletype overlay we can see why - the coastal route is longer but has mostly open tiles while the inland route is shorter but mostly hills.

20430

so we could change a few tiles along the inland route from hills to fertile tiles to make that route the fastest but there might be another way which could fix both armenia-pontus and armenia-cappadocia at the same time.

if we look at the current Armenia-Cappadocia path we can see it goes a long way round

20431

whereas the route near Pontus looks a lot shorter

20432

however that route is currently blocked by the river and also, as Armenia is already adjacent to Cappadocia by another route, then if the fastest Armenia->Cappadocia path clipped through Pontus that would glitch the pathing.

if i push the cappadocia region up a little so armenia is no longer adjacent to pontus (except via impassable mountain tiles) then the game won't mind pathing to pontus via cappadocia and at the same time pushing the river near pontus up a tile creates a more direct armenia-cappadocia path which looks like it might be the fastest.

which seems to work (the distance is still too far for the pathing arrow to get the whole path but when cappadocia builds roads it's long enough for the cappadocia-armenia pathing)

20433

and the Pontus->Armenia pathing arrow is also within range

20434

but not Armenia->Cappadocia when only Armenia has roads

20435

however Armenia->Cappadocia does come within range when both regions have roads thus confirming it's both the fastest path and that the game knows it

20436

#

26: Armenia-Media

Armenia is adjacent to Media by this route

20418

but the fastest path is much more direct and clips through Atropatene

20426

one way to fix this might be to give the chunk of Media between the two rivers to Atropaten (light blue) so armenia-media are no longer adjacent.

this would make hatra-atropatene regions adjacent and the path between those seems okay if Armenia loses a tile or two.

20419

it would also make atropatene-babylon adjacent but as it's too far for the pathing arrow it's hard to say if the fastest path would be this

20420

which would be okay, or this

20421

which would cross through media and break the region clipping rule.

After editing the region it seems that without roads the babylon-atropatene path would cross media (possibly causing the AI to glitch)

20422

with roads in Media this path is reinforced (and as roads have increased the range of the pathing arrow so it now reaches all the way to Phraaspa we can be sure it's the actual fastest path)

20423

however with roads in Atropatene it seems the fastest path switches to go through Atropatene which should be fine

20424

so the Babylon-Phraaspa pathing might not cause a problem or if it does it might fix itself when Phraaspa builds roads but if it does turn out to cause a problem i can just remove the bridge between Atropatene and Babylon so the regions no longer count as adjacent.

I wouldn't usually like to remove a path between regions to fix a problem but I don't mind in this case as the Persian Royal Road (in terms of RTW regions) went Babylon-Hatra-Cappadocia so Hatra as a crossroads region seems appropriate.

#

After some testing this seems to work well. Generally changing a bunch of regions at once leads to new glitches somewhere but if so I haven't spotted them yet.

#

Anyway hopefully these case studies will prove useful to someone. I won't go through all the 30 or so i noticed on the vanilla map as it'll mostly be repeating myself.

The general pattern is the changes needed are either a) small edits involving: fords, river placement, a few region ownership tiles or placing an impassable tile or two or b) a rubik's cube type deal where you have to juggle a bunch of regions at once to ensure only the ones with valid fastest paths are adjacent in game terms (i.e. having a shared border with passable terrain).

ReluctantSamurai
01-09-2018, 01:16
From what I've observed, the Middle East appears to have more than it's share of path-finding problems. In looking at the RTW map in it's entirety, perhaps it's just my imagination, but there seems to be a lot more twisting and winding of roads through mountains and rough terrain than anywhere else:shrug: I've never cataloged it, but just like Carthage seems to get buried under a slew of path-finding problems in the Western Med, Seleucia mirrors that problem in the Eastern Med. They rarely ever target the nearest rebel town of Palmyra (in the east), or Halicarnassus (in the west). Getting into the Lycia province is the most puzzling, as it's just a stone's throw across the river~:confused:


movement costs may matter indirectly as finding the fastest path through difficult but not impassable terrain is an obstacle also, just not as much of one as impassable terrain - so roads and difficult terrain may have an effect there

Although it involves considerably more tinkering, increasing movement rates might be a good follow-up to map alterations in aiding path-finding problems...


I'm thinking a better solution may be the exact opposite and give the unwanted direction a close by region with very high unrest instead. So instead of a dozen armies crawling over the desert towards a very distant settlement the AI just has one army constantly retaking the same close by settlement.

That's just evil~D


as the Persian Royal Road (in terms of RTW regions) went Babylon-Hatra-Cappadocia so Hatra as a crossroads region seems appropriate.

Although it's a topic for a different thread, the Persian Royal Road was as advanced as anything the Romans built. I had some links somewhere covering the topic, and it makes for some fascinating reading (and caused me to give the Parthians the "Paved Road-building" capability).

In any case, fabulous work:hail:

nikolai1962
01-09-2018, 06:50
From what I've observed, the Middle East appears to have more than it's share of path-finding problems.

agree - that whole quarter of the map and the bit around massilia/lugdunensis are the two worst imo


They rarely ever target the nearest rebel town of Palmyra (in the east), or Halicarnassus (in the west). Getting into the Lycia province is the most puzzling, as it's just a stone's throw across the river

yes, it's the strangest thing as when pontus takes sardis they usually go on to take halicarnussus with no problem so it's not a persistent clipping type problem, it's something else. there's a few places like that which i've never managed to figure out but i'm hoping they're a side effect of problems elsewhere and so will eventually clear as other problems are cleared.


Although it involves considerably more tinkering, increasing movement rates might be a good follow-up to map alterations in aiding path-finding problems...

Yes definitely - increasing MP fixes a lot of problems on its own. I kept them at 80 while doing this as i specifically wanted to see where the AI gets stuck so I could try and fix it but the plan was always to increase MP when i was done, Although I'll probably do it by giving movement traits to AI generals.


Although it's a topic for a different thread, the Persian Royal Road was as advanced as anything the Romans built

yes, knowledge getting lost after a civ collapse and then reinvented somewhere else


In any case, fabulous work

Thanks, I'm pretty pleased to be honest as I can finally enjoy the game again.

In fact took a break from map editing to play a bit before moving on to the next stage - trying to ensure every settlement is within pathing range. Will be interesting to see if that fixes the remaining unexplainable problems or just creates new ones :)

nikolai1962
01-11-2018, 23:14
breakthrough on the multi-region movement - kicking myself as it's obvious once you see it but I didn't have such a clear example before...

adding some regions in parts of the vanilla map to make sure all settlements in adjacent regions are within pathing range of each other and got a situation where Hasdrubal regularly got stuck on the single blue tile by the mouse cursor in the middle of the image below (en route from Carthage via the Leptis Magna region to the desert region in the lower right corner .)

20442

(I knew the army started in Carthage cos it was Hasdrubal and not a randomly named captain and he hadn't moved out of Carthage yet.)

(nb portions of the map like this where 3+ regions join at a point are prime contenders for the region clipping bug.)

looking at the settlement to settlement path from Carthage to the settlement in the target region there are no obvious issues

20443

however they are not adjacent regions so if we assume the AI uses region to region movement in this situation what might that be? assuming the game knows the region to region path is Carthage region ->Leptis Magna region-> desert region then let's say it's first move is to calculate the fastest path to the closest border tile of the region adjacent to the target region (i.e. Leptis Magna region) which by eye looks like it would be this.

20444

the fastest path from that tile to the target settlement also seems okay

20445

however the path to the closest tile in the target region clips

20446

placing an impassable tile in the right spot should stop the path clipping and fix the problem

20447

which it does (at least from that direction).

20448

#

this is actually a more general case of the region clipping previously mentioned in that the fastest path between two *adjacent* settlements will in most (all?) cases automatically include the fastest path from start settlement to closest passable tile in target region.

#

from past observation my theory was the AI used region to region movement to get to an adjacent region and then switched to finding a path to the settlement itself but this example suggests it paths to get in the actual target region first. this kind of pathing glitch happens a lot but it's usually hard to be sure what the precise cause is as unless it happens in the first few moves you generally don't know where the AI army was when it was assigned its target but in this case by lucky accident the combination of a) the odd shape of the target region in this example (a temporary thing while i juggled region borders) and b) it being Hasdrubal and very early in the game made it obvious.

nikolai1962
01-16-2018, 20:59
the previous post implies that in multi-region movement the key is not the overall settlement to settlement path but

a) the armies start tile to the nearest (or fastest to reach) tile of the next region in the region-to-region path

b) the path from that resulting tile to the fastest border tile of the next region in the chain

and finally

c) the path from the resulting border tile in the target region to the target settlement

an example of where this can happen

#

on the vanilla map the distance from campus alanni to a border tile of the caucasus regions is beyond path finding distance

20466

(nb there's no way to know if the game's internal max path finding distance for AI armies is the distance allowed the player using their right-click movement but it's the only clue available)

(nb AI armies won't always be assigned targets from a settlement tile - they could be in any tile in the source region - but they often are in the settlement or the waiting spot outside the settlement (usually the tile SW of the settlement if it's not blocked) so measuring from the settlement is a good first iteration)

from the other direction the path from a caucasus region settlement to a steppe border tile is well within range

20467

and the steppe border tile to the settlement is within range also

20468

there are multiple ways to fix this:
- move the campus alanni settlement down
- push the border of the caucasus regions up
- add an extra region
all of which can create new pathing problems so need to check afterwards.

I added an extra region - imaginatively titled campus_alanni02

20469

#

another example

on the vanilla map the arabia settlement is distant from some of its adjacent settlements so the borders of those regions are pushed out such that the distance for the nearest border tile to the arabia settlement is within range e.g. vanilla Palmyra region

20470

and vanilla Bostra region

20471

however now i'm pretty sure i can fix most pathing problems i've reactivated one of my original aims which was to make regions (or a cluster of regions) have the same shape as the roman provinces they eventually became a part of so that if you're playing Roman you can make your empire look like historical maps and as a result made the distance between the Palmyra border tile -> Arabia settlement too far.

20472

No problem though - easily fixed as long as you know what to look for.

ReluctantSamurai
01-19-2018, 13:39
A lot of this is much like the process of map creating in Pacific General that I did. Play-testing the map to make sure units behaved correctly was a large part of the time involved. The finished map often had many, many alterations from the beta version...

nikolai1962
01-19-2018, 15:47
yes exactly - we can't change the AI code but we can change the map to cope better with the flaws in the existing AI code

nikolai1962
01-28-2018, 22:46
a type of glitch, a minor addendum and a major breakthrough

1) a type of glitch

generally if the AI is stuck it can be hard to spot as often it is just one stack among many but then there's the other kind

20518

this can happen when
a) a faction has only one potential adjacent land target and the army assigned to it is stuck
b) a faction has no potential land targets and the a naval landing has glitched
c) a faction temporarily has no adjacent land targets cos it's at peace with all it's neighbors - this generally only happens briefly after defeating one enemy faction and before starting a new war with a neighbor

in this case it was (c) - Macedon has just defeated Greece and was at peace with all its other neighbors

#

2) a minor addendum

the fastest way to clear most path-finding glitches is to check the settlement-to-settlement path between adjacent regions looking for any clipping issues however

vanilla Macedon: army in Larissa moves out to city "waiting spot" (usually the tile SW of settlement unless it's blocked) and waits, getting extra units from Larissa each turn and getting the Captain promoted to general (the AI will often promote a captain of a stack that has been assigned a target settlement)

261BC

20519

and waits 254BC

20520

and waits 226BC

20521

eventually (209BC) another faction takes the target settlement (Athens)

20522

and the stack moves

20523

but after 100+ turns of not expanding and paying the upkeep for a full stack that isn't doing anything it's a bit late

20524

#

Solution

if you look at the fastest path from Larissa to Athens it seems okay

20525

and to be thorough the fastest path from Larissa's waiting spot to Athens also

20526

but if you move the mouse around the tiles adjacent to the target settlement rather than the settlement itself the path clips the Corinth region

20527

also, just to be thorough again, on the assumption the AI doesn't calc settlement to settlement but 1) start tile to fastest path to a passable tile in the target region and then 2) from that tile to the target settlement then check that too - which clips also if for whatever reason the path finding chooses to go that way around the mountain

20501

on the assumption the path-finding does go that way for some reason it is easily fixed by giving the tile it clips through to the Athens region - which seems to work

#

so the expanded sequence is

1) check the fastest path settlement-to-settlement doesn't clip
2) check the fastest path from the start settlement's waiting spot to the target settlement doesn't clip
3) check the fastest paths to tiles adjacent to the target settlement don't clip
4) lastly check the fastest path from the start settlement to a passable tile in the target region is not different from the fastest path overall

#

example of last point

the fastest path from Narbo to Lugdunum seems okay

20528

(actually it's not as although the diagonal from Narbo region to Lug region doesn't clip, the underlying orthogonal path can only go either right and up or up and right and the latter is blocked by the mountain tile so the orthogonal path clips the Massilia region - however it can easily be fixed by removing that corner tile from Massilia)

however the fastest path from Narbo to the nearest passable tile in Lugdunensis is like this

20529

and the fastest path from that tile within Lugdunensis region to Lugdunum clips back into Narbo region.

nikolai1962
01-28-2018, 22:57
split into two posts as too many attachments

#

3) a major breakthrough

path finding problems are mostly in three categories
1) problems at the very start of the game which i could never figure out till now
2) problems that recur consistently during early expansion
3) problems that mostly occur later in the game and more randomly depending on the ebb and flow of expansion

I'd given up on what caused (1), fixed most of (2) and was finishing off (3) and just realized how to fix (1).

example Thrace faction, Sautes

at the beginning of the game before factions are at war with other factions they target nearby rebel regions so Sautes ought to target Byzantium

270BC

20530

268BC

20531

265BC Sautes has died but the now Captain led army still doesn't move as Macedon heads for Byzantium

20532

260BC if Macedon had succeeded the army would have been given new orders and moved off but they didn't so it's still stuck

20533

there's a bunch of these in vanilla among the factions e.g. Vindex for the Gauls, Arsaces for Parthia etc and glitches like this right at the start of the game have a compound effect on a faction's expansion.

there are three ways armies like this become unstuck during the game:

1) another faction takes the settlement so the stuck army gets new orders
2) the distance between the stuck army and the settlement comes within one turn of movement (roads are built, general gets a movement trait etc)
3) occasionally attacking or being attacked by a nearby rebel spawn

you can "fix" these problem by making the path one turn only through one or more of: increasing base movement points, giving the general a movement trait, building roads in advance, moving the general closer, moving the settlement etc but this is more like over-riding the problem than figuring it out and fixing it.

for example Sautes with base movement points set to the vanilla 80

20534

with base movement points increased to 120 he is within one turn of Byzantium

20535

and attacks first turn

20536

#

The clue i missed is the rare occasions when a stuck army moves to attack nearby rebels.


the bug is an army assigned to attack an adjacent rebel settlement in the first turn before it has moved is not fully initialized in some way and only becomes so after its first move.

so counter-intuitively an actual fix is to move the army further away - specifically to a region that isn't adjacent to the the target settlement so the army has to do region-to-region movement first, in this case reduce MP back to 80 and move Sautes into the other Thrace faction region

20537

and he quite happily find his way to Byzantium over the next few turns

20538

20539

20540


update: with further testing it turns out the army doesn't have to be in another region just > 2 turns move away from the target settlement so < 1 or > 2 turns away is okay but if both > 1 and < 2 turns away it gets stuck. useful to know as any time you change MP some armies may become stuck and some unstuck.

#

there are a bunch of these among the various factions e.g Vindex in his original spot would never move unless you made Massilia within one turn of movement

20541

but if you move him just over the region border into Aquitaine

20542

he'll quite happily find his path to Massilia

20543

20544

20545


update: actually only 3 in the vanilla game: Vindex, Sautes and Arsaces, as the others are > 2 turns away from their targets.

#

took me 10+ years but finally figured it out.

ReluctantSamurai
01-29-2018, 13:56
the bug is an army assigned to attack an adjacent rebel settlement in the first turn before it has moved is not fully initialized in some way and only becomes so after its first move


with further testing it turns out the army doesn't have to be in another region just > 2 turns move away from the target settlement so < 1 or > 2 turns away is okay but if both > 1 and < 2 turns away it gets stuck

Some weird internal thing? Does the same thing happen with a faction at war with another faction, rather than rebels?


but after 100+ turns of not expanding and paying the upkeep for a full stack that isn't doing anything it's a bit late

Seen that scenario played out repeatedly:no:


took me 10+ years but finally figured it out

:stupido2: Sometimes, the solution isn't in a straight line...~D

nikolai1962
01-30-2018, 01:37
Some weird internal thing?

Yes, I've noticed something like this before with armies moving to a target and getting stuck > 1 but < 2 turns away. Just a guess but I think there are two bits of path-finding code, long-distance and short-distance and the game switches from one to the other when an army is "in range." However my guess is the game was originally developed with higher base MP and the "in range" code has a glitch somehow related to that i.e. it somehow switches too soon.


Does the same thing happen with a faction at war with another faction, rather than rebels?

good question - vanilla factions only start at war with rebels and this bug only seems to apply to armies given orders to attack before they've moved and so by the time the factions get into wars with each other most of the starting armies have moved (apart from the ones that are already stuck). However it might happen in mods that start factions at war with each other?

will have to try and test for this

(though now i think of it scipii have no available rebel targets and begin a war in sicily soon after the start - will have to check to see what happens there)

the only other way i could imagine this happening is if a newly spawned general was given a target (rebel or faction) before they moved out of a city.


Seen that scenario played out repeatedly:no:

yes - a faction at the start may only have one or twp targets so if one is bugged their expansion is handicapped from the beginning.



:stupido2: Sometimes, the solution isn't in a straight line...~D

all's well that ends well

#

vanilla armies that start outside settlements (may have missed a few)

julli (2)
1) rebel target < 1 turn away
2) watchtower

brutii (2)
1&2) no available land rebel target -> naval landing

scipii (1)
hmm?

gauls (2)
1) rebel target (stuck)
2) watchtower

britons (2)
1) watchtower
2) no available rebel target (moves to settlement)

dacia (1)
rebel target but > 2 turns away

thrace (1)
rebel target (stuck)

numidia (1)
rebel target > 2 turns away

carthage (1)
no land rebel target (on sicily)

egypt (1)
watchtower

parthia (1)
rebel target (stuck but only briefly as armenia takes target)

armenia (1)
watchtower

pontus (1)
rebel target > 2 turns away

key thing is it's easy to fix - just move the army closer or farther away

nikolai1962
01-30-2018, 06:48
Does the same thing happen with a faction at war with another faction, rather than rebels?

seems so - the Scipii are given Syracuse as a target by the senate but the army outside Messana is < 1 turn away so isn't stuck and attacks on turn one but if you move him > 1 turn's move away he doesn't move.

nikolai1962
01-30-2018, 19:38
this happens on MTW2 as well - most starting armies are either < 1 turn away or > 2 turns away from their rebel targets and so move to attack on turn one but a few are > 1 but < 2 turns away e.g. Vaasco for Spain and won't move. move Vaasco > 2 turns away from the adjacent rebel region settlements and he moves to attack on turn one.

only had a quick look but at first glance both Venice and Scotland also have a general stuck at the start for the same reason.

ReluctantSamurai
01-31-2018, 01:36
key thing is it's easy to fix - just move the army closer or farther away

I just don't understand why such a simple fix wasn't done by the devs:dizzy2: I can see missing problems a number of years into the game, but some of these stacks stalling within the first few moves should have been spotted if proper play-testing had been done:shrug:

nikolai1962
02-01-2018, 02:53
I just don't understand why such a simple fix wasn't done by the devs

if you spend time watching the AI move you notice it straight away but when i was working on this the first time 10+ years ago I assumed it was a path finding problem rather than a bug and so spent *hours* editing the map around Massilia to try and get Vindex to move - and the same later with Vaasco in MTW2. it being a simple bug like this never occurred to me until this attempt.

weird.

uanime5
02-21-2018, 02:34
I made a modified version of the descr_strat in which I added the maximum roads to every settlement to see how the roads link from one city to another. This makes it easier to see possible problems the AI may have. Attached is the descr_strat in case anyone wants to use it.

Found an issue between Tolosa and Burdigala. Unfortunately the screenshot won't upload.

Also some settlements didn't have any roads (unsure if this is a bug).

nikolai1962
03-25-2018, 12:33
uanime5

thanks


Also some settlements didn't have any roads (unsure if this is a bug)

roads only form if there's a complete orthogonal path between two settlements (up, down. left, right) even if the road is drawn with diagonals after being calculated - so it could be that.

(edit: also if a settlement/region isn't referenced in the descr_strat.txt the game doesn't throw an error it creates a rebel village without any buildings so it could be that also)

ahowl11
07-20-2018, 06:57
Any news here? Or is everything pretty much solved?