Some more observations on the Campaign AI
-----------------------------------------------------------------
Intrigued by the failure of the HRE to expand very far, and also by the priorities the AI assigns to settlements in the game, I played 30 turns as HRE in Barebones scenario. The AI was given total control of building and recruitment. (NB with auto-managing no agents are recruited or armies moved. So human player has to do these if they want them to happen.) Generally the AI adopted a balanced tax rate, except after capturing settlements, when it adopted a military stance.
I responded positively to all diplomatic contacts, but initiated none. All rebel armies were fought by the nearest garrison. Because the AI did not recruit any agents, I recruited priests, assassins etc to counter heretics. I did not declare war on any other faction (except when I joined a Crusade), and none declared war on me.
After battles damaged units were moved to where they could be repaired (if buildings had been built.) (NB no units were ever added to the recruitment queue or buildings added to the build or repair queues.)
Certain aggressive military adventures were attempted with the forces the AI provided:
Siege of Antwerp (T9) - BSing army attacked by defenders first turn and defeated by them - attackers retreated.
Siege of Prague (T20) - Successful (T24)
Join crusade on Cairo called (T28) (Actually joined a few turns later.)
(After T30 played another 40 turns to see what happens but didn't keep record of building)
(Joined another Crusade, again on Cairo; captured Antwerp, Florence, Bern all with the AI determining the tax rate and which units to build. Overall the AI does a very good job of managing the economy, even if its decision making on unit production is a little wayward at times. It is however very rigid in certain aspects, which results in newly captured settlements often failing to build new units or repair buildings quickly, they have to keep their position in the queues. Also found public order problematic in Bologna (probably resents having German govenor?)
As the overall faction stance is Balanced Smith, this should be balanced regarded production - with biases towards growth, taxable income, trade level bonuses (roads), walls and xp bonus buildings; whereas unit production should be exactly even, with no bias towards any particular type of unit. (This from CavalryCmdr's excellent essay on the subject) However production can be biased by strategic considerations, such as I'm under threat from an enemy so build defenders, our enemy has many cavalry so build more spearmen. Apparently.
Sadly CavalryCmdr does not seem to have delved further into working out the AI's production priorities in any detail (AFAIK.) So we have to rely on a certain amount of deduction with the caveat that this needs confirming from proper traces of AI decision making.
I have appended an Excel compatible spreadsheet showing what was built on which turns for HRE in the first 30 turns.
From this we can see that, as long as the AI has sufficient money it keeps building buildings. The AI seems to like a certain float for "discretionary expenditure" and for expenditure that isn't accounted for in the initial decision making phase for the human player (which presumably AI factions don't need so they can spend - it merely allows some cash for the human player to spend on agents, non-queued building, extra units etc. Given it's more economical not to duplicate code, one can guess that every faction has a slot if_player_human for this section that gets ignored otherwise.)
(NB although most buildings are "queued", the AI is quite capable of using some of the "discretionary money" to build single turn buildings such as dirt roads, small chapels, between the human player pressing end turn and the beginnings of a new turn. The turn a building is completed the queue is empty in that settlement but the AI regards it as occupied when deciding it's main spend. (The human player can add a building here if there is enough cash, but with the exception of single turn items, the AI usually waits another turn before starting another building for that settlement.)
The order for decision making is the order settlements are displayed in the lists on screen, which means that the settlements at the top of the list will tend to get the best buildings, but, by not starting building for multi-turn buildings until after the turn a building is completed, there is some scope for settlements further down the list to get new buildings, but that diminishes as the number of settlements increases (with the limiting factor that in later game stages the AI may not have enough money to build expensive buildings in the top settlements and so may build lower down the list until it has enough spare money (which it rarely has.) Which building gets built is down to several factors, and amongst those is likely to be a randomising factor, so the order of building will differ between settlements. Also with different start times (in turns) circumstances may change so priorities may also change.
One priority does seem to be true however. Wall upgrades are prioritised - presumably as they give happiness bonus and enable better units to be built and so score more highly than other buildings? In every instance once any existing buildings were completed the wall upgrades were started the next turn there was sufficient money. Although outside the time limit for detailed comment, by turn 70 Vienna had managed to get a merchant bank built! (not bad for early era! )
Regarding newly captured settlements a lot depends on the money obtained by sacking and the number of settlements without queued buildings. If there's a lot of money and nearly all other settlements are already building, then repairs may occur very promptly - having captured Cairo, for example, all damaged buildings were repaired within 2 turns! However I also noticed that the AI often builds new buildings before spending money on repairs. Prague got a new Grain Exchange and a Ballista Maker before the walls were repaired. From this one can deduce (with usual caveats!) that there is some algorithm that assigns numerical values to each building depending on what the build priorities are and (as in the invade decisons, the game engine works out the options and goes with whatever scores the highest, within the remaining budget.)
(note on modding and adding new buildings - these numerical values have to related to what the game engine already understands, so buildings that add happiness, allow better units to be built, increase public order; add to religion conversion etc can all be factored in, but it's unlikely to pick up on those which add traits to agents and generals?)
-----
Moving onto what units the game engine builds.
This is much more difficult to work out from observation as the human player inevitably has an input in what units get used and as the game progresses the interaction with other factions will also have be factored in. All one can say is that in this case the human player was only at war with one faction - Egypt (and no units were built in Cairo on both occasions it was occupied) and did not belong to any alliances, then the test case is representative of a fairly neutral set of circumstances. What the AI would build if it was at war with neighbours and involved in alliances I shall leave to others to discover.
The first striking observation is that for the first 8 turns the AI did not recruit any units, despite being able to recruit at least town guard and peasants. Evidently it saw no need to bother with such units. After that the majority of units were those available at the main castle of Staufen: 7 Mailed Knights, 1 Sgt spearmen, 2 Armoured Sgts, 2 Peasant x-bows. Innsbruck provided 3 Mailed Knights and 4 Mtd Sgts. Bologna contributed 2 Cogs and 2 Merchant Cavalry Militia (once merchant guild built.) None of the towns built any spearmen and Prague built 1 unit of Town Guard, before it started spamming ballisas and (later) catapults. All the spearmen and peasant archers were those the HRE started with, with me shifting them to towns and castles, respectively, to be rebuilt if necessary.
Now it would dangerous to generalise but here it appears that the game engine is biased towards high value units against low value ones, preferring not to build any low value ones rather than spend money on peasant and militia units. This is probably due, in part, because I didn't make many offensive moves and the only factions we were at war with were Egypt and Rebels and so there was no need to build more defensive units. However after building many cavalry units in Staufen the AI switched to heavy spears and x-bows presumably to achieve some sort of balance. (Some time after the 30 turns Frankfurt got the Teutonic Knghts order building and built 3 units of mounted Teutonic Knights, but I don't recall any towns building any spears in all 70 turns, although xbow militia later appeared in a couple of towns.)
Regarding repairing units.
These the AI handles quite efficiently, provided the units are inside a settlement that can rebuild them. This is a very important consideration as many of the units a faction starts with in Barebones (not to mention M2TW , Kingdoms scenarios and other mods (including Stainless Steel)) cannot be recruited or repaired as the buildings simply don't exist to build them at the start of the game. (This is one of my bugbears - IMHO only those units that can be recruited should appear at the start up of the game - if that means upgrading settlements to allow this, so be it.) Also some town units are in castles and castle units are in towns. As the AI never (AFAIK!) moves units to rebuild them deliberately (some might end up in the relevant settlements by accident) any of the units in the "wrong" type of settlement will never able to be rebuilt. (Either they should be assigned to the correct type of settlement or both types of settlement should be able to recruit a range of basic units.)
Anyway once the relevant buildings had been built, those units in the "correct" type of settlement were repaired as quickly as the recruitment slots would allow. Upgrading once leather tanners had been built also worked very smoothly. Every unit got queued up and upgraded. (NB as there were less than 9 in Frankfurt at the time it remains to be seen if the AI remembers to check those it couldn't queue up as soon as the building is built.) It should be noted that only 1 leather tanner building was built in 30 turns, suggesting a priority in building better units rather than upgrading existing units, and that the leather tanner is built more because the AI can afford it?
Regarding priorities, contrary what I believed previously, the AI attended to repairing and upgrading units before building new units, provided it was able to do so, although is also capable of doing both at the same time if the number of recruitment slots allows.
------
Conclusions
Firstly we have to assume that the decisions the AI makes for the human player are similar (if not identical) to those it makes for factions under its own control. With the obvious exception that the game expects the human player to take control of agent recruiting and army movements and responses to "missions".
The AI appears competent at running the economy generally speaking. Most problems I had with balancing the books (and in 70 turns it was never more than 300 fl in the red) were down to interventions I made. Public order is capable of a degree of control - I noticed settlements changing from blue or red face to yellow after the end of the player turn suggesting a change in tax regime but it can be vulnerable if too many of the garrison leave and fail to return, or a good govenor dies - it's down to the human player to shift govenors around. So this cannot replicate the AI faction behaviour.
Regarding new buildings, with a balanced stance the AI built a range of buildings, generally starting with economic buildings but switching to military later on, with a scattering of religious and public order buildings. If this is typical of AI behaviour for the factions it controls, then one cannot expect the early turns to be very military oriented, and so one shouldn't expect much military activity, apart from the units a faction starts the game with. Given the lack of buildings to recruit from in the early stages of the game and the difficulty of repairing units, the first 10 turns or more are unlikely to see much sustained activity. It also seems that certain settlements are assigned a role for unit recruitment, a specialisation. For example the only settlement to produce ballistas and (later) catapults was Prague, although others could have built them.
There seems a bias towards recruiting the best units available and against recruiting lesser ones. This can lead to unbalanced armies taking the field or lop-sided garrisons. The lack of basic spear miltia recruitment is certainly a drawback, as is the lack of basic missile units. It is, of course, possible this is due to the lack of nearby enemies to threaten settlements and thereby provoke more defensive unit production.
The only problems regarding repairing damaged settlements appear to be the order a settlement is in in the main list; the lack (sometimes) of money; and the AI preference for building a couple of new buildings before it repairs existing ones. There is undoubtedly an algorithm that controls this by assigning values to all possible building it can build or repair. So it may calculate that there is more to be gained from building new buildings than repairing existing ones.
Repairing units is constrained only by the fact that many units are in (or end up in) settlements that cannot repair them due to lack of suitable buildings either because the building doesn't exist yet, being the "wrong" type of unit for settlement or possible lack of money. Generally the AI will try and repair and upgrade units before it builds new units if it is possible.
Attachment 20455