# The algorithm according to which the AI decides...

#### onomastikon

##### Dual Wielding Banjos
According to what algorithm or other decision-making calculations does the AI decide to attack you?
It seems odd to me to be in a game in which my so-called friend Mao, the second-strongest nation, is polite to me and, it seems, with good reason, since he receives some nice luxuries he cannot get elsewhere, etc etc. We trade for a ROP. Shortly thereafter (3 turns IIRC), he moves some forces into my territory and sacks one of my (crappier) cities. (The last mistake he ever made, btw. On my subsequent turn, I get the rest of the world to ally with me against him, he is wiped off the planet in 19 turns. Interestingly enough, right after that war, the Japense, my so-called friend and ally with whom I was "gracious", attacked me -- and was eliminated 16 turns later. Quite helpful to me, really.)

Why does the AI do this? What calculations does it utilize according to which it has nothing to gain by attacking me on turn X, but somehow plenty to gain on turn X+1?

(I am playing Vanilla on Emperor.)

There is a pretty complicated equation to all this the problem is th AI cant use any human logic behind it and can only see a few figures and cant predict or see any future implications. It happens alot especilly on Sid as soon as you look like your gonna win you get ganged up for pretty much the rest of the game. I would imagine that its like that to a degree on all skill levels just not quite as bad for each level you drop by. Even on Emperor tho its will seem pretty dumb tho i would imagine and only gets worse as you go up. At least on Sid tho it does gang up in a way in which could win.

I have seen some calculation somewhere. Basically IIRC the AI will decide to attack if it can do so, and if it has a better than XX% chance of winning, this will tend to be the case if you do not have terrain bonuses in your advantage, if the AI unit is superior to you, or if your unit is damaged. I do not recall the percentage, but it was surprisingly low I believe.

The AI also can decide on strategic points to attack, where the above would usually prevent it from attacking, these will be resource tiles or city tiles, which it will determinedly try to boot you off.

Ah, hang on I thought you meant specific unit-unit situations, sorry, just re-read your post.

The AI will base it's decision on whether or not you are Weak, Average, or Strong in terms of the military advisor. It calculates relative strength based upon the approximate formula: MilStrength=(SumOfUnitAttackValues*1.5)+(SumOfUnitDefenceValues). You can see that Attack is considered more valuable than defence, so advanced players often advise that you ignore defensive troops in favour of offensive ones. The calculation also ignores the extra movement of mounted or mechanised units.

There is a term in the formula for artillery units, but it is based on some feeble proportion of their Bombardment strength, so that about a dozen artillery units are considered as good as one offense unit.

Basically, if your advisor tells you that you are weak compared to XXXXX, then the AI will consider you a potential target. Keep them happy by trading with them and you should be ok. Establishing embassies is a good idea btw. Alternatively, build lots of offensive type units until your advisor says you are strong.

Thanks!
Interestingly enough, I was "average" vs China for the entire game up until the point when he declared war. Then I was "strong"!

You should also consider that if you're "average", you're very likely to win the war, especially with some artillery.

They probably just lost enough units to push them into the weaker category somewhere. The AI should always lose more units than a human in battles, if you take the unit vs unit calculation I mentioned, they will be far more likely to attack in a weak position than a human.

I think some of the 'problem' comes from open cities. I have seen the AI attack me when I am stronger if there is an unoccupied city. They just love to take them and apparetnly will declare war to get one.

Yes, they have poor strategic decision making. We think, 'He won't sack that city. I'm 4 times as powerful as he is'. But the AI sees the open city, takes it, and then you declare war and crush him.

It seems even VERY weak defenders can prevent this.

Breunor

Quantity over quality can often be enough it would seem.

The AI will often sneak attack even when militarily weaker. I had the Chinese attack an Infantry in a city with a horseman which had no hope of winning. Also they violated a lux trade and a ROP.

lol I found the attack probability calculations I mentioned while re-reading Sir Plebs Going for Sid thread (post #203), here is the relevant section:

Here are some interesting data points from my tests. The top line of each pair in the following table represents a test case where the AI unit will not attack. The bottom line of each pair changes one factor by +1 or -1 to cause the situation to pass a threshold to the point where the AI will attack.

attack - attacker - defense - defender - attack win
strength - HP --- strength --- HP ---- probability

3----------2----------20----------2----------4.7%
4----------2----------20----------2----------7.4%

4----------3----------20----------3----------3.6%
5----------3----------20----------3----------5.8%

5----------4----------20----------4----------3.3%
6----------4----------20----------4----------5.4%

3----------5----------20----------5----------0.3%
4----------5----------20----------5----------0.9%

2----------6----------20----------6----------0.02%
3----------6----------20----------6----------0.1%

6----------4-----------8----------6----------13.5%
6----------4-----------8----------5----------22.1%

6----------4-----------6----------8----------11.3%
6----------4-----------6----------7----------17.2%

To clarify, in each pair of rows the top row is a situation in which the AI will not attack, the 2nd row has 1 changed variable and resulted in the AI attacking. The reason for the high defender hp is that SirP was investigating under what situations the AI will attack an army.

The critical point in most cases is that if the chances of winning are over a meagre 5% the AI will decide to attack!

As you can se though, and as SirP pointed out, with Elite (5hp) units or units modded to be stronger, this critical value changes in a manner that makes little sense.

Thanks to SirPleb

Edit: table edited for clarity...

Hey thanks, this is interesting stuff.

Still one thing seems odd to me -- and not just the oddities you rightly point out in the AI's tacitcal deliberations:
It seems odd to me that the AI will decide to start a war based on the outcome of one possible battle (out of potentially hundreds in the ensuing war). While the AI has much to gain by keeping the peace (its reputation, happiness, etc. etc.), it will often choose to break a deal and risk its neck... based on one measly potential battle??

Pentium said:
You should also consider that if you're "average", you're very likely to win the war, especially with some artillery.

Very true since the AI bumbles around in war more than anything else, except for continental war

Replies
32
Views
3K
Replies
1
Views
1K
Replies
1
Views
546
Replies
0
Views
150
Replies
2
Views
472