Is there any logic to an AI DoW?

Awesome thread! :goodjob:

I also have some questions:

What about war declarations when you don't do what they ask? I guess that iDemandRebukedSneakProb and iDemandRebukedWarProb have sth to do with that. There is also iDeclareWarTradeRand, 40 for everybody. How does it work exactly?

Thanks in advance! :)
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 :p).
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.

What about the price?

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.:crazyeye:}


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. :p

Stalin in very generous mood (2-tech-BUG!), I have only 20 :gold: 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:gold: instead of the 105:gold: 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.
 
Hmmmh nobody else cares to post -- I wonder why? ;)

Well, you're in charge here! :worship: Everything one needs to know about wars in civ in one thread! :thanx:
 
Ok it appears I was wrong about Mahatma--he can never be a Dagger/doDaggerStrategy (btw what is really meant by that?), no matter where Delhi is located on the map.
He just lacks the necessary features (high MaxWarRand, high flavor values for military, Attack UU) and often does MissionaryStrategy which excludes Dagger.

I've taken a closer look at AI_doWar and most of the relevant functions that are called there and tried to put the main checks and criteria for the AI's war planning into comprehensible(?) words (MSExcel). Some of them differ quite a lot from the descriptions in Niklas' post. For simplicity I've neglected the concept of several players forming one team (so 1 player = 1 team, note: Vassals do not join the Master's team, they will still be two separate teams with 1 player each).
The AI's current strategy and financial situation is pretty important for the likelihood of DoWs. Especially the fact that the AI will not even start thinking about any wars when it is following the GetBetterUnitsStrategy might be responsible for the much earlier DoWs on Deity compared to the lower difficulties. The AI needs to be able to build at least 2 offensive units (UNITAIs ATTACK_CITY, COUNTER, RESERVE and PILLAGE) in its capital. Units of the types Axeman, Spearman, Chariot qualify here (basically everything better than Warriors and Archers), so once it manages to hook up the necessary strategic resources it will drop that strategy and start rolling the dice. With the 2 starting settlers and discounts for training more plus the fast teching I think Deities will reach that point 1000 yrs earlier.

The other interesting factors are how Vassals and the financial situation affect the probabilities for wars. I don't really know what to think of the HUSP-factor (HighUnitSpendingPercentage). For boxed in unit spammers this should be huge (compact empire = low total expenses). E.g. checking the 990AD save of Sisiutil's ALC24 shows Mehmed with USP = 12:gold:/57:gold: = 24% (HUSP = (USP-7)/3 = 5) and 2-city-Pacal with 2:gold:/4:gold: = 50% (HUSP = 14) (note: foreign trade is not taken into account!). So they should consider a total war 6 / 15 times as often, but Pacal's power is probably much to low to actually find a valid victim.
It's also interesting how the raiders don't care about the attitude that much (NWR+10), so Boudica will declare at pleased if she is in financial trouble! (Edit: no she won't due to the capping at 99 and her NoWarProb=100)





The take home message (see also Niklas): Power doesn't mean anything to prevent a DoW unless you are over the relevant threshold! Attitude is much more important. If you are a Lonely Heart your are completely safe from Dogpiles and only have to fear LimitedWars from other Lonely Hearts. Have rather short borders. Don't be too close to yourself.

There is a (minor) BUG in AI_doWar as it checks bFinancesProMaxWar for limited raids instead of bFinancesProLimitedWar. There is a MAJOR (well known) BUG in CvPlayerAI::AI_playerCloseness, where the code determines the closeness of the victim to itself instead of the war planning AI's closeness to the victim, so that compact empires with many large cities make the juciest targets (AI_startWarVal). But it also affects the AI's strategy in the beginning of the game (AI_getStrategyHash). After making the first contact with a neighbor the AI will experience a sudden increase of paranoia due to the super (self-)close neighbor and drop Strategy_Peace and might directly jump to Strategy_Dagger. Daggers don't care about their money when it comes to starting a war... They also skip the whole war preparing thing (which others might drop again, see Saladin in ALC24).
The BetterAI guys have created a fix but AFAIK there is no guarantee yet, that the correct version doesn't bring up other unwanted side effects. (There are so many hard coded "x += (condition)? y : z"s and "q *= iNonsense"s in CIV's code that you just never really know what's gonna come out after killing a silly bug!)

To conveniently check and sort the several Leaders according to their WarRands and NoWarProbs or PowerRatios I've put their XML-values into an additional xls spreadsheet coarsely sorted by category. Columns are grouped and expandable, there is a "Game" column where you can put numbers in to filter everything for a current game. Leaders have their BTS-Colors.



I hope I didn't make too many mistakes here, after all this whole war thing is a pretty complex mess.


Edit: some minor corrections:
A) 4. AI is in financial trouble when (Inflated Costs + foreign trade dificit) > 60% of (beakers per turn + taxes income + foreign trade surplus), threshold increases by additional +8% when aiming for cultural victory, +12% when at war or preparing one, +10% when researching Future Techs

D)11. the +10 for NWR also applies for Daggers when AggAI is off (beware of Daggers in financial trouble--not only will they not oppose wars when broke, they will also care less about friends)

E) 2. MaxPlotDist is 72 for Standard Maps (with cylindrical world wrap)​

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. :sad:
 
Thanks! The spreadsheet screenshot is just an "appetizer" ;) -- you can find the complete list of all AI leaders including the Barbarian leader with all attributes/variables from CIV4LeaderHeadInfos.xml converted to the excel spreadsheet "LeaderHeads_317.xls" which is part of the attached zip-file.
 
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
 
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

lol nice.. sounds about right too.
 
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?
 
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.
 
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 ).
 
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...:confused: Using OpenOffice.
 
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

Haha, that made my day. This is a great thread though. Tons of useful info.
 
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...:confused: Using OpenOffice.
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.
 

Attachments

  • LeaderHeads_317.pdf
    57.9 KB · Views: 284
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 :p ).

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 :eek: ) 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 :p ), 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 :p ), 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 :D ). 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 :p ) 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 ........
 
@Yamps: did you try clicking on the "+" button above each column to expand their contents?

Yeah, I thought it had to be sth banal like that. :blush:

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.

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...:thanx:
 
Ok...another question. :D

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? :eek:
 
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).
 
:nope:
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!
 
Top Bottom