[BTS] When does AI go from plotting to DOW?

lindsay40k

Emperor
Joined
Mar 13, 2009
Messages
1,688
Location
England
So I've on occasion noticed an AI was at WHEOOHRN but it never actually took the plunge and went to war. This evening I needed a screenshot of Toku declaring war; I cooked up a map for myself where I could beat him to loads of Wonders, got Currency and demanded tribute a dozen times, you get the idea. Yet with only a single Quecha, he still didn't DOW on me. I Worldbuildered him a few dozen Cossacks, Gunships, and Tanks, and next turn he piles them into me. Out of curiosity, I reloaded earlier and did the same, and sure enough he DOWs right away, with his Power graph showing a spike like the number of Deutschmarks in circulation in 1923.

Now, with no other neighbours, I couldn't tell if he was already WHEOOHRN, but I am led to believe that if the AI gains a very large military advantage over a rival over a very short period of time, then it is quite capable of declaring a war that it had not been 'counting down' to. I have sometimes assumed that dogpiles occur as a result of bribes, with the annihilation of Shaka's stack making Catherine drop the price for which she'd be willing to go to war at the request of Cyrus, but now it seems to me that the mere act of destroying the bulk of someone's units may be enough to make an AI spontaneously see their cities as low-hanging fruit?

One end result of pile-ons is that all the AI involved come out happier with everyone else who joined the coalition. It is questionable as to whether or not the +1 diplomas something the AI weighs up; perhaps this is just a happy outcome of the AI being programmed to have an opportunistic bullying streak. Perhaps WHEOOHRN does not set a countdown to war, but rather locks the AI out of being prepared to go to war with anyone but their victim, whilst setting its building priorities to producing units - which in turn will build its Power ratio to a critical mass whereby they'll declare war? Perhaps it also reduces the ratio at which they'll be prepared to do so? Has anyone been digging through the code to figure this stuff out?
 
I've mostly been dealing with the K-Mod war planning code, but it's not that different from BtS. So here's what I think the BtS code (CvTeamAI::AI_doWar) does:

If we're already planning war
: Conclude preparations after (exactly) 5 turns for a "limited" war, otherwise after 10 turns ("total" war). These preparation times are adjusted to game speed. And, apparently, prep time should be reduced if we have at least twice as much military power as they have, but I don't think the code (added in BtS) actually works; seems to be missing a multiplication by 100:
Spoiler :

int iOurPower = getPower(true);
int iTheirPower = GET_TEAM((TeamTypes)iI).getPower(true);
int iRatio = (1 + iOurPower) / (1 + iTheirPower);
if (iRatio > 200) { // Never true?
iTimeModifier *= 100;
iTimeModifier /= iRatio - 100;
}
For total land war, preparations can't conclude if we have fewer aggressive units than 1 + 0.25 * (1 + our population + our cities). If attackers are insufficient, preparations continue for up to 10 more turns before getting canceled.

When preparations are complete, war becomes imminent and is declared as soon as an attack stack reaches the border. I can only think of three ways how a war could be averted at this point: Someone else declares war on us; we sign a peace treaty with our target; or the tactical part of the AI somehow doesn't manage to form a stack or reach a city that it wants to attack. In the last case, war remains imminent indefinitely as far as I can tell (not good). In any case, attitude and power aren't double-checked.

As for starting war preparations, there are several checks that can prevent preparations with a per-turn probability. The first one is mostly based on difficulty and the Aggressive AI option (which factors into other probabilities and thresholds too). The next check depends on our personality and the type of war plan: total, limited or dogpile. Dogpile war only applies to land targets that are already in another war; limited war has to be land war unless we're alone on our continent. The third check is based on our personality and our attitude toward the target. This no-war probability can be 100% if we're at least Pleased. Attitude is averaged when the target has vassals; attitude toward civs with defensive pacts doesn't matter.

Next (non-probabilistic), the power ratio is checked – no war if the ratio is too unfavorable. The threshold depends on our personality and the type of war: Total land war, total naval, limited or dogpile. Power from vassal agreements and defensive pacts is fully counted. Civs already at war with the target only count when considering a dogpile war.

The AI chooses one target that meets the conditions above, mostly based on CvTeamAI::AI_startWarVal. Diplo bonuses or penalties aren't considered, and neither is (interestingly) power ratio; on the contrary, the AI prefers targets with lots of land. Attitude and proximity also matter.

Normally, war preparations commence against the chosen target; however, in the case of a dogpile war, war becomes imminent without preparations. Same for total war when pursuing the "Dagger" strategy. That could've happened with Tokugawa. Not quite sure what Dagger was intended for by the BtS developers; probably for quick surprise attacks. Causes the AI to build up units without having a fixed target (and thus without WHEOOHRN). But even a dogpile or Dagger war isn't declared until units are ready to cross the border.
 
Aha. So, with Deity Toku having the entire rest of the continent to himself, his rapidly widening and heightening empire may well have kept his Preparing from reaching a critical mass of attack units versus empire size, and when he gets a mountain of attack units WB'd in, it pushes him over this threshold and into Immnient, and with attack units already at the borders this means that in the same turn he DoW'd.

Thanks, this has been really informative!
 
Finally got around to testing this in an unmodded BtS game. AI strategies and Area AI type are visible in Debug mode ("chipotle", Ctrl+Z), so I didn't bother to compile a debug DLL. Duel map, Aggressive AI, Inca vs. Japan, me doing nothing except researching Currency in order to demand tribute. Toku began war preparations (Area AI "massing") on turn 105. Before that, for some 80 turns, he ran the "Get Better Units" strategy, which prevents war planning. The AI needs to be able to train at least 2 different attackers in order to get out of this strategy, and Warriors and Archers don't count.

On turn 117, I tried gifting him 8 Tanks, which lead to a DoW 4 turns later. Toku switched to Area AI "offensive" immediately, but I guess he didn't want to attack with just the Tanks or not from the plot where I put them, so he moved some units around before declaring war. When I reloaded and didn't gift any units, Toku didn't form an attack stack (Area AI remained "massing") and dropped the war plan on/ after turn 125 (back to Area AI "neutral"). Apparently, the war plan timed out due to, as you wrote, Toku's quick expansion (37 population in 6 cities). Toku didn't use the Dagger strategy in my test.
 
Top Bottom