Diplomacy AI Development

How do the AI pick social policies? I've found they've been picking pretty sub optimally recently. For instance one civ picked Progress and only settled 4 cities, another picked authority but never went to war.
This is also partially a problem with the AI not warring enough, especially Authority AI. Because of this all the authority civs fell really, really far behind - one of them was still working on their medieval era policy when I got a ideology. This is partially because I was playing on a map with more water, but even very close neighbors that hated each other didn't go to war that often.
 
How do the AI pick social policies? I've found they've been picking pretty sub optimally recently. For instance one civ picked Progress and only settled 4 cities, another picked authority but never went to war.
This is also partially a problem with the AI not warring enough, especially Authority AI. Because of this all the authority civs fell really, really far behind - one of them was still working on their medieval era policy when I got a ideology. This is partially because I was playing on a map with more water, but even very close neighbors that hated each other didn't go to war that often.
That depends on difficulty. AI takes optimal choices on Immortal and Diety.
 
Does AI CS anger only occur with allies (and the lowering of their influence), or does it happen with friendships too?

India just asked me to not get friendly with Monaco...but I am not their ally (and never have been), and I haven't used any GD on them, so I am not sure why they are upset.
 
India just asked me to not get friendly with Monaco...but I am not their ally (and never have been), and I haven't used any GD on them, so I am not sure why they are upset.
He must just think you're a cutie-patootie and feel threatened that you may swoop in to eventually steal his "Mon"...;)
 
Why? Shouldn't they make more or less optimal decisions either way, but get less bonuses on easier difficulties?
Even though I play King/Emp games, I change the settings for the AI to always use the best options for policies/building selection.
 
How do the AI pick social policies? I've found they've been picking pretty sub optimally recently. For instance one civ picked Progress and only settled 4 cities, another picked authority but never went to war.
This is also partially a problem with the AI not warring enough, especially Authority AI. Because of this all the authority civs fell really, really far behind - one of them was still working on their medieval era policy when I got a ideology. This is partially because I was playing on a map with more water, but even very close neighbors that hated each other didn't go to war that often.

That depends on difficulty. AI takes optimal choices on Immortal and Diety.

Authority AI aggression should be restored for the next version. As for policy choices, Immortal/Deity AIs always pick the highest scoring choice whereas lower difficulty AIs pick randomly between the top 2/3. The decision-making process is in the CvPolicyAI file - I haven't looked closely at it.

Does AI CS anger only occur with allies (and the lowering of their influence), or does it happen with friendships too?

India just asked me to not get friendly with Monaco...but I am not their ally (and never have been), and I haven't used any GD on them, so I am not sure why they are upset.

It's primarily based on how close your Influence totals are to each other, and it can happen if you're not allies. Lowering their influence (especially repeatedly) nets an additional penalty that intensifies the competition.

Why? Shouldn't they make more or less optimal decisions either way, but get less bonuses on easier difficulties?

I'm not the one who designed it that way (it's actually a Firaxis decision), but I think it was added as a simple way to tweak AI skill by difficulty. It also applies to tech and city production choices.
 
I'm not the one who designed it that way (it's actually a Firaxis decision), but I think it was added as a simple way to tweak AI skill by difficulty. It also applies to tech and city production choices.
No! It was Gazebo's brilliant way to have AI's intelligence increase with difficulty. This is my most favorite example of the smart, yet simple things, which make VP so great.
 
No! It was Gazebo's brilliant way to have AI's intelligence increase with difficulty. This is my most favorite example of the smart, yet simple things, which make VP so great.

Those difficulty settings exist in BNW - look it up. :)

He did make the selection AI much smarter and lowered randomness, though.
 
Those difficulty settings exist in BNW - look it up. :)

He did make the selection AI much smarter and lowered randomness, though.
I will do no such thing. I refuse to even consider this blasphemous idea! :)

I'd swear it was introduced in VP a few years back. Either way, I like the system of ranking of the possible decisions and then picking randomly from the best ones nicely simulating intelligence.
 
Hot take: AI shouldn't vote for Spaceflight regulations resolution if science victory is turned off
 
I'm not the one who designed it that way (it's actually a Firaxis decision), but I think it was added as a simple way to tweak AI skill by difficulty. It also applies to tech and city production choices.
I will do no such thing. I refuse to even consider this blasphemous idea! :)

I'd swear it was introduced in VP a few years back. Either way, I like the system of ranking of the possible decisions and then picking randomly from the best ones nicely simulating intelligence.

I see. I could maybe see why there is variety choice in production/tech, but with policies picking the top 2/3 out of 3 choices is almost random.
 
Hot take: AI shouldn't vote for Spaceflight regulations resolution if science victory is turned off

Fixed for next version, thanks for pointing it out. While fixing, also discovered and fixed a bug causing the AI to support Spaceflight Regulations whilst currently going for Science Victory (was adding 500 score instead of subtracting).
 
Progress update on my diplomacy AI rework: I've gathered all the memory-related code in one place and categorized/organized it, which was desperately missing, as well as separated all the memory-related functions (and there are a lot) from the rest of the code.

I've also cut down on excess memory consumption by reducing arrays that were storing data for a maximum of 63-80 players (for no reason) to a lower size, sometimes as low as 22.

Next I will remove unnecessary memory values, add new ones, and rename others - then do some testing to make sure everything works properly and there are no crashes. Fixing the memory system is without a doubt the most boring part of the rework, but I'm getting through it despite my limited free time, and there's more exciting things to come after that.

Here's a sneak peek at what I want the DoTurn() function (wherein the AI updates all its diplomacy-related values, makes decisions, and contacts other players) to look like in the future. This is a draft, of course.
Code:
/// Runs every turn!  The order matters for a lot of this stuff, so be VERY careful about moving anything around (!)
/// Recursive: Modified the order of things here substantially. The AI-only check in this function has been replaced by AI-only checks in all the functions called for additional flexibility.
void CvDiplomacyAI::DoTurn(DiplomacyPlayerType eTargetPlayer)
{
   // Function start
   m_eTargetPlayer = eTargetPlayer;
   ////////////////////

   // War damage decay and war state evaluation - comes before everything else!
   DoWarDamageDecay();
   DoUpdateWarDamageLevels();
   DoEstimateOtherPlayerWarDamageLevels();
   DoUpdateWarStates();

   // First evaluation of war and military statistics! We will evaluate again after changing our Opinion, Approach & War Status below.
   // Update strength assessments
   DoUpdatePlayerMilitaryStrengths();
   DoUpdatePlayerEconomicStrengths();
   DoUpdatePlayerTargetValues();

   // Update threat levels
   DoUpdateMilitaryThreats();
   DoUpdateWarmongerThreats();
   DoUpdateWarProjections();

   // First evaluation of peace willingness
   DoUpdateWarProjections();
   DoUpdateWarGoals();
   DoUpdatePeaceTreatyWillingness();

   // Forget about diplomatic penalties that have expired
   DoForgetExpiredPenalties();

   // Update aggressive postures
   DoUpdateMilitaryAggressivePostures();
   DoUpdateExpansionAggressivePostures();
   DoUpdatePlotBuyingAggressivePostures();

   // Update anything relating to promises made by other players
   DoUpdatePromiseStatus();

   // Update direct competition dispute levels
   DoUpdateLandDisputeLevels();
   DoUpdateWonderDisputeLevels();
   DoUpdateMinorCivDisputeLevels();

   // Update victory-based dispute levels
   DoUpdateVictoryDisputeLevels();
   DoUpdateVictoryBlockLevels();

   // Update our estimates of what we think other players are up to
   DoEstimateOtherPlayerMilitaryThreats();
   DoEstimateOtherPlayerWarmongerThreats();
   DoUpdateEstimateOtherPlayerLandDisputeLevels();
   DoUpdateEstimateOtherPlayerWonderDisputeLevels();
   DoUpdateEstimateOtherPlayerMinorCivDisputeLevels();
   DoUpdateEstimateOtherPlayerVictoryDisputeLevels();
   DoUpdateEstimateOtherPlayerVictoryBlockLevels();

   // Update our estimates of what other players think of each other
   // Do ourselves last, since it's the most important to us, and we'll have more information going into the evaluation
   DoEstimateOtherPlayerOpinions();
   DoEstimateOtherPlayerApproaches(); // AI makes share opinion requests of other AIs as part of this
   DoUpdateOpinionTowardsUsGuesses();
   DoUpdateApproachTowardsUsGuesses();

   // Are any players now untrustworthy to us?
   DoUpdateUntrustworthyFriends(/*bTeamCheck*/ false); // Sets to true if the individual player is untrustworthy, false otherwise
   DoUpdateUntrustworthyFriends(/*bTeamCheck*/ true); // Sets to true if the individual player OR anyone on that player's team is untrustworthy, false otherwise

   // Test if any players are easy attack targets
   DoUpdateEasyAttackTargets();

   // Opinion
   DoUpdateOpinions();

   // Approach
   vector<PlayerTypes> v; // Need an empty vector here, since on normal turn updates, no players are being reevaluated
   DoUpdateMajorCivApproaches(v, /*bBetweenTurnsUpdate*/ false); // A between turns update will call DoUpdatePlannedWarsAndDemands(), but the normal turn update won't (also matters for the approach curve)

   // Special Case War Stuff
   // All of these functions may trigger WAR! and a subsequent reevaluation of opinions/approaches.
#if defined(MOD_DIPLOMACY_CIV4_FEATURES)
   if (MOD_DIPLOMACY_CIV4_FEATURES)
   {
       DoRequestIndependence(); // Request independence from our master
   }
#endif
   DoProcessCoopWars(); // Handles everything involving existing coop war agreements
   DoSendWarTauntsToAIPlayers(); // Send move troops requests and certain taunts to AI players!
   DoSendWarTauntsToHumanPlayers(); // Send move troops requests and certain taunts to humans in singleplayer! Handled differently in multiplayer.

   // Normal War Stuff
   DoUpdatePlannedWarsAndDemands(); // Plan any other wars we want to declare, as well as demands we want to make
   MakeWar(); // Declare war, if we're ready
   MakeDemands(); // Make demands of other civs, if we're ready

   // Minor Civ Approach
   DoUpdateMinorCivApproaches();

   // Second evaluation of war and military statistics - functions above may have changed it!
   // bUpdateLogsSpecial is set to true for all of these functions - don't update the logs if no change happened
   DoUpdateWarDamageLevels(true);
   DoEstimateOtherPlayerWarDamageLevels(true);
   DoUpdateWarStates(true);
   DoUpdatePlayerMilitaryStrengths(true);
   DoUpdatePlayerEconomicStrengths(true);
   DoUpdatePlayerTargetValues(true);
   DoUpdateMilitaryThreats(true); // DoUpdateWarmongerThreats is updated whenever warmongering penalties change, so don't update that here
   DoUpdateWarProjections(true);

   // Second evaluation of peace willingness
   DoUpdateWarGoals(true);
   DoUpdatePeaceTreatyWillingness(true);

   // Make peace with humans we're at war with (humans are usually the biggest threat, so this is an exception to the "contact AIs first" rule).
   DoMakePeaceWithHumanPlayers();

   // Make peace with AI major civs we're at war with
   DoMakePeaceWithAIPlayers();

   // Make peace with City-States we're at war with
   DoMakePeaceWithMinors();

   // Update our valuation of other players as friends and enemies
   DoRelationshipPairing();
   DoUpdateDefensivePactValuation(); // DP valuation uses Friend/Competitor values from DoRelationshipPairing(), so it needs to be updated separately

   // Planning Exchanges - Update our desire for Declarations of Friendship, Defensive Pacts and Research Agreements
   DoUpdatePlanningExchanges();

#if defined(MOD_DIPLOMACY_CIV4_FEATURES)
   // Select the tax rate for our vassals, if we can
   if (MOD_DIPLOMACY_CIV4_FEATURES)
   {
       DoDetermineTaxRateForVassals();
   }
#endif

   // Any minor civs we want to chat with?
   DoContactMinorCivs();

   // Any major civs we want to chat with?
   DoContactAIPlayers(); // AI players are contacted FIRST, and humans LAST! If the AI wants a trade item (including vassalage) from a human, this is recorded for DoContactHumanPlayers (to make sure AI-to-AI trading doesn't deprive the human of all opportunities).
   DoContactHumanPlayers(); // As part of DoContactHumanPlayers, if the human refuses the trade, AI may then attempt to trade for the item with other AI players before resuming discussion with the human.

   // Logging
   LogTurnStatus();

   ////////////////////
   // Function end
   m_eTargetPlayer = DIPLO_ALL_PLAYERS;
}

I intend for the AI to be able to make multiple statements in a single turn to cut back on spam and make the AI more intelligent overall. The current AI has no capability to do this, but my future one will. :)
 
Last edited:
One important change I want to make to deal AI, in addition to allowing them to make multiple statements in one turn, is to change offers from the AI so that you cannot remove the items they requested from your side of the deal table when it is not your turn (since the AI is asking you "what do you want for this?" not "do you want to make any deal whatsoever?"). You will still be able to offer and request more if you like, of course.

This will apply between AIs as well, and will allow for more strategic trading on the part of the AI. If you refuse to sell, say, Iron to the AI - they can go to other AI players, trade for Iron, and then make a second offer for something else they want.

I'm thinking a "refuse all trades with this leader" checkbox may also come in handy here.

And the AI will rank the things they want from other players in order of priority, asking for the most important items first.

This kind of sophisticated logic is entirely absent from the base game, but when I actually figure it out I think the end result will be very impressive. :)

Figuring this all out for multiplayer is going to be a pain, though...

Really impressive all the work you are doing. The AI is already so much better than the basic game.

I'm glad you're enjoying it!
 
I'm thinking a "refuse all trades with this leader" checkbox may also come in handy here.

I think if nothing else this would be good for very late game. Your going for your win and you now longer care about a few deals here and there....I usually just agree to whatever deal the AI wants at this point just to keep them quiet. So such a button would be extremely handy.
 
Top Bottom