As I noted I've dug around in the AI programming related to declaring war. It's an interesting story, I'll try to relate is as simple as possible here. I guess after this game is over I could tidy this up and post it as a strategy article. But that's after the game.
If you don't feel like reading all of this, at least read the conclusion, and preferably the implication section as well. It's good if we are all aware of these things.
When will the AI go to war
There are two fundamentally different ways in which the AI can decide to go to war with another civ. Either they go to war for diplomatic reasons, or they do it for strategic reasons.
Diplomatically, there are two reasons for the AI to go to war. Either they decide to go to war because a demand is rebuked, or they are bought or coerced into a war by an ally. I haven't looked into the stuff behind this since we aren't really risking either at this point.
The interesting stuff, at least for us here and now, is the strategic reasons for the AI to go to war. There are three different wars the AI could be planning, which all have similar mechanics behind them:
1) Total war
2) Limited war
3) Dogpile war
Every turn, if the AI is not already at war (or preparing to go to war) with someone, and the AI is not in "financial trouble" (I haven't looked to see what that means), the AI rolls the dice to see if it wants to go for a war. First it rolls to see if it wants to go for a total war. If not, it rolls again to see if it instead wants to go for a limited war. If not that either, it rolls to see if it wants to dogpile someone. If not, no war planned, roll again next turn.
Total war
The decision process behind a total war is the following:
1) Roll the dice, i.e. generate a number up to that AI's iMaxWarRand number. If the rolled number is 0, i.e. a 1/iMaxWarRand chance every turn, the AI decides to see if it wants to go for a total war. Note that this doesn't mean it
will go for a total war, only that it will consider it. The number iMaxWarRand is 200 for Asoka and Washington, 300 for Lizzy and 100 for Toku and HC. Note that if the roll is 0 at this step, the AI will not consider a limited or dogpile war that turn even if it doesn't decide to go for a total war after all.
2) Ok, let's see if we want to go to total war against someone. The first thing to do is to roll the dice again, to get the iNoWarRoll number, which will govern just
how willing the AI is to go to a war. This is a number between 0 and 99. The fact that this step is done here and not together with step 4 below means that this number is rolled once and for all for a turn, and all potential targets are compared against that same value.
3) The AI then makes three passes through all the other civs it has met, to see who to go to war against, if any. If a suitable target is found in one pass, it doesn't bother to do the subsequent passes.
A) On the first pass, only adjacent neighbors are considered. Just who is considered adjacent is determined by the AI's iMaxWarMinAdjacentLandPercent number, ranging from 0 to 4. If that many percent of the AI's total land borders the considered target, it is a valid target for that pass (for those who have 0, it is enough to be reachable via land). Asoka has 0, HC has 1, Washington 3, Lizzy and Toku 4. This means we are valid targets for Asoka and Washington for this pass, but not for any of the others.
B) If no suitable target was found on the first pass, in the second pass all civs reachable via land are considered (or, if the AI in question is alone on his land area then all civs, but that's no issue here). In this pass we are valid targets for all our current contacts, and maybe a few more that we haven't met yet.
C) If no suitable land target is found, all civs are considered. Here we are obviously a potential target for anyone.
For each pass, for each civ considered, the AI goes through the same steps:
4) Check if iNoWarRoll >= the AI's iNoWarAttitudeProb for his attitude towards that civ. If it isn't, that civ is not a target.
5) Check if the AI's power ratio towards that civ exceeds the threshold value for that AI. The threshold value is iMaxWarNearbyPowerRatio in passes A and B, and iMaxWarDistantPowerRatio in pass C. Note that the calculation is done by multiplying the AI's power by this value and then comparing it to the potential target's power. If the threshold isn't exceeded, the AI doesn't feel strong enough to take on that civ as a target.
6) Each civ that matches the criteria so far (i.e. not liked enough, and not strong enough) is a potential target, so if any civ gets this far in the calculations, the AI
will start planning a war. To find
who of the potential targets that the AI will choose, calulate the AI's war
value against that civ. This is done by the following steps:
- Take the number of land tiles the target owns that borders the AI, multiplied by 4.
- Add the "capitol proximity" between the target and the AI - this is quite simply the plot distance between the two capitols, multiplied by 1.5 if the capitols are on different land masses.
- Multiply the number gotten by a factor determined by the AI's attitude towards the target: 1 for Friendly, 2 for Pleased, 4 for Cautious, 8 for Annoyed and 16 for Furious.
The chosen target is the one for which this value is highest.
And that's it, for a total war.
Limited war
For a limited war (which is considered if step 1 for total war isn't true), the steps are the same, except there is only one pass, in which all adjacent civs are considered (including all civs that are alone on a landmass, and including all civs anywhere if the AI itself is alone on a landmass). But the values and thresholds used are different.
1) iLimitedWarRand is used instead of iMaxWarRand. This value is generally lower - 200 for Lizzy, 160 for Washington, 120 for Asoka, 80 for HC and 60 for Toku. This means the AI is more likely to go for a limited war than for a total war.
2) iNoWarRoll has an additional -10 factor. This means that the chance to accept going to war based on attitude in step 4 is lower, in other words the AI is less likely to go to a limited war with someone it likes, compared to a total war.
3) Only one pass, as noted.
4) Same as for total war, except iNoWarRoll is -10 as noted above.
5) iLimitedWarPowerRatio is used instead of any of the ones noted above. This value can be higher or lower than iMaxWarNearbyPowerRatio depending on leader, there seems to be no real pattern.
6) War value is calculated exactly the same.
Dogpile war
If none of the steps 1) for total or limited war are true, the AI will consider if it should join a dogpile. Again the calculations are done very similar to the previous variants, but with slightly different numbers.
1) iDogPileWarRand is used instead. This is an interesting value since it says something about the morale of the leader. It can be either 100, 50 or 25 - and lo and behold, Lizzy is one of those with 25 (Toku is another). In other words, Lizzy is very unlikely to decide to go to war on her own (high values for iMaxWarRand and iLimitedWarRand), but if there's a war going on, she's not too picky to jump right in. Washington and HC both have 100, Asoka has 50.
2) iNoWarRoll has an additional factor of -20, i.e. the AI is even less likely to dogpile someone it likes. In other words, the roll must exceed iNoWarAttitudeProb + 20 for a war to be considered.
3) Only one pass is done, and in that pass only civs reachable by land are considered. Also, only civs that are at war are considered.
4) Same as for total war, except iNoWarRoll is -20 as noted above.
5) The power ratio calculation is done a bit differently, and uses the same number for all leaders. The power of the AI, plus the power of all other civs that the potential target is already at war with, must exceed 1.5 times the target's power.
6) War value is calculated exactly the same way.
Implications
There are a few very interesting implications of this decision process, not surprising. To me what stands out as most important right here and now is that there are two ways to avoid war. One is to be liked well enough, the other is to be strong enough to be a deterrent. But note in particular with the latter that it is a
threshold value. What this means is, unless we can reach up to the threshold value of a particular AI, we might as well have 0 power rating, it's going to be just as (not) deterring. And the threshold values are fairly high too - Lizzy is the one with the lowest threshold value, at 80% of her own power for total war. We're not even close to being at 80% of
any AI's power at this point. So our only deterrent right now is good relations.
On the other hand, good relations are a pretty good deterrent already. No AI will ever go to war against someone they are Friendly with (diplomatic reasons aside, I haven't dug into those at all so I don't know if you could buy in someone - I suppose you can, for some AIs like Catherine). No AI will ever dogpile someone they are Pleased with (lowest threshold there is 80, and iNoWarRoll is at -20), few leaders will consider a limited war, and even total war is 20% chance at most. At Cautious the values drop dramatically for some, down to 20% threshold at the lowest, others remain as high as 70%. Below Cautious, you're in definite danger.
Also interesting is that the war
value for an AI is not at all dependent on the power ratio against the target. The only factors are what land the AI hopes to grab, and the attitude towards that civ. So again we might as well have 0 power rating, if we're not the juciest target in the area then we will go scot free anyway. I would also have guessed that things like potential wonder grabs would factor in here, but nope. So we can build as many wonders as we like, it won't make us a bigger target.
Looking at the leaders in our vicinity, this is what we can say for sure:
Asoka
Asoka will never go to war with us at Pleased or above, and we are there already. If we were to drop to Cautious for some reason, the chance is 0.3*1/200 ~= 0.15% that he would
consider declaring a total war on us at any given turn. But if he gets as far as that, it is definitely not improbable that there will be a "better" target for him, i.e. with a higher war value, since if he were to consider us then he would also consider all others that he is Cautious with and below, assuming they pass the power ratio test (and he is among the stronger). Again at Cautious, the chance that he would consider a limited war against us is 0.2*1/120 ~= 0.17%, with the same caveat about other targets.
Elizabeth
Lizzy would consider going to total war at Pleased, but the chance for that is 0.1*1/300 ~= 0.03% at any given turn, assuming she finds no better target. She wouldn't consider a limited war at all. At Cautious, the chance is 0.5*1/300 ~= 0.17% for a total war and 0.4*1/200 = 0.20% for a limited war. Note that these are (roughly) summed, so the total chance that she will consider a war each turn on Cautious is ~0.37% for either a total or limited war.
Huayna Capac
HC would not go for a limited war at Pleased, and the chance to consider a total war is 0.1*1/100=0.10% on any given turn. At Cautious, the chance is 0.5*1/100 = 0.50% for a total war and 0.4*1/80 = 0.50% for a limited war. On Annoyed, the chance is 0.9*1/100 = 0.90% for total war and 0.8*1/80 = 1% for a limited war, for any given turn. We are probably farther away than many other targets though, and he is Cautious with most that we know. Only caveat is that they must pass his power ratio test to be considered at all, and he is not among the stronger currently.
Tokugawa
The values for Toku to go to total war are exactly the same as HC's, he is slightly more eager to start limited wars though. At Cautious the chance for a limited war is 0.4*1/60 ~= 0.67% on any given turn. Note that this means that at Cautious, which he is currently at with us, the total chance is roughly 1.17%, or 1/85, that he will consider going to war with us on any given turn. His war value is likely higher with Lizzy though, she would have to be more than twice as far from him as we are for us to be considered first - but she is stronger than him, and his ratio values are 100 for all kinds of close wars. We are currently the only one (that we know) who are weaker than him, and thus his only valid target.
Washington
Washington is dangerous since he is the one most likely to find us the "most valuable" target, considering our long border. He will not go to war at all on Pleased though, so the faster we get there the better. At Cautious, his chances to consider a total war is 0.3*1/200 = 0.15%, and the chance to consider a limited war is 0.2*1/160 ~= 0.13%. So every turn at Cautious, the risk that he considers attacking us is ~0.28%, or roughly 1/360.
Conclusions
If you didn't read all the above, read this at least. To me, this says three things about our game.
1) It is very important that we keep certain leaders at least Pleased, Washington in particular.
2) We should keep an eye on Tokugawa, maybe even consider appeasing him in some way, despite his bad relations with Lizzy. She is the one who likes us the most right now anyway, and the least likely to attack us even if she didn't, and we could take a -1 worst enemy trade modifier with her at this point without dropping her below Pleased.
3) We might as well not care about our power rating, it won't do us any good anyway, there's no way we can catch up to where it becomes a deterrent. So if we build military, it should be for actual defense, not for power rating purposes.