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. Cokolwiek

    Cokolwiek Prince

    Joined:
    Dec 17, 2019
    Messages:
    490
    Gender:
    Male
    I am not familiar with terminology, I was applying it to whole AI foriegn policy.
    Can you elaborate or give an example of predictable versus erratic diplomatic situation?
     
    JamesNinelives likes this.
  2. Moi Magnus

    Moi Magnus Emperor

    Joined:
    Mar 1, 2015
    Messages:
    1,867
    I will not take examples in the actual state of VP diplomacy, because I don't know enough of the current code, but here is an hypothetical example:

    Assume two situations for an AI, identical (up to the AI knowledge) in everything but a declaration of friendship with the player. The AI is currently weighting if it should declare war to the player. The friendship declaration was not a fake one made in preparation of a backstab. How should he consider friendship? On one side, friendship is something valuable (and backstab give diplomatic penalties), on the other side, backstab give some tactical advantage from surprise.
    + If you put a weight way too high to friendship, the AI will be too predictable, as having a declaration of friendship might just immune you to wars with that civ.
    + However, if some AI personality make them MORE likely to declare you war to friends than to non-friend (cf Napoleon in BNW), then it is too erratic because the player will just remain puzzled at the situation. [You know, because having a declaration of friendship is supposed to be something good to have...]
     
    JamesNinelives likes this.
  3. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    I'm working on this. :)

    @Moi Magnus proposed an excellent idea where all players are given a military rating that goes up or down when military units are killed, based on your kill/death ratio, the strength of the units, and the military rating of the target. The AI could compare their military rating to other players' and adjust their desire for war based on this. It could also play into other functions, like an AI's choices for friends or Defensive Pacts.

    Delayed trade offers are potentially exploitable (for instance, wait for a DP offer, denounce that AI, then accept to dissuade them from retaliating), not really the case for coop war requests - a few potential issues come to mind, but nothing unresolvable. I'll implement an option to wait one turn and assess the situation at some point. :)

    I wish Civ had a more useful advisor system, because this is actually the kind of thing you could use advisors for if they actually gave good advice.

    I'll poll the community on this.


    Perhaps there could be a general statement somewhere on the deal window, like "The leader will be very grateful to you for this offer" or "This offer will not change the leader's view of you". Or the Opinion number change from making the deal could be displayed, although that's potentially immersion-breaking.

    Sharing intrigue is a slight buff to Opinion, I could note that in the description.

    I honestly don't think you need an exact number to know that insulting or denouncing the AI is going to make them very angry with you. :)


    I'll keep that idea filed under "someday/maybe". It sounds potentially fun, but complicated to handle, and my focus is on improving the existing mechanics first.

    I'm glad you enjoy the diplomacy aspect of the game. I'm not programming the AI for easy mode diplomacy; disabling victory competition is an option for a reason.

    Predictable VS erratic: the AI makes approach calculations every turn to decide how to behave towards other civilizations, and adjusts these values gradually every turn if they change. If the AI considered only a few factors in these decisions, then it would be far too predictable and players would exploit it mercilessly. For instance, many players know that in vanilla BNW, you can sell your excess luxuries for absurdly large amounts of Gold (7 GPT if you have neutral relations), and take advantage of their overvaluation.

    If the AI changed its approach every single time conditions changed, rapidly fluctuating from NEUTRAL to FRIENDLY to HOSTILE to WAR, etcetera, then it would behave too erratically, be impossible to comprehend, and it would never get anything done either.

    "Predictable" and "erratic" are not necessarily opposites, but my point is more that neither of them is desirable at an extreme level.

    A well-designed diplomacy AI behaves in a way that players can observe, understand and respond to (predictability), but that is also able to change, adapt and surprise them (erraticness).

    For this reason, the AI chooses its approach using a large set of factors and adjusts its approach gradually on a curve, so sudden changes in the situation don't upset it - although in some cases, sudden changes in approach are justified. Credit goes to Gazebo and co. for the approach curve and generally making diplomacy a lot better compared to BNW prior to my arrival on the scene.

    Please do not use "gay" to mean "stupid and emotional" in this dismissive way. That kind of language encourages intolerance.

    I think it's fine as Declaration of Friendship; it expresses the meaning just fine, it's been that way for many years and changing it now would cause more confusion than anything else.

    And there are certainly friendships between nations, both historical and current. The world may be a dark and scary place these days, but there is a human element in our nations' governments.
     
  4. burleigh

    burleigh Chieftain

    Joined:
    Apr 22, 2002
    Messages:
    56
    Location:
    Woodford, Essex/London, UK
    Would it be possible when you get the instant requests e.g. for a declaration of friendship (or a war) to get a shortened breakdown of their relationships with that request? For example, I’ve just accepted a declaration of friendship with Greece and been slagged off by other friends who were- unknown to me- Greece’s enemy. Similarly, I’ve gone to war on request with someone who had a defensive pact with a powerful neighbour.
    Generally, the diplomacy is really fantastic- thanks! There seems to be less anti-human diplomatic dog piling in this beta (though I haven't hit the later stages yet, and it could just be down to me not doing as well this game, so I’m less of a threat
     
  5. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    If you play with EUI, the relationship breakdown is visible if you mouse over a leader's portrait in the sidebar or their visible approach.
     
    burleigh likes this.
  6. JamesNinelives

    JamesNinelives Emperor

    Joined:
    Mar 16, 2019
    Messages:
    1,188
    Gender:
    Male
    Location:
    Australia
    That's a cool idea! Maybe included cities gained/lost? Becuase sometimes it's worth sacrificing units to capture/defend a city :).

    Yes. Imo they exist mostly for comedic effect at the moment lol. I like the science advisor who, on turn 1 goes: can found found a city already? Carrying all this equipment if very tiring.
     
    Last edited: Feb 18, 2020
  7. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    Upcoming change for next version:
    Code:
    Adjusted diplomacy AI evaluation of military strength
    - Slight bump to AI valuation of DPs/vassals
    - AI now considers teammates when evaluating military strength
    - New military rating system affects diplo AI's perception of a player's military strength
    
    Military Rating
    - Each major civilization gets a military rating which starts at 0 (cannot go below 0)
    - Losing units/cities/trade routes and having your tiles pillaged reduces your military rating
    - Killing units, plundering trade routes, capturing cities, and pillaging tiles increases your military rating
    - Barbarians don't affect the rating
    - Rating does not decay over time, but changes in later eras matter more than in earlier eras
    - When considering a player's military strength, AI will calculate the percentage difference between that player's rating and the global average rating of other (living) players
       Above average: the % difference will be added to your military strength (max +100% bonus)
       Below average: half of the % difference will be subtracted from your military strength (max -50% penalty)
    - This means that if you're successfully fending off waves after waves of AI units or conquering other civilizations, all AIs will now recognize your military skill and be more reluctant to attack you,
    even if you have a smaller army
    - Military rating modifier is also applied to teammates, DPs, masters/vassals (which are considered to be a portion of your own military strength by the diplo AI)
    - Should increase the odds of human players obtaining DPs, as well
    
    This change should help teach the AI that skilled humans and players with a lot of military advantages are not to be trifled with lightly, although it won't prevent all wars from occurring, and humans will not be able to exploit the system by, say, conquering someone and then disbanding all their military units.

    I'm not skilled at UI work so the military rating will not currently be visible to the player, but I'll work on getting it displayed if the system works.

    Change is experimental, let me know how the AI behaves in the next beta in the feedback thread: https://forums.civfanatics.com/threads/vox-populi-diplomacy-feedback.652134/

    EDIT: Additional adjustment
    Code:
    Removed a few AI-only diplo mods, should hopefully result in humans receiving more DoFs/DPs
    
     
    Last edited: Feb 18, 2020
  8. Guynemer

    Guynemer King

    Joined:
    Feb 20, 2002
    Messages:
    652
    That sounds very interesting, and just reading the concept it seems to make sense. Excited to see it in practice.
     
  9. andersw

    andersw King

    Joined:
    Feb 11, 2008
    Messages:
    886
    Location:
    sweden
    A very ambitious list, I wish you all the good luck.
    Diplo in this game is NOT my strongest part and I fear I will have to adjust.
    Think the Ai gets a bit tetchy? then you havent seen me getting surprise ganked or beaten on a wonder by one turn.
     
  10. CrazyG

    CrazyG Deity

    Joined:
    Oct 14, 2016
    Messages:
    5,098
    Location:
    Beijing
    They believe you are expanding your empire too aggressively

    Spoiler Screenshot :

    20200219103000_1.jpg

    This modifier is really annoying me. I'm playing progress with 6 cities. I have good land to put 2 more down, but I wanted to try and have the AI on my side at least for a while, and they get so mad if you have more cities. Egypt seems upset about Aachen, but I settled that city on turn 90. I gave him plenty of time to put a settler there, he didn't.

    This is actually a reload, my first playthrough I dropped two more settlers and got denounced and warred by everyone instantly (Egypt was so upset he backstabbed me). I'm not expanding too fast, its well within reason and happiness constraints. I think they are all upset that I have 2 more cities than they do. You know what they could do to address that? Build settlers. It's turn 100, most of them have 100% happiness, there's plenty of land. I don't see what's stopping them.
     
    vyyt, Balint2 and Kim Dong Un like this.
  11. kenneth1221

    kenneth1221 Warlord

    Joined:
    Apr 18, 2016
    Messages:
    203
    Dumb question, but where's your army? Your empire looks a tad fragile.
     
    JamesNinelives likes this.
  12. Kim Dong Un

    Kim Dong Un The One & Unly Supporter

    Joined:
    Dec 17, 2017
    Messages:
    668
    Gender:
    Male
    Location:
    Pyongyang
    I'm really intrigued to see this new system in action, but I don't necessarily know if it's a good idea to have trade routes be factored into the equation. A lot of times there's no way to protect multiple routes from being pillaged in a single turn, the first turn after a DoW, and I fear this could skew numbers; there are many instances in late game where you can lose basically all of your routes due to the AI's victory block kicking in when playing for cultural victory. At the same time, having the ability and prowess to sustain protection and ensure your routes travel safely throughout the course of a game should serve as an indication of strength toward the other AI, so I guess it makes sense.

    Only one way to find out!
     
    Heinz_Guderian and Recursive like this.
  13. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    I looked at the code for this and facepalmed.

    There's a < sign where there's supposed to be a > sign.

    THAT explains a lot. Will fix.
     
  14. CrazyG

    CrazyG Deity

    Joined:
    Oct 14, 2016
    Messages:
    5,098
    Location:
    Beijing
    All I have is 3 chariots and a pathfinder, but if someone wars me I'll immediately swap to building units everywhere. Where would I get attacked though? Egypt gave me friendship. Polynesia is far away. Aztec and I fought a war already, the city states bear his attacks. I'm confident I'll have time to react while the chariots stall.
     
  15. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    Wait, never mind, the calculation is correct. It probably has to do with the AI's slower settling speed.

    I'll adjust it so you need 80% more than the global average # of cities (up from 50%) to get the modifier, and see if that helps. There have been a number of reports about this modifier.

    Also, the AI will likely be expanding more next version. If their expansion speed increases I'll tweak it back down, but this should be fine.
     
    Last edited: Feb 18, 2020
  16. JamesNinelives

    JamesNinelives Emperor

    Joined:
    Mar 16, 2019
    Messages:
    1,188
    Gender:
    Male
    Location:
    Australia
    The point though is that if you have lots of cities and few military the AI is supposed to see that as an opportunity to attack you. At least, that's how I understand it.

    Honestly, I think the modifier is doing what it's intended to do - punish reckless expansion. Sure, you can defend that land if you have to, but if the AI has the same attitude you would never have been able to found so many cities. And if the AI left their cities so sparsely defended surely the human player would see that as an opportunity to attack.
     
    tu_79 likes this.
  17. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    I made reckless expansion a worse modifier and AI is expanding slower, so I think it makes some strategic sense to bump up the % threshold a bit. I'll tweak it again next version if needed.
     
    JamesNinelives likes this.
  18. CrazyG

    CrazyG Deity

    Joined:
    Oct 14, 2016
    Messages:
    5,098
    Location:
    Beijing
    Your understanding is off. You get the modifier regardless of how strong your military is, it is based solely on the number of cities. I can edit in some giant death robots and I still get the penalty.
    I don't think my expansion was "reckless" at all. Do you think 6 cities by turn 105 is too many? At the rate the AI goes the continent won't even be filled by Renaissance.
     
  19. Recursive

    Recursive Emperor

    Joined:
    Dec 19, 2017
    Messages:
    1,572
    Gender:
    Male
    No, military strength is factored in.

    Code:
        // If this guy's military is as big as ours, then it probably means he's just stronger than us
       if (ePlayer != GetPlayer()->GetID() && GetPlayerMilitaryStrengthComparedToUs(ePlayer) >= STRENGTH_AVERAGE)
           return false;
    
     
    JamesNinelives likes this.
  20. CrazyG

    CrazyG Deity

    Joined:
    Oct 14, 2016
    Messages:
    5,098
    Location:
    Beijing
    Correct me if I'm wrong.

    It does affect AI's opinion of you.
    But the "They believe you are expanding your empire too aggressively" is based solely on city number, no?
     

Share This Page