Diplomacy AI Development

Diplo AI has been getting a lot smarter over time with my modifications, however whether they choose to DoW if you insult them is actually random (friends will never declare, and friendly approach/opinion reduces the chances, but still). Perhaps that's something to be looked at.

I see your point, although I still feel there's a distinction between capturing a forward-settled city and using a one city exemption to capture a capital with lower penalties.



You aren't intended to be the #1 bad guy in the world for capturing two cities - I captured three in my most recent game, two of my neighbors hated warmongering and yet I didn't get massive penalties for it (I did get massive penalties with Morocco for capturing his cities, but that's to be expected). Perhaps your neighbors just rolled 10's for warmonger hatred scores or something? :)

---

We could try something like (in pseudocode):
Code:
If other player is aggressor and we've only captured one city:
- And the other city is a border city with ours,
- And the other city isn't an original capital or Holy City,
- And the other city isn't the other player's only city,

Then reduce warmongering penalties for city capture by 50%.

Remember, though, that warmongering penalties aren't just for realism, they're meant to signal to the AI whether you're dangerous and risk attacking them - and to apply a mechanical penalty to unit CS and make conquest harder.

Another thing to consider: the player who declared war may be the aggressor, but perhaps they declared war in response to being backstabbed, or having their capital captured, or to regain their lost cities, or for any number of other "legitimate" reasons. In this case, reducing warmongering penalties wouldn't be a smart move for other AIs - even if the AI "shouldn't" have DoW'd someone stronger, the other player is still the real aggressor here.

The Casus Belli system from Civ 6 comes to mind...
I think the number of cities each civ has should be taken into account. If you are a very tall civ and take one or two cities from your very aggressive expansionist neighbour, no one should be really worried about that. Also, holy cities and capitals, as you pointed out, are very strong targets.

So, what if you set two kinds of targets: Strong and weak. Strong targets are capitals, holy cities and big cities from a neighbor with fewer cities or population than the aggressor. Weak targets are all the rest. Make weak targets be just a third of the penalty of a strong target. Three low value cities equals one big city.
 
Seeing some promising stuff in my new game (4-10 patch/standard/king/Germany/progress):

I forward settled Korea and initiated 2 wars, but as soon as I was taking his capital, France (authority) - who I thought was being passive by not attacking Arabia at all - stormed my lands and proceeded to take my vulnerable city that I neglected to build walls in. Almost my entire army was still exiting my newly conquered land, so I couldn't respond and the city fell in 3 turns.
Spoiler :
Screenshot (210).png
I eventually responded once my army was present, and the war ended not too long after retaining the city. By this time Arabia had taken matters into his own hands, and they each traded cities.
Spoiler :
Screenshot (211).png
All of these events combined with happiness crunch left me unable to fortify my lands with the last couple cities I planned to establish; Askia swooped in and settled right behind me after already denouncing me for settling Dortmund and buying a couple tiles. I am about to attack him now that I'm at peace with France.
Spoiler :
Screenshot (212).png
Lastly, England and I had good trade going; I was actually supplying her with horses in hopes she would attack Songhia. Now she has suddenly lost her capital to the Zulu, who've I've yet to even discover. This is all taking place by turn 157.
Spoiler :
Screenshot (214).png
 
Does anyone know if there is a diplomatic penalty when annexing a puppet after many turns have passed ?

I have several puppets which I conquered many many turns ago during earlier eras. I was thinking to annex them endgame but not sure if I will make other Civs angry. I know that initially the very first time the city gets conquered puppeting is less hostile actiin than annexing, but is there a diplo penalty in doing it after many many turns have passed ?
 
Does anyone know if there is a diplomatic penalty when annexing a puppet after many turns have passed ?

I have several puppets which I conquered many many turns ago during earlier eras. I was thinking to annex them endgame but not sure if I will make other Civs angry. I know that initially the very first time the city gets conquered puppeting is less hostile actiin than annexing, but is there a diplo penalty in doing it after many many turns have passed ?

There is no diplomatic penalty for annexing cities. There is for razing cities.
 
Annoying to happen but positive AI improvement. So that you know, when you are about to conquer a Civ they may accept to become vassal to another major Civ. This causes a peace. However the peace is not forced for long 15 turns, you can declare another war the next turn. Of course you declare a war to the vassal owner too.

Also bear in mind week endangered Civs tend to make defensive pacts with your neighbours, your worst enemy. The AI has improved. I wish the player also could have those but way too often I see impossible messages. Sometimes looks like cheating, harder for the player but easily granted to AI. Or I might be imagining.
 
Annoying to happen but positive AI improvement. So that you know, when you are about to conquer a Civ they may accept to become vassal to another major Civ. This causes a peace. However the peace is not forced for long 15 turns, you can declare another war the next turn. Of course you declare a war to the vassal owner too.

Also bear in mind week endangered Civs tend to make defensive pacts with your neighbours, your worst enemy. The AI has improved. I wish the player also could have those but way too often I see impossible messages. Sometimes looks like cheating, harder for the player but easily granted to AI. Or I might be imagining.

There used to be a number of bugs preventing it from happening for humans, but I fixed those. Most likely it's because there's no deal offer where the AI asks to become your voluntary vassal, and no one wants to check whether it's possible every turn. That's another target for my "interaction/deal logic" reform later.
 
There used to be a number of bugs preventing it from happening for humans, but I fixed those. Most likely it's because there's no deal offer where the AI asks to become your voluntary vassal, and no one wants to check whether it's possible every turn. That's another target for my "interaction/deal logic" reform later.
One way to help the player against checking every turn is instead to come with a solution where when the vassal opportunity is ripe then a UI message comes to the screen informing the player that there is a potential if wished.
 
One way to help the player against checking every turn is instead to come with a solution where when the vassal opportunity is ripe then a UI message comes to the screen informing the player that there is a potential if wished.

Yeah, that's the idea.
 
Can you make it so that a major civ can't accept voluntary vassalage when any of their current warscores is lower than -90?
 
Can you make it so that a major civ can't accept voluntary vassalage when any of their current warscores is lower than -90?

I can. But why? Voluntary vassalage is a peacetime option.
 
If the AI is gonna ask for a liege every time it is losing a war, then capturing vassals is no longer possible.

Just forbid voluntary vassalage when at war.
It is possible. I just did it the other day. Portugal became vassal of Denmark just as I was about to capture their capital. On the next turn I re-declared war to Portugal and Denmark and captured the capital.

But I know what you are saying. It can be annoying but I had a whole lot of military in Portugal and Maria could not escape that cheaply. Too late but good try from her
 
I have found a strange piece of code in file CvDiplomacyAI.Cpp, routine DoUpdateOnePlayerMilitaryStrength. This is used to evaluate the relative military strength of two civs. The code is:
Code:
            if(iDPThem > 0)
            {
                iOtherPlayerMilitary *= (int)((iDPThem * .1f) + 100);
                iOtherPlayerMilitary /= 100;
            }
            if(iDPUs > 0)
            {
                iMilitaryStrength *= (int)((iDPUs * .1f) + 100);
                iMilitaryStrength /= 100;
            }
This code multiplies a civ’s military score by a tenth of the sum of the military score of the civs that they have a defensive pact with, and adds that to the civ’s own score.

I’m guessing that what is intended is to add 10% of the military score of the civs that they have a defensive pact with:
Code:
            if(iDPThem > 0)
            {
                iOtherPlayerMilitary += iDPThem / 10;
            }
            if(iDPUs > 0)
            {
                iMilitaryStrength += iDPUs / 10;
            }
If this is indeed a bug, then it could have a big impact on the AI’s view of its strength relative to other civs, and a significant impact on their diplomatic actions.

I’m also reporting on github of course. #6482 (as Tom Robinson nearly said)

As a specific example, I had a base score of 4151, Babylon 3185 and The Huns 3347. Babylon and The Huns had a Defensive Pact. In computing it’s final military strength, Babylon scored 13953:
Code:
(3185 * (334 + 100)) / 100 = 13953

Note that this is more than the sum of Babylon and their DP partner’s scores.

It then divides my score (*100) by their score, giving a percentage rating of 29, which meant I was classed as Weak by Babylon. If my suggested method were used, their score would be 3519 (3185+334), giving a rating of 117, which would mean they considered me Strong. That seems more appropriate.

All figures were obtained by single-stepping through the code in the debugger.

I found this while investigating why Babylon were not offering friendship, despite massive positive diplomatic scores. I found that their Approach was friendly (+5 points) and Opinion was Ally (+10), but the Military Threat was Critical (-15). I was then looking into how I was considered Weak based on Military Strength but Critical as a Military Threat, as the two are somewhat related.

As an aside, the Critical rating was based on 162 for relative military power (not the same as used for computing relative military strength), 100 for proximity and 40 for having declared one war (it was 200 turns ago). This was 302 points and just over the Critical threshold of 300.

When considering a Declaration of Friendship, it might be worth reconsidering the relative weights of Approach and Opinion compared to some of the other factors, particularly Military Threat. I feel they should be weighted higher. Also, as a human player, I would consider someone being a critical threat a positive reason to try for a DoF, not a negative one! I guess that’s just how the AI works though.
 
Last edited:
I have found a strange piece of code in file CvDiplomacyAI.Cpp, routine DoUpdateOnePlayerMilitaryStrength. This is used to evaluate the relative military strength of two civs. The code is:
Code:
            if(iDPThem > 0)
            {
                iOtherPlayerMilitary *= (int)((iDPThem * .1f) + 100);
                iOtherPlayerMilitary /= 100;
            }
            if(iDPUs > 0)
            {
                iMilitaryStrength *= (int)((iDPUs * .1f) + 100);
                iMilitaryStrength /= 100;
            }
This code multiplies a civ’s military score by a tenth of the sum of the military score of the civs that they have a defensive pact with, and adds that to the civ’s own score.

I’m guessing that what is intended is to add 10% of the military score of the civs that they have a defensive pact with:
Code:
            if(iDPThem > 0)
            {
                iOtherPlayerMilitary += iDPThem / 10;
            }
            if(iDPUs > 0)
            {
                iMilitaryStrength += iDPUs / 10;
            }
If this is indeed a bug, then it could have a big impact on the AI’s view of its strength relative to other civs, and a significant impact on their diplomatic actions.

I’m also reporting on github of course.

As a specific example, I had a base score of 4151, Babylon 3185 and The Huns 3347. Babylon and The Huns had a Defensive Pact. In computing it’s final military strength, Babylon scored 13953:
Code:
(3185 * (334 + 100)) / 100 = 13953

Note that this is more than the sum of Babylon and their DP partner’s scores.

It then divides my score (*100) by their score, giving a percentage rating of 29, which meant I was classed as Weak by Babylon. If my suggested method were used, their score would be 3519 (3185+334), giving a rating of 117, which would mean they considered me Strong. That seems more appropriate.

All figures were obtained by single-stepping through the code in the debugger.

I found this while investigating why Babylon were not offering friendship, despite massive positive diplomatic scores. I found that their Approach was friendly (+5 points) and Opinion was Ally (+10), but the Military Threat was Critical (-15). I was then looking into how I was considered Weak based on Military Strength but Critical as a Military Threat, as the two are somewhat related.

As an aside, the Critical rating was based on 162 for relative military power (not the same as used for computing relative military strength), 100 for proximity and 40 for having declared one war (it was 200 turns ago). This was 302 points and just over the Critical threshold of 300.

When considering a Declaration of Friendship, it might be worth reconsidering the relative weights of Approach and Opinion compared to some of the other factors, particularly Military Threat. I feel they should be weighted higher. Also, as a human player, I would consider someone being a critical threat a positive reason to try for a DoF, not a negative one! I guess that’s just how the AI works though.

Good catch! I'll fix. That does look like it's causing a significant issue. I wasn't the one who added that code, it's been there for a long time, but after inspecting it, it's clearly written incorrectly. Explains a lot. :)

Re: DoRelationshipPairing, I plan to look at that soon. The factoring in of military strength into the approach calculation is more nuanced.
 
Last edited:
Great! Sorry, didn't mean to imply it was your code (and I knew it was at least two years old), this just seemed the best thread to use.

And I see it's already fixed :thumbsup:
 
Great! Sorry, didn't mean to imply it was your code (and I knew it was at least two years old), this just seemed the best thread to use.

And I see it's already fixed :thumbsup:

No worries, I didn't take it offensively. I make mistakes too, so don't be shy to point out other errors you may find, regardless of whether they were mine or not. :)

Thanks for your help!
 
I posted this in G's balance thread but it might be more of a AI diplomacy discussion:


World Religion is a good thing to get don't get me wrong, but I think the AI thinks its the second coming or something. Its a solid proposal, but it does not deserve the lashback and the fierce opposition that the AI gives to it.

Meanwhile, it is reasonable that the AI hates UN so much (since its giving DV players the open door)….but because of that, it makes DV feel like I have to have a majority of all votes before I can even attempt UN (and that's assuming the AI doesn't throw a counter proposal that I have to defend, which the AI to its credit is getting better and better at). I often struggle with that vote more than the final supremacy vote...because there my vassals have to vote for me...and my CS allies are now giving me a serious boost in votes.
 
My last game was really fun until VC and my friend (declaration of friendship active) proposed for sanction against me?

Whyyyy? We had joint wars, he asked me for help to declare war against another and i accepted, as i wrote we had declaration of friendship plus a lot of other deals, then he propose something like this.

This really brake my games. Everything else feels so good with the game now

Hope it is possible to fix!
 
I posted this in G's balance thread but it might be more of a AI diplomacy discussion:


World Religion is a good thing to get don't get me wrong, but I think the AI thinks its the second coming or something. Its a solid proposal, but it does not deserve the lashback and the fierce opposition that the AI gives to it.

Meanwhile, it is reasonable that the AI hates UN so much (since its giving DV players the open door)….but because of that, it makes DV feel like I have to have a majority of all votes before I can even attempt UN (and that's assuming the AI doesn't throw a counter proposal that I have to defend, which the AI to its credit is getting better and better at). I often struggle with that vote more than the final supremacy vote...because there my vassals have to vote for me...and my CS allies are now giving me a serious boost in votes.
That brings the question? How do AI decide that the player is going to win before it does?

Is AI estimating how long it will take it for victory so it can assess its possibilities? Or is it just angry at anyone who is close to victory?
 
I posted this in G's balance thread but it might be more of a AI diplomacy discussion:


World Religion is a good thing to get don't get me wrong, but I think the AI thinks its the second coming or something. Its a solid proposal, but it does not deserve the lashback and the fierce opposition that the AI gives to it.

Meanwhile, it is reasonable that the AI hates UN so much (since its giving DV players the open door)….but because of that, it makes DV feel like I have to have a majority of all votes before I can even attempt UN (and that's assuming the AI doesn't throw a counter proposal that I have to defend, which the AI to its credit is getting better and better at). I often struggle with that vote more than the final supremacy vote...because there my vassals have to vote for me...and my CS allies are now giving me a serious boost in votes.

My last game was really fun until VC and my friend (declaration of friendship active) proposed for sanction against me?

Whyyyy? We had joint wars, he asked me for help to declare war against another and i accepted, as i wrote we had declaration of friendship plus a lot of other deals, then he propose something like this.

This really brake my games. Everything else feels so good with the game now

Hope it is possible to fix!

World Congress (League) AI =/= Diplo AI, but I'll give this a look over once the upcoming version is released (I believe it's supposed to be tonight).

That brings the question? How do AI decide that the player is going to win before it does?

Is AI estimating how long it will take it for victory so it can assess its possibilities? Or is it just angry at anyone who is close to victory?

Close to...

Domination Victory? Player has >= 75% of other players' original capitals

Diplomatic Victory? Player has >= 75% of votes required to win

Science Victory? Player's team has built the Apollo Program or any spaceship part, OR has at least 90% of techs and (num civs ahead of in tech > 2x num civs behind of in tech)

Culture Victory is more complicated:
Code:
Player must at least be in the Modern Era

If >= 4 other civs (not counting this guy) are alive, percent to check is 50%.
If 3 other civs (not counting this guy) are alive, percent to check is 25%.
Otherwise, percent to check is 0%.

If % of civs Influential or Dominant on > percent to check, and player will be influential on the civ they have the lowest influence on within 75 turns, then they are close to a cultural victory

They are also close to a cultural victory if they're currently building the CEP.

(Adding for next version to fix a bug: If player is already influential on all civs, then they are close to a cultural victory.
Reading the code made me realize that it returns "NO_PLAYER" for the civ a player has the lowest influence on if they are already influential with all civs.)

Exceptions
- If the game has already been won and this is the "Just one more turn..." phase, then no one is close to any victory.
- If the victory condition in question is disabled, it isn't counted (except Domination Victory, since you can always win by killing all other players).
- AI won't apply weight for being close to a victory condition if victory competition was disabled in DiploAIOptions.sql or the game has already been won (except Domination Victory).
 
Last edited:
Back
Top Bottom