# Is there any logic to an AI DoW?

Discussion in 'Civ4 - Strategy & Tips' started by marstinson, Aug 6, 2008.

1. ### DanF5771Emperor

Joined:
Feb 21, 2008
Messages:
1,194
Hmmmh nobody else cares to post -- I wonder why? Anyway:

iDemandRebukedSneakProb is a leader's probability to start preparing for a Limited War against you after not giving in to one of his demands. Washington surprisingly shows a value of 100 here (as the only leader), which means you better pay tribute to him. Cathy and Ragnar have 80 -- that's not that much of a surprise. But Washington's and Ragnar's ContactRands for DemandTribute are only 1000, whereas Cathy's is 50 (for all the xml values check out the spreadsheet attached to this post)!

iDemandRebukedWarProb suggests that the AI will switch to a Limited War directly after rebuking a demand, but there is currently no such thing implemented in the code! Setting the values to 100 and repeatedly rejecting their empty threats had no effect at all, except the usual "-1: You refused to give us tribute!". So currently these leader values are completely irrelevant.

iDeclareWarTradeRand - this is where it gets interesting. This xml value is 40 for all leaders except for one, Pacal's is 60; it is used to determine the probability that an AI bribes another player to join a war it is currently fighting with a 3rd player. The formula for the chance to consider a bribe strongly depends on the duration of the most recent war (CHOSEN dogpile wars get a penalty -> fewer bribes):[pre]WarCounter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ...
Chance: 50%| 33%| 25%|5.8%|4.7%| 4%|3.4%| 3%|2.7%|2.5%|2.5%|2.5%| ...[/pre]These numbers are for the xml value of 40; since higher values result in lower chances (it's a "...Rand" in contrast to the "...Prob"s), Pacal's chances are 50%|25%|20%|4%... There is a sharp drop after the 3rd turn.

In CvPlayerAI::AI_doDiplo() the AI loops over all other players (the human player comes last); if it doesn't decide to contact the current potential trading partner for any other reasons it will try to bribe him into one of its wars (this does not need to be the most recent war!) with the above mentioned probability. That's how I understand the code, I'm quite shocked about the 50/50 chance on the first turn after the DoW, but more requirements must be met. The human player cannot be bribed (normally, see below ).
If the RNG agrees to a potential bribery, the code loops over all valid dogpile victims and determines the "best".

Example:
Stalin DoWed Cyrus 20 turns ago and DeGaulle - the master dogpiler - decided (unbribed) to jump in at Cyrus' side last turn, so Stalin is currently at war with Cyrus and DeGaulle. He also knows Suleiman and hasn't contacted him for any other reasons --> he has a 50% chance to ask Suleiman to dogpile on either Cyrus or DeGaulle. Suleiman checks whether he can be bribed to war them (he must like Stalin enough [>Annoyed] and dislike the others enough [<Friendly, those are Suleiman's thresholds], not at war yet, no peace treaties, enough power). If both players pass the test, the "best" victim is chosen by [pre]iValue = Random(1...1000)*(101+AttitudeWeight)/100.[/pre]AttitudeWeight is a value between -100 and +100 depending on the victim's attitude towards the instigator (Furious: -100; Annoyed: -40; Cautious: -5; Pleased: +50; Friendly: +100). This is a bit strange and at first I thought it might be a bug because the player with the highest iValue "wins". So if DeGaulle is Pleased with Stalin and Cyrus is Furious towards him, Suleiman is much more likely to be bribed against DeGaulle (iValue=1...1510) than against Cyrus (iValue=0...10). But maybe it is intended to compensate for the additional drop in attitude "-2: You brought in a war ally against us!" after the bribe.

Stalin determines iOurValue = AI_declareWarTradeVal(victim, Suleiman) which depends on:
• number and size of the victim's cities: 10*NumCities + 2*TotalPopulation(incl.Vassals)
• Suleiman's attitude towards the victim: * 1| 1.25| 1.5| 2.5| 5 for Furious|Annoyed|Cautious|Pleased|Friendly
• Power Ratio (incl.Vassals): * ( 0.5 + Power_Victim/(Power_Suleiman+Power_Victim)) --> *(0.5...1.5)
• Victim not a LandTarget for Suleiman? --> *2
• Stalin's WarSuccess against victim: *(1...1.5) // 1.5 = no success
• number and size of Suleiman's cities: + 20*NumCities + 15*TotalPopulation(incl.Vassals)
• Suleiman's attitude towards Stalin and number of wars Stalin is fighting: * (0.75...0.9) | (0.5...0.8) for Pleased|Friendly
• number of victim's nukes: + 250*NumNukes //Don't want to get nuked
• number of Suleiman's nukes: + 150*NumNukes //Don't want to use nukes on another's behalf
• scaling for elapsed game turns: *(0.6...2.0) // early wars are cheaper

What can Stalin offer?

Stalin loops over all techs he knows and which he can trade to Suleiman and determines the "best" tech with the highest value according to [pre]iValue = Random(1...100)*(Number of beakers Suleiman needs to research this tech)[/pre]He then determines iTheirValue = Suleiman.AI_techTradeVal(eBestGiveTech, Stalin) which depends on:
• Number of beakers Suleiman needs to research this tech
• percentage of known other players who have the tech
• AITradeModifier for the tech (+10% for most military techs)

Then there is most certainly a bug in the code:
Stalin compares the two values and if (iTheirValue > iOurValue) he puts another tech on top of the deal!!! I'm sure it should be the other way around, Suleiman should get a second tech only if one tech is not enough to cover his costs. There are further attempts to level the difference between iTheirValue and iOurValue by trading gold (iGiveGold, iReceiveGold) but the amounts are capped at the leader's AI_maxGoldTrade. {There is a minor bug in this calculation too. If Stalin is in financial trouble (his iGoldValuePercent=3) he asks for 50% less cash than if he is not (his iGoldValuePercent=2) due to iGold = ((iTheirValue - iOurValue) * 100) / iGoldValuePercent.}

Finally if (iTheirValue > (iOurValue * 3 / 4)) the deal is good and Suleiman will DoW the victim for 1 or 2 techs +- some gold.
This condition also indicates that giving a second tech if (iTheirValue > iOurValue) is unnecessary. Furthermore it shows that the bug prevents successful bribe deals when 1 tech is not enough and the instigator does not have the necessary cash to reach the 75% threshold. I personally think this should be fixed -- it might entail some more dogpile wars due to successful bribes.

Here are some screenshots I made after lifting some restrictions in the SDK.

Stalin in very generous mood (2-tech-BUG!), I have only 20 to compensate:

This is too good for me - I ask to renegotiate and suddenly all he offers is:

Stalin is offering the following trades when I contact him depending on whether he is currently in financial trouble:

If he is in financial trouble he only asks for 70 instead of the 105 he wants if he is not. It appears this behaviour affects all sort of trades and maybe it IS intended, to have the AI sell stuff for bargain prices at times of financial trouble to get SOME cash.

2. ### YampsDeity

Joined:
Aug 30, 2007
Messages:
2,731
Gender:
Male
Location:
Zagreb, Croatia
Well, you're in charge here! Everything one needs to know about wars in civ in one thread!

Joined:
Sep 18, 2008
Messages:
38
Location:
Finland
Nvm... . . .

4. ### oedaliKing

Joined:
Apr 6, 2007
Messages:
906
Gender:
Male
Location:
Washington, DC
This is the best read I have had in a while... Congrats!

5. ### TephrosCaffeine Junkie

Joined:
Apr 12, 2006
Messages:
521
Excellent work. What about the leaders that aren't listed in this post? Half the time I unluckily want to know about a leader that's not listed there.

Joined:
Feb 21, 2008
Messages:
1,194

7. ### CivCorpseSupreme Overlord of All

Joined:
Nov 15, 2005
Messages:
1,930
Dan always makes me feel old and stooopeeeed. I use a different spread sheet.

Montezuma->Checks to see if he is Monty, if yes then DOW.
Shaka-> checks to see if he knows you exist, if yes then DOW, if No then DOW everyone else until he meets you then DOW
TheMeInTeam->checks to see if game is started, if yes then DOW

8. ### GagoniteIrishman

Joined:
Nov 6, 2005
Messages:
208
lol nice.. sounds about right too.

9. ### TephrosCaffeine Junkie

Joined:
Apr 12, 2006
Messages:
521
Every since I found this thread I now write down values for leaders as I meet them in a game. I make a chart to reference for the rest of the game on which ones don't declare at pleased, the maximum power ratio for them declaring when near or far, the tech trade known percent value, and how much they have to like you before they'll trade monopoly techs. Anybody else do that? Any others that are especially useful?

10. ### notqueArtificially Intelligent

Joined:
Nov 13, 2005
Messages:
1,654
What an amazing thread. So the bugs should be fixed right? By betterai team?

I have a lot of leaderheads to change around values for. Hopefully I get what I'm looking for. Wow.

11. ### r_rolo1King of myself

Joined:
May 19, 2006
Messages:
13,818
Location:
Lisbon, Portugal
Some of the bugs pointed here were already fixed in the BetterAI mod, like the self-closeness one ( in fact , it was that particular bug that ignited the start of the BTS BetterAI ).

12. ### YampsDeity

Joined:
Aug 30, 2007
Messages:
2,731
Gender:
Male
Location:
Zagreb, Croatia
I've just downloaded the LeaderHeads_317 spreadsheet, I was using other reference charts before. So, here comes a stupid question, why I don't see any numbers in the sheet? Everything is white... Using OpenOffice.

Joined:
Mar 30, 2006
Messages:
2,264
Gender:
Male
Location:
Brazil
@Yamps: did you try clicking on the "+" button above each column to expand their contents?

Joined:
May 30, 2007
Messages:
1,215
Location:
Haha, that made my day. This is a great thread though. Tons of useful info.

15. ### DanF5771Emperor

Joined:
Feb 21, 2008
Messages:
1,194
I guess OpenOffice can't handle the grouped data in the collapsed columns properly. I've updated the attachment with a version that has all rows and columns expanded. If this doesn't work you can also try out the following slightly altered pdf-version.

File size:
57.9 KB
Views:
183
16. ### r_rolo1King of myself

Joined:
May 19, 2006
Messages:
13,818
Location:
Lisbon, Portugal
Ok, I'm not much a man of ranting about particular games, but I think my last LHC game version ( the one currently ongoing ) show a very irking phemonenon related with the AI DoW mechanics. I also know that this will not be corrected in Civ IV by the devs, but it can be useful to think on it in terms of amateur modding ( like the better AI.... I know this thread is linked there ).

Ok, let's go on with the story: as most of you are aware, in the LHC games you start isolated. In this case most of the world went to a budha lovefest with a rogue hindu. I contacted most of them and got a acidental spread of the AP religion ( budhist one, how original... ), but the rogue hindu didn't had a single budha city and was despised by most of the budhists. Even then I seen 3 AI getting to "hands full" status and I was pretty sure that one of them was for me ( having between 20 and 40% of the power of the AI combined with them being cautious ( that is another point: why on Earth the AI would consider to do a invasion in those terms, to a faraway AI that didn't even had time to try to get better relations with them? Was because of that particular issue that the initial grace period was implemented anyway ? :/ ) makes wonders in that regard ... ) . But then.....

The AP got in the was and started a cruzade against the heaten hindu ( that I obviously didn't defied ... huge oportunity for diplo goodies ). Like in all cruzades in the games I played, this enede being self perpetuating, with AI getting in and out ( the heaten managed to hold in the fight for 300 years, and I passed from maces to infantry in that time ) until the heaten capitulated to the highest score AI.

That cleaned all the "hands full" ( I guess that the majority of those "hands full" were for the heaten )... all but one. The more advanced AI was still in hands full and I was pretty much expecting a invasion. But in those days I could spit tanks in 1 turn from the cap ( that didn't even had HE ) and had another dedicated all prod city, so I was able to chunk a decend defense force. I also positioned my navt to funnel the in coming attack to a certain city, that had more than enough garrison to cope with a direct landing and enough tanks to deal with a in field battle if needed. Then he dowed in the worst moment possible, when I DoWed via DP a third party that was stupid enough to attack the score leader ( let's say he ended in the wrong side of a nuke shower combined with a blitzkrieg that would had made Rommel proud ), so I had to face the war alone.

The war was pretty uneventful: AI suicides most of the navy vs my battleships, some transporters unload the enemy army right into CG II infantry in a fruitless amphibious attack ( they killed exactly 0 units of mine in that attack ) and utterly their naval untis in the area was destroyed , small task force groups were sent from time to time ( normally 1 carrier, some battleships and destroyers and some transports ), always by the same path ( other thing to change , maybe ), a thing that made it easy to erase them by a skillful use of the navy.... pretty much what it is expectable in a war between 2 equal age foes ( he had flight on me, but you know how the AI is dreadful in using air units in naval invasions ). In the end he foolishly vassaled that guy that had Dowed the score leader and ended being a vassal , after some nuking of it's core cities.

Like I said , this is more a rant than anything, but highlights a very stupid point ( that was already covered in a post by DanF some pages ago ): the AI will not check for the target power after it decides to go to war, EVER It will only consider if it's buildup is eficient (in AI terms, that is ). That might be alright in maybe 80% of the games, where there aren't big obstacles to the AI dow, but in some games, where the DoW is postponed by force majeur issues ( like lacking ocean traveling ships or being involuntarily involved in other war before the actual march order ), it can give HUGE mismatches between the situation that made the AI consider declaring war and the actual field situation. In my game ( that is probably a extreme example, but the extremes most of the times are where the flaws of a system are shown ) that particular AI thinked that was a good idea to wage a war with their rifles against my maces and ended landing infantry, tanks and cavs against a well prepared foe ( more than warned about his treacherous intentions ) that had a equal standing in military techs ( except in air power ) terms and was playing in home, without even considering if it's decision 200 turns ago was a good idea And that is a big flaw in the AI DoW mechanics ........

17. ### YampsDeity

Joined:
Aug 30, 2007
Messages:
2,731
Gender:
Male
Location:
Zagreb, Croatia
Yeah, I thought it had to be sth banal like that.

No, it works ok. I simply missed those buttons...Sorry for making you do more extra work. Obviously you respond too fast. Anyway, thanks for the spreadsheet! It's so comprehensive, wow...

18. ### YampsDeity

Joined:
Aug 30, 2007
Messages:
2,731
Gender:
Male
Location:
Zagreb, Croatia
Ok...another question.

Is it safe to ignore a demand from a civ already in war or in wheoohrn mode? I'm wondering should I just ignore Monty and his high iDemandRebukedSneakProb (60), since he's already in wheoohrn. I'm suspecting that he's going for the other guy, but could he add another war plan if I send him off and come back when he's done with the first?

19. ### TheMeInTeamTop Logic

Joined:
Jan 26, 2008
Messages:
25,880
IIRC it's safe to ignore the demand, although if they have designs on you of course it buys time. You have to weigh this against the diplo hit of giving them something, if anyone counts them worst enemy.

I usually refute my non allies relentlessly if my allies don't like them (tend to give in otherwise, unless I can put them in a sandwich war the second they DoW with confidence in my garrisons).

20. ### DanF5771Emperor

Joined:
Feb 21, 2008
Messages:
1,194

WHEOOHRN does NOT prevent an AI from switching to WARPLAN_PREPARING_LIMITED after the refusal of one of their demands. Likewise there is nothing that keeps the AI from opening a second front while still being busy in the other war. In a test game I bribed my favorite neighbor Monty (modded to CONTACT_DEMAND_TRIBUTE = 1; iDemandRebukedSneakProb = 100) into a war vs. poor Lizzy. Unsurprisingly, Monty demanded a tech from me in the very next IBT (btw. they never demand monopoly techs). Instead of giving him the tech I provided him with a couple of Modern Armors via WB which promptly entered my cultural borders after some turns of "war preparation" had elapsed. He was still at war with Lizzy at that time!