1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Adaptive Difficulty v.3

Dynamically adapts game difficulty (AI bonuses) during gameplay.

  1. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
    FearSunn submitted a new resource:

    Adaptive Difficulty - Dynamically adapts game difficulty (AI bonuses) during gameplay.

    Read more about this resource...
     
    [to_xp]Gekko likes this.
  2. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
    Just to explain one more important thing with this mod.
    It does nothing to AI per se. Approach taken here is "decorational AI" or "obstacles AI" or however you call it. Main goal is to make this game challenging hence more rewarding for a human player. Therefore I am not pretending here doing something substantial to improve AI.
     
  3. MarigoldRan

    MarigoldRan WARLORD

    Joined:
    Mar 12, 2011
    Messages:
    1,724
    Good mod.
     
  4. Laurana Kanan

    Laurana Kanan Queen's

    Joined:
    Apr 10, 2014
    Messages:
    1,041
    Gender:
    Female
    Location:
    Near the Greatest Snow on Earth
    @FearSunn Would you mind elaborating a bit more on what the AI bonuses are specifically?
     
  5. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
    As requested more detailed explanation how Adaptive difficulty functions.

    With this AI gets 4 types of bonuses:
    1. Combat units;
    2. Religious units;
    3. Wartime with human bonuses;
    4. Shared yields.

    PART 1. Combat units:

    AI tracks human military strength by counting human combat units and gets reinforcements if certain RatioThreshold is reached.
    This RatioThreshold is individual for each AI player and depends on his diplomatic stance towards human.
    Friendly AI_p1 will get additional combat units if Human/AI_p1 combat units RatioThreshold is above 1.6.
    Where Unfriendly will start to get "nervous" at ratio 1/1. AI at war with human will get units until 6/10 (0.6) RatioThreshold.
    Table1: Stance (RatioThreshold):
    DIPLO_STATE_ALLIED 2.5
    DIPLO_STATE_DECLARED_FRIEND 2
    DIPLO_STATE_FRIENDLY 1.6
    DIPLO_STATE_NEUTRAL 1.3
    DIPLO_STATE_UNFRIENDLY 1
    DIPLO_STATE_DENOUNCED 0.8
    DIPLO_STATE_WAR 0.6

    This RatioThreshold is further adjusted by number of friends human has.
    Formula: adjustFriends = (1/aiPlayers)*humanFriends
    So in standard game with 5 AI opponents 1 human friend will give value 0.2.
    This adjustFriends value is added to RatioThreshold.
    Consider a game with 5 ai opponents where human has 2 friends. This would increase RatioThreshold by 0.4
    Now if human engages in war his opponent will get reinforcements till 1/1 (0.6+0.4) RatioThreshold.
    Therefore going to war with no friends would mean you should overcome 0.6 RatioThreshold making such war much harder to win as opposing AI player will get additional units every turn until it reaches 0.6 RatioThreshold (6 human /10 ai).

    So, this is only one part of "adaptive bonuses" AI gets.
    I will gladly answer any questions on this part before going to others.
     
    Laurana Kanan likes this.
  6. Laurana Kanan

    Laurana Kanan Queen's

    Joined:
    Apr 10, 2014
    Messages:
    1,041
    Gender:
    Female
    Location:
    Near the Greatest Snow on Earth
    Great! Thanks for the explanation for this part! How do the additional units work? I see the unit types listed in the LUA file, but is it one unit (of the type based on the most advanced tech researched) per city per turn until the threshold is met?
     
  7. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
    Additional combat units are granted one per turn until threshold is met. Unit is granted in the capital provided it is not under siege. If capital is under siege, another city (not under siege) will be chosen. AI gets best possible unit it allowed to have subject to tech progress and resources.
    Therefore it is a good strategy to deny AI from strategic resources and siege AI cities during war.

    ps.New version is almost ready for upload. My explanations here are based on new upcoming version therefore ignore for the moment some discrepances with current Lua code you may notice.
     
    Laurana Kanan likes this.
  8. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
  9. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
    PART 2
    Shared Yields (Science, Culture, Faith)

    AI tracks human player yields per turn and gets some part of yields difference (DifferenceAdjustment).
    For example if human yields 100 Science per turn and AIp1 gets 60 then difference is 40.
    From this 40 AIp1 gets DifferenceAdjustment depending on diplomatic stance towards human:
    At War and Denounced gets 1 (all 40). Unfriendly gets 0.8 (40*0.8=32). Neutral-0.6. Friendly-0.4. Declared-0.2. Ally gets nothing.

    This setup makes diplomacy important as you will share less yields the better your relations are.
    But this is just one part of yield sharing. Another part - AI share yields among themselves.
    Each AI player gets part of another AI yields provided they have net and are neutral or friendly.
    Neutral gives 0.25 of yields, where friendly and above shares 0.5
    This is further adjusted by number of human friends (adjustFriendsGlobal) and human relations with specific AI player (fFactor).
    Bottom line: more friends AI player has more shared yields from other AI it gets. Human can prevent this by befriending with AI player.
    Again Diplomacy is at paramount importance here!
     
  10. Laurana Kanan

    Laurana Kanan Queen's

    Joined:
    Apr 10, 2014
    Messages:
    1,041
    Gender:
    Female
    Location:
    Near the Greatest Snow on Earth
    Going back to the bonus units for a second -
    This may be a fringe situation, but what happens if the capital is under siege and is also the last city? Or, another situation where the AI doesn't have any city that isn't under siege?
    Going by what the order and type of units you have listed under "if not isWarmonger then", I think it might be better to pick only a single class of unit, like only Melee or Ranged, rather than a mix of different kinds. For example, I can't imagine the AI effectively using multiple Horsemen rather than multiple Swordsmen. Speaking of which, would there be any issue if I wanted to add new units from my own or other mods (i.e. Steel + Thunder)?

    Last thing I'm concerned with is Maintenance Costs. How well do you expect the AI to handle the extra cost of these bonus units considering they're notorious for being bankrupt and disbanding units?
     
  11. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
    In such situation this AI player wont get any bonus units. This is done intentionally. While giving some advantage to the AI this mod also gives some tools for human player to overcome this. Making the game more deep strategically.

    From coding point of view I am not sure it is possible to grant "abstract" class unit. Lua method requires specific type of unit as an argument. AI will get best possible unit subject to tech and resources. I think this is ok. AI is terrible on tactical level we all know, but with more units it is now a real threat, not just distraction.

    AI will not get such custom made units as bonus. AI will build them on its own as usual but wont get them from this script.

    AI will get bonus units only if it could afford them. Script checks for AI player balance before granting. I've never seen this is a problem for AI. But I always play with More Strategy mod where AI trained to value gold more. Therefore my experience here might be different from base game.
    Btw Ai will not get any units if it is at war with another AI and not human. This exception is needed to ensure wars among AI are still "fair".
     
  12. Laurana Kanan

    Laurana Kanan Queen's

    Joined:
    Apr 10, 2014
    Messages:
    1,041
    Gender:
    Female
    Location:
    Near the Greatest Snow on Earth
    That's good. I was afraid it might cause a crash.
    I didn't mean an "abstract" class unit. I meant instead of having Swordsmen, Crossbowmen, Horsemen, etc. (many different classes, some of which the AI doesn't utilize well), have only Warriors, Swordsmen, Musketmen, etc. (all Melee class, which the AI uses more effectively). This is probably more for my own benefit since I've heavily modified all units. For example, giving machine gun bonus units en masse to the AI would be a waste since I have them as new unit class that functions more like a support unit that grants bonuses to other units.
    So you're saying that if I add, for example, the Rifleman unit from Steel & Thunder to your script and make sure this mod loads after that one it won't work?
     
  13. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male
    If this Rifleman from another mod is implemented correctly and you just edit AdjustBonuses.lua in a proper way it wont cause any problems. Mods load order irrelevant here. Adaptive Difficulty is a script not database entry.
     
  14. FearSunn

    FearSunn Chieftain

    Joined:
    Dec 10, 2017
    Messages:
    189
    Gender:
    Male

Share This Page

Ebates: Get Paid to Shop