Diplomacy AI Development

Yeah, but does AI consider it? It's not evident from this code.

Based on how @Recusive described it, I would say no. But perhaps there will be a more nuanced version in future :).

I think @CppMaster 's point is that if your yields increase by (say) 1% and every other player's benefits by 5%, then you don't actually "benefit" in the sense that Civ is a game where only one player can win.

I've always found the different between absolute and relative increase interesting. For example, a bonus of +7 something might be 5% for a small civ but 1% for a large one. On the other hand, +14 to a winning civ but +7 to you probably isn't in your favour, even if you benefit more percentage-wise. But it might be if those yields are more valuable to you - e.g. faith for a founder vs. a non founder! ^^
 
Is it normal that civs offer capitulation easily now? I've conquered 4 out of 8 of Boudicca cities, but I didn't started to attack next city yet and her capitol is intact and she offered a capitulation to me. It used to be way harder a year ago.
 
Is it normal that civs offer capitulation easily now? I've conquered 4 out of 8 of Boudicca cities, but I didn't started to attack next city yet and her capitol is intact and she offered a capitulation to me. It used to be way harder a year ago.

4 cities was usually the magic number last year, for non wide civs.
 
Aha! While doing my memory rework I stumbled upon this minor yet significant bug:
Code:
CvDiplomacyAI::GetMostValuableDoF(bool bIgnoreDoFs)
...
           //Ignore DoFs we already have.
           if (!bIgnoreDoFs && IsDoFAccepted(ePlayer))
               continue;

CvDiplomacyAI::GetMostValuableDefensivePact(bool bIgnoreDPs)
...
           //Ignore DPs we already have.
           if (!bIgnoreDPs && GET_TEAM(GetTeam()).IsHasDefensivePact(GET_PLAYER(ePlayer).getTeam()))
               continue;

To translate, the AI logic for "most valuable DoF/DP not counting current DoFs/DPs" and "most valuable DoF/DP counting current DoFs/DPs" was reversed because of those two exclamation points, meaning the AI was not always selecting optimal friend/DP choices.

Fixed for next version, and should be helpful to humans getting more friendships and DPs.
 
Really? How does it work exactly? Does the game track frequency of units killed and cities captured?

No, but it decays over time (by 1/50th of the current value while at war - fixed this for next version since it wasn't working - and 1/10th of the current value while at peace).

Additionally, if it's been a while since a city was captured, war score drops (if another city is captured, the timer is reset).

(Also, as I checked the code I realized another issue with that calculation, which I will be fixing for next version...)

Edit: Fixed. Capturing another player's city was giving THEM a war score boost if they'd previously inflicted damage on you.
 
Last edited:
Speaking of capitulation, am I missing something with vassal diplomacy/voting in World Congress? I love that you get a free diplomat with each vassal, but every voting deal is impossible to them. It doesn't matter if the deal works for or against me.
 
Re: Approach, the aggression increase is throughout the game. Early game just has an additional bonus if you're considered an "early game competitor".

Re: DPs, I corrected a bug for next version that was causing the AI to make too many DPs (and DoFs).

Re: Strength estimates, I also rewrote the code for this - let's see how things are in the next version.

Seems like the strength estimates are better, at least in my sample size of one game. I am 5th of 6 with the 6th being my vassal and the most powerful AI is offering me a defensive pact and a token amount of money. So I assume I am getting some sort of bonus to my troop count. Another AI has been massing troops near my borders for a long time now as well and I thought he was going to attack but now I think he is afraid of me. Seems reasonable as I have made two players my vassals
 
Speaking of capitulation, am I missing something with vassal diplomacy/voting in World Congress? I love that you get a free diplomat with each vassal, but every voting deal is impossible to them. It doesn't matter if the deal works for or against me.

It does seem very difficult to buy a WC vote even if it's a vote the AI should want. Some trade deals are the same way: they need a strategic and they offer me nothing for it. That being said I haven't played in a few versions.
 
In the game I'm playing at the moment I just entered the last ere (I think the Information Era) and suddently everyone I'm friends with decides they aren't interested in friendship anymore. Four civs, all in a matter of 1-2 turns. Including Austria who I have helped a great deal, and just liberated one of their cities during war they are loosing badly.

I get that late-game competition is a thing but I'm not in the lead by any means, I'm just slightly ahead in technology. Siam and Brazil are both much more powerful in terms of production, territory, and military. China is ahead of me in several areas although just barely. So it's confusing to me that nobody sees the value of friendship with me anymore. It makes the benefit of the Freedom national wonder (which gives bonus food and gold per friendship) kinda pointless in that era too.

Edit: I did also just build the Appollo Program 1 turn after entering a new era, so that might be part of it. Still confusing.
It does seem very difficult to buy a WC vote even if it's a vote the AI should want.

I've been buying a lot of votes in my current game. So works for me at least.
 
Last edited:
Speaking of capitulation, am I missing something with vassal diplomacy/voting in World Congress? I love that you get a free diplomat with each vassal, but every voting deal is impossible to them. It doesn't matter if the deal works for or against me.
It does seem very difficult to buy a WC vote even if it's a vote the AI should want. Some trade deals are the same way: they need a strategic and they offer me nothing for it. That being said I haven't played in a few versions.

Deal logic needs revising. On my to-do list but not the highest priority atm.

Seems like the strength estimates are better, at least in my sample size of one game. I am 5th of 6 with the 6th being my vassal and the most powerful AI is offering me a defensive pact and a token amount of money. So I assume I am getting some sort of bonus to my troop count. Another AI has been massing troops near my borders for a long time now as well and I thought he was going to attack but now I think he is afraid of me. Seems reasonable as I have made two players my vassals

I don't think the buff to humans has been added yet, but that's good.

In the game I'm playing at the moment I just entered the last ere (I think the Information Era) and suddently everyone I'm friends with decides they aren't interested in friendship anymore. Four civs, all in a matter of 1-2 turns. Including Austria who I have helped a great deal, and just liberated one of their cities during war they are loosing badly.

I get that late-game competition is a thing but I'm not in the lead by any means, I'm just slightly ahead in technology. Siam and Brazil are both much more powerful in terms of production, territory, and military. China is ahead of me in several areas although just barely. So it's confusing to me that nobody sees the value of friendship with me anymore. It makes the benefit of the Freedom national wonder (which gives bonus food and gold per friendship) kinda pointless in that era too.

Edit: I did also just build the Appollo Program 1 turn after entering a new era, so that might be part of it. Still confusing.


I've been buying a lot of votes in my current game. So works for me at least.

If you've built the Apollo Program AI assumes you're going for Science Victory and acts accordingly.
 
Aye- I pretty much assume I'm getting mass DoW'd during a run on science victory once spaceship parts start being built. It's kind of exciting though- holding off the hordes long enough to help my citizens escape. Science victory would otherwise be very "hit next turn" IMO.
 
Deal logic needs revising. On my to-do list but not the highest priority atm.
This is something I have seen people complaining since the beginning, and I mean more than five years ago.

I am afraid to ask, but where can I find the logic for the prices offered in deals?

And, the real question is, what should be a fair deal?
For example, if I am making 20 gold per turn, you have 6 horses using none, and I want just 2 horses for a couple of horsemen, how much money should I offer?
In real life there are two thresholds: the price the buyer will never pay because that is too much for him, and the price the seller will never accept because that is too little for him. In a void, the fair price would be in the middle. But in a real world with plenty of buyer and sellers there is also a common price. How can we know the buyer and the seller thresholds?
In the example, maybe other civs are paying 3 gold per turn for each horse, so even if 5 gold per turn could be considered a fair price between us, there are other civs offering a much better price. The problem is that I can't go check other deals if it is not my turn, I can only ask for different offers in my turn.

So let's say I am an AI trying to decide what is a fair price for the horses. I would approach every civ in the game and ask who is willing to sell for lower, and then I'd offer a price between that and what I am willing to pay the most. Or, if I am interested in helping a civ or improving our relationship, or maybe the opposite, I would make a discount (or a tax) on the price only for this civ first and then check worldwide prices.

To make it harder, if I had 5 horses to sell, I would accept a lower price for the first horse, and a much higher price for the last one, since I don't like to be left without strategics. If I have plenty of money, I don't value money too much, if I have scarce strategics I value resources very high, in such scenario I should offer a lot of gold for a few strategics. But once I have purchased some strategics, I will not need them that much, and since I have been left with less gold, I would value gold more. Is this kind of dynamic valuing done during the deal offer? In other words, if 5 gold for 1 horse is considered fair, then 20 gold for 4 horses should not be fair, not just because the buyer has no money, but because he won't pay that much for more horses, buying in bigger lots should be cheaper.

With relative values, a fair price can be obtained for every deal amount, but it's tricky.
 
This is something I have seen people complaining since the beginning, and I mean more than five years ago.

I am afraid to ask, but where can I find the logic for the prices offered in deals?

And, the real question is, what should be a fair deal?
For example, if I am making 20 gold per turn, you have 6 horses using none, and I want just 2 horses for a couple of horsemen, how much money should I offer?
In real life there are two thresholds: the price the buyer will never pay because that is too much for him, and the price the seller will never accept because that is too little for him. In a void, the fair price would be in the middle. But in a real world with plenty of buyer and sellers there is also a common price. How can we know the buyer and the seller thresholds?
In the example, maybe other civs are paying 3 gold per turn for each horse, so even if 5 gold per turn could be considered a fair price between us, there are other civs offering a much better price. The problem is that I can't go check other deals if it is not my turn, I can only ask for different offers in my turn.

So let's say I am an AI trying to decide what is a fair price for the horses. I would approach every civ in the game and ask who is willing to sell for lower, and then I'd offer a price between that and what I am willing to pay the most. Or, if I am interested in helping a civ or improving our relationship, or maybe the opposite, I would make a discount (or a tax) on the price only for this civ first and then check worldwide prices.

To make it harder, if I had 5 horses to sell, I would accept a lower price for the first horse, and a much higher price for the last one, since I don't like to be left without strategics. If I have plenty of money, I don't value money too much, if I have scarce strategics I value resources very high, in such scenario I should offer a lot of gold for a few strategics. But once I have purchased some strategics, I will not need them that much, and since I have been left with less gold, I would value gold more. Is this kind of dynamic valuing done during the deal offer? In other words, if 5 gold for 1 horse is considered fair, then 20 gold for 4 horses should not be fair, not just because the buyer has no money, but because he won't pay that much for more horses, buying in bigger lots should be cheaper.

With relative values, a fair price can be obtained for every deal amount, but it's tricky.

It's in CvDealAI.cpp. Have fun. :)
 
An example on relative values.
Say Civ A wants to buy horses from Civ B.
Civ A has 4 horses and produces 21 gold per turn.
Civ B has 12 horses and produces 14 gold per turn.

Case 1 horse.
Civ A values 1 horse as 1 on 5 horses it will end up with. Since horses is the only strategic resource this far, it means increasing strategics by 20%.
Civ A might be willing to pay a maximum of 20% of its gold production, so it will pay no more than 4.2 gold per turn for 1 horse.
But since the horse is wanted for a horsemen unit, then the cost of maintaining that soon to be unit has to be included. Say it will cost 1 gpt in maintenance.
Then Civ A will pay a maximum of 20% of its spare gold production (20 - 1) * 20%, so 4 gpt.
Civ B values 1 horse as 1 on 12 horses it has connected. Selling one horse means reducing strategics by 8.3%.
Civ B might be wanting to receive a minimum of 1.26 for that horse.
Theoretically, a fair price would be the average, 2.63 gold per turn for 1 horse.

Case 2 horses
Civ A values 2 horses as 2 on 6, so a 33% increase. 2 horsemen will take 2 gpt from budget.
Civ A will pay no more than 6.3 gold per turn.
Civ B values 2 horses on 12 horses it has, as 16% of strategics.
Civ B wants a minimum of 2.78 gold per turn.
x / (14 + x) = 0.166 <==> x = 0.166 * (14 + x) <==> (1 - 0.166) * x = 14 * 0.166 <==> x = 14 * 0.166 / (1 - 0.166) = 2.78
The average is 4.54 gold per turn for 2 horses, so every horse costs 2.27 gpt.

Case 3 horses
Civ A values 3 horses as 3 on 7, so 42.8%. Say 3 horsemen cost 3 gpt in maintenance.
Civ A will pay as much as 7.7 gpt.
Civ B values 3 horses on 12 as 25%
Civ B wants a minimum of 4.6 gpt
Average is 6.15 gpt for 3 horses, so every horse costs 2.05 gpt.

Case 4 horses
Civ A values 4 horses as 4 on 8, so 50%. 4 horsemen is 4 gpt in maintenance, so 17 spare gold per turn.
Civ A will pay as much as 8.5 gpt.
Civ B values 4 horses on 12 horses as 33.3% of its strategics.
Civ B wants a minimum of 7 gpt
Average is 7.75 gpt, 1.93 gpt per horse.

Case 5 horses
Civ A values 5 horses as 5 on 9, so 55.5%. 5 horsemen is 5 gpt in maintenance, so 16 spare gold per turn.
Civ A will pay as much as 8.9 gpt.
Civ B values 5 horses on 12 horses as 41.6 % of its strategics.
Civ B wants a minimum of 10 gpt, making the deal impossible.

I've only considered the cost of the horsemen maintenance, but maybe their purchase/production could be factored in.
Even if civ A is able to purchase 4 horses, it will take a time before it can produce 4 horseman, making this deal less appealing.
 
Back
Top Bottom