Not why, but when does the AI decide to attack?

Yzen Danek

Warlord
Joined
Dec 15, 2005
Messages
182
A little history:

Monarch game, large map. I got a horrible starting location, decided to try for a cultural win anyway. Ranked number 3 for score, but unconcerned; I'm on pace to finish a cultural victory by the 1930s with my science/culture at 70/30.

With my cultural boundaries pushing hard against #2 Ceasar, one of his cities flips, and four turns later he declares war. Fair enough; I'm -4 with him for 'close borders spark tension', and -2 for 'sway of heathen religion.' He's got a lot more units than me, but I have enough to stave off a couple of waves, a lot of money, and my cultural cities are far inland. I'll weather the attack, buy my way into peace, and keep pushing for my cultural victory.

But, for kicks, I decide to go back and see what I could have done differently to avoid the war. So, I reload the autosave 3 turns before the flip. When the city flips, I gift it back to him. This increases my 'trade relations have been fair' by +3. I play on; he still attacks in exactly the same turn.

So, I reload the autosave 7 turns before the flip. This time, I change research to liberalism, get it in 3 turns, and switch to free religion, removing the -2 penalty to our relations. Then I gift him the city back, for another +3. Still, on exactly the same turn, he attacks me.

I can hardly blame him; I'd attack me too as hard as my culture is crushing his ability to grow his border cities. But the question that this example brings to my mind, more than 'why does the AI attack?,' is 'when does the AI decide to attack?' Why this one turn everytime?
 
I think that's a really good question. I was under the impression that it was largely random (saving external forced circumstances), but now I'm almost wondering if it's preordained as the map is created.
 
Kolyana said:
I think that's a really good question. I was under the impression that it was largely random (saving external forced circumstances), but now I'm almost wondering if it's preordained as the map is created.

It's far from random.

AI civs will attack under a number of circumstances... If you neglect to build your military, then the AI will often see you as an easy target and attack.

If you look like you're getting a good lead in score, the AI will often build it's forces and mount an attack.

If you've cramped the AI with your cultural borders and pushed them into a corner, they'll often attack.



I was once cruising for a time victory, well ahead in score, when China declared war 70 or so turns from the end of the game, I lost a fair amount of land, and managed to negotiate peace with a few turns to go and just a tiny lead in score.

On the last turn china completes a wonder and overtakes me to win!
They sure knew what they were doing when they started that war!
 
a lot of it might be military strengths. Try building an extra unit or two in every one of your cities and seeing if he attacks.
 
The first thing that comes to mind is that the check for declaring war comes at fixed intervals. Say, every ten turns. On their turn for checking for war, the Civ in question 'rolls' to see if they're going to attack. Factored into this roll is current disposition, and relative power.

In this current situation, the sum of adjustments for his disposition towards me is around +3, and he has about 3 times the military power I do. Pulling a number out of thin air, say he has a 15% chance of deciding to declare war on me this turn. He will declare war on a roll of 85-100. The turn comes around where he checks to see if war is declared, and he rolls a 98.

Now, most have probably noticed that Civ4 has predetermined rolls so that you can't use the load game feature to change the outcome of a particular battle; if you reload and fight the same fight over again, you will have identical results. I haven't played around with this enough to figure out exactly how this has been accomplished, or whether it can be manipulated. (I'm glad it's there; I think reloading to change a random event is cheesy, and reloading should only serve the purpose of making overall changes to your plan.)

I know that some past Sid games (like Colonization) what the game appeared to have done is generate a random number table at the beginning of the game, which it read in sequential order, so that someone could actually change the results of a battle by reloading, forcing a different event (making it use up the random number that had previously resulted in a loss), and then attacking with the desired unit (giving it a new chance to win with a new number on the table).

So again, I'm not sure how Civ4 handles the random number generator or tables to ensure identical outcomes, but if, in the case I described, the random number used to determine if Ceasar will attack me this turn is a high roll, like the 98 I used above, it may be that no amount of changing of events to placate him will be enough to exceed the roll. Perhaps, had he rolled a mere 86 out of 100, my changes might have been enough to set the threshold for going to war higher than his roll.

But, this is nearly impossible to test.

My question to other players is: has anyone ever been successful at turning back time, making some changes in their international relations, and averting a war?
 
Were you getting close to the cultural win with your cities? If the AI sees they're about to lose, they're going to start a war with you to try and prevent that. Trying holding Great Artists in reserve and and grabbing the last few thousand in culture in one final turn to get the win. That way, the AI won't see that you're about to get the victory and won't have that incentive to attack.
 
clut said:
It's far from random.

AI civs will attack under a number of circumstances... If you neglect to build your military, then the AI will often see you as an easy target and attack.

If you look like you're getting a good lead in score, the AI will often build it's forces and mount an attack.

If you've cramped the AI with your cultural borders and pushed them into a corner, they'll often attack.



I was once cruising for a time victory, well ahead in score, when China declared war 70 or so turns from the end of the game, I lost a fair amount of land, and managed to negotiate peace with a few turns to go and just a tiny lead in score.

On the last turn china completes a wonder and overtakes me to win!
They sure knew what they were doing when they started that war!


There *IS* a random element ... you only have to look at the XML files to see that, but that's why I added "barring external factors" ... in other words, as an extreme example, if you attack the AI, then obviously this is an external force dictating war.

A weak military is built into the XML ... I've seen the modifiers for a weak or strong military as compared to each civilization ... likewise for different civics and such.

But if we agree that essentially there is a *chance* that the AI will declare war based on a collection of factors - your strength, location, civics, religion and so on - I was still under the impression that this gave a figure that was essentially a *chance* of the AI declaring war ... a random probability modified by various external circumstances.

However, if the AI declares war on the same turn, even with circumstances changing, this almost suggests that the chance of war was ordained well before hand and irregardless of circumstances.
 
Yzen Danek said:
The first thing that comes to mind is that the check for declaring war comes at fixed intervals. Say, every ten turns. On their turn for checking for war, the Civ in question 'rolls' to see if they're going to attack. Factored into this roll is current disposition, and relative power.

I think you've hit the nail ont he head here ... I've seen something in the XML which would support this ... a check for war every x-amount of turns. Bingo.
 
petey said:
Were you getting close to the cultural win with your cities? If the AI sees they're about to lose, they're going to start a war with you to try and prevent that. Trying holding Great Artists in reserve and and grabbing the last few thousand in culture in one final turn to get the win. That way, the AI won't see that you're about to get the victory and won't have that incentive to attack.

No, it's only 1770. I'm really just starting to hit my stride culturally. All of my cities are right around 10,000 culture, but each is producing 200+ per turn now.
 
So, given that war is checked at x intervals, the question that remains is: is it based on a fixed equation, or is there a roll? If it's a fixed equation, you should always be able to go back in there and change enough stuff to change the outcome (in my case, switiching to Nationhood and drafting the crap out of units in my non-cultural cities.)

If it still falls to a random roll, it's possible that sometimes the roll is so high that no matter what you do, that nation will always declare war.
 
Back
Top Bottom