• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.
Resource icon

Adaptive Difficulty v.3

FearSunn

Warlord
Joined
Dec 10, 2017
Messages
277
FearSunn submitted a new resource:

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

Dynamically adapts game difficulty (AI bonuses) during gameplay.
AI tracks human military strength and science yield per turn and tries to get on par.
Bonuses are individual for each AI player and mostly depend on AI diplomatic stance towards human.
AI start to get more bonuses (including on religion, culture and gold) during war times with human. Therefore human player should try to wage his wars quickly and decisively now.
These bonuses stack on top with any other bonuses AI gets from set...

Read more about this resource...
 
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.
 
@FearSunn Would you mind elaborating a bit more on what the AI bonuses are specifically?

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.
 
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?
 
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.
 
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!
 
Going back to the bonus units for a second -
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.
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?
AI gets best possible unit it allowed to have subject to tech progress and resources.
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?
 
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?
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.

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

...would there be any issue if I wanted to add new units from my own or other mods (i.e. Steel + Thunder)?
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.

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?
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".
 
In such situation this AI player wont get any bonus units.
That's good. I was afraid it might cause a crash.
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 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.
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.
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?
 
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?
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.
 
Back
Top Bottom