1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Diplomacy AI Development

Discussion in 'Community Patch Project' started by Recursive, Feb 14, 2020.

  1. tu_79

    tu_79 Deity

    Joined:
    Feb 11, 2016
    Messages:
    7,031
    Location:
    Malaga (Spain)
    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.
     
  2. tu_79

    tu_79 Deity

    Joined:
    Feb 11, 2016
    Messages:
    7,031
    Location:
    Malaga (Spain)
    Where's that file located?
     
  3. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    Here you go.
     

    Attached Files:

  4. Stalker0

    Stalker0 Baller Magnus

    Joined:
    Dec 31, 2005
    Messages:
    6,512
    I think we are getting a little complicated here. I think its fine to define the standard value for strategics (aka the normal "fair" price). And then put in some simple logic that says:

    1) IF AI has more than X of certain strategic, they are willing to sell at Y% markdown (Y doesn't have to be complicated, could just be 15% or something whatever makes it enticing).
    2) If AI has less than X of certain strategic, willing to but at Y% markup
     
  5. tu_79

    tu_79 Deity

    Joined:
    Feb 11, 2016
    Messages:
    7,031
    Location:
    Malaga (Spain)
    No, it is not. The values change from era to era, and from map sizes, and that's a source of weird deal offerings.
    Working with relative values should not be that difficult for the CPU and should produce more sane prices during the whole game.

    EDIT.
    In fact, the value of strategics is done as you want:
    Code:
    int iItemValue = 10 + (2 * GC.getGame().getCurrentEra());
     
    Last edited: Jul 7, 2020
  6. JamesNinelives

    JamesNinelives Emperor

    Joined:
    Mar 16, 2019
    Messages:
    1,188
    Gender:
    Male
    Location:
    Australia
    I'm not sure what that changes though. Surely the AI knows I'm going for some kind of victory?
    Except that in my case it's not. Like I said, I'm not leading the world in anything but tech and even that not by much. If my rivals decided to declare war on me together I'd be crushed. My real strength was in diplomacy - that's how I got this far.

    What really gets me is that many of the people I've just lost friendship wish are directly threatened by someone else much more. So surely it would be in their interest to have friends? Austria is about to be completely erased by Siam (or would be without my intervention).

    Update: the world is in chaos. Wars have erupted everywhere. The Congress has finally realised Siam is a threat to civilisation as we know it and proposed to sanction them but it's a bit late for that now lol. It's like the AI have become self aware and know that this is just a simulation - and one way or another it's all going to be over soon XD.

    Also, just found out Siam has a nuke near what's left of my liberation fleet lol.
    Spoiler :
    20200708121210_1.jpg

    1 turn later Vienna's capital and their other city on that continent are captured. Guess I'll retreat and try to defend their new island capital - and last remaining city :).
    2 turns later, Austria has capitulated and is now Siam's vassal. Siam is still invading Greece to the South but I can't keep this up much longer. Time to go home. I did at least get a decent peace settlement.
     
    Last edited: Jul 8, 2020
  7. usadefcon1

    usadefcon1 Warlord

    Joined:
    Sep 24, 2016
    Messages:
    131
    I think the first question the AI needs to ask itself is "How much do I want this?"

    Then "What am I willing to give up for it?"

    Then modify for "How much do I like this Civ? / Are they a Warmonger? / Do I even care?"
     
    vyyt likes this.
  8. tu_79

    tu_79 Deity

    Joined:
    Feb 11, 2016
    Messages:
    7,031
    Location:
    Malaga (Spain)
    I'll discuss current deal value in another thread. It's deep.
     
    JamesNinelives likes this.
  9. RyesDaile

    RyesDaile Chieftain

    Joined:
    Nov 12, 2010
    Messages:
    18
    Is this with vassals? I am able to get trade deals for WC votes with most non-vassal CIVs, but vassals will never accept anything in exchange for their WC vote.
     
  10. JamesNinelives

    JamesNinelives Emperor

    Joined:
    Mar 16, 2019
    Messages:
    1,188
    Gender:
    Male
    Location:
    Australia
    Hmm. No, I don't have any experience trading with vassals unfortunately :(.
     
  11. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    I wonder why vassals in particular have a difficult time with it, then. Hmm. Are they consistently hostile/guarded from mistreatment?
     
    JamesNinelives likes this.
  12. stii

    stii Prince

    Joined:
    Oct 3, 2010
    Messages:
    427
    I think it is the fact the vassals aren't allowed to vote on their own. They always vote for you for host and mostly vote the same way you do in resolutions. Not sure about WC, but I'd guess that is the same.
     
    JamesNinelives likes this.
  13. stii

    stii Prince

    Joined:
    Oct 3, 2010
    Messages:
    427
    I decided it was a bit lazy to not just check how this works. This was past another victory type and with all five other players as my vassals but it probably works the same anyway.

    WC had no one vote for it but they didn't oppose it very much. 2 vassals just voted for other things, 2 voted against with a tiny number of votes and the last used half their votes. So with all my votes it was pretty easy to pass. Seems like it is impossible for vassals to vote for WC as one of mine was very happy with me DoF and even willing to sell me techs. They did all vote for the diplomatic victory so it seems like that is the same as host where they have to follow your lead.
     
    JamesNinelives likes this.
  14. RyesDaile

    RyesDaile Chieftain

    Joined:
    Nov 12, 2010
    Messages:
    18
    Not always. I have been able to get a few friendly/afraid vassals and trades for WC votes are still not possible.
     
    Vhozite and JamesNinelives like this.
  15. azum4roll

    azum4roll King

    Joined:
    Jul 17, 2018
    Messages:
    830
    Gender:
    Male
    If you aren't the first to ask for votes, it's possible that the AI has already sold their votes to another AI.
     
    JamesNinelives likes this.
  16. CppMaster

    CppMaster Emperor

    Joined:
    Feb 13, 2018
    Messages:
    1,166
    Gender:
    Male
    Location:
    Poland
    Y, I can't buy any votes from vassals too. If their votes are already sold then it shouldn't appear on the trade screen, just like resources.
     
  17. JamesNinelives

    JamesNinelives Emperor

    Joined:
    Mar 16, 2019
    Messages:
    1,188
    Gender:
    Male
    Location:
    Australia
    So the item is visible, but it's telling you deal vaue is 'Impossible'?
    I wanted to say my feelings on this subject has eased a little now that the game is over and I can look back at it. Turns out it wasn't just me - other people built the Apollo Program (or were conquering cities etc.) and they were actually even less popular than than me due to my otherwise good relationships.

    You've done a lot of work lately and I'm really grateful for it. Things have improved significantly. Also, the world is a very stressful place at the moment. Hope you are well, best wishes <3.
     
    Last edited: Jul 10, 2020
    Recursive likes this.
  18. CppMaster

    CppMaster Emperor

    Joined:
    Feb 13, 2018
    Messages:
    1,166
    Gender:
    Male
    Location:
    Poland
    Yes
     
    JamesNinelives likes this.
  19. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    Well, after inspecting the code, the cause of the problem seems obvious enough. :lol:
    Code:
    /// What is the value of trading a vote commitment?
    int CvDealAI::GetVoteCommitmentValue(bool bFromMe, PlayerTypes eOtherPlayer, int iProposalID, int iVoteChoice, int iNumVotes, bool bRepeal, bool bUseEvenValue)
    {
       int iValue = 100;
    
       if(iNumVotes == 0)
           return INT_MAX;
    
       //vassals get out!
       if (GET_TEAM(GET_PLAYER(eOtherPlayer).getTeam()).IsVassal(GetPlayer()->getTeam()))
           return INT_MAX;
    
       if (GET_TEAM(GetPlayer()->getTeam()).IsVassal(GET_PLAYER(eOtherPlayer).getTeam()))
           return INT_MAX;
    
    I'll remove this, unless it's the World Leader vote.
     
    JamesNinelives likes this.
  20. CppMaster

    CppMaster Emperor

    Joined:
    Feb 13, 2018
    Messages:
    1,166
    Gender:
    Male
    Location:
    Poland
    Why? Vassals should never sell votes for a World Leader if it's their master?
     

Share This Page