AI Gold Spending

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
I've designed a system for the AI to spend its excess gold in v131.15 beta. The game already has a table of AI priorities. Here is Alexander's entry:
Alexander
4 Offense
4 Defense
4 City_Defense
5 Military_Training
4 Recon
3 Ranged
7 Mobile
5 Naval
7 Air
5 Growth
5 Production
5 Gold
6 Science
4 Culture
6 Happiness
4 Great_People
7 Diplomacy​
I use this list as weighted probabilities to pick something to buy when the AI has more gold stored than 200 + 150% research agreement cost (with some special exceptions like emergency defense units).

For example, Alexander is about twice as likely to get a Mobile unit (horse/tank) as a Ranged unit (archer). Depending on the option chosen from the priority list, it checks cities from largest to smallest until it finds an affordable unit/building of the selected priority. Some things like food/growth check from smallest to largest city.

If the "Diplomacy" priority is selected from the list, it selects a citystate to bribe depending on factors like:

  • Favors close citystates.
  • Favors those with 0-60:c5influence: current influence.
  • Favors passing a rival's influence.
  • Militaristic AIs favor militaristic citystates, and vice versa.
  • etc...
 
This sounds amazing, Thal. It is basically a solution to one of the AI's biggest failings, and I'd be shocked if even a rudimentary such sytem didn't make the game much more challenging and fun. Can't wait to try it!

If it works well enough, in fact, I suspect we'll have to tone back the AI's gold bonuses to keep difficulty in check.


One question: what's the reasoning for favoring city-states near 30:c5Influence:Influence? It seems it should favor those closest to Allied status (whether that be 60:c5influence:Influence or the current Ally/rival's :c5influence:Influence), or, failing that, the closest to 60 without being over.
 
Could you clarify your question? A citystate in the 0-60:c5influence: range is closest to an alliance, because most gold gifts provide 30-60:c5influence:, and alliances require at least 60.
 
I guess I'm just thinking that between two City-States at 29:c5influence: and at 59:c5influence:, giving a gift to the latter would be more helpful (more turns of Allied status). I guess it's not clear which is better, depending on how you weigh Allies vs Friends.
 
Ah I see what you mean now. :)

The value of going over 60:c5influence: depends on factors I don't have in the search algorithm. This is where Firaxis's game core takes over. It buys and maintains alliances by considering influence, happiness, resources, proximity, rival influence, etc. It picks up citystates in the 59 range -- and attempts to prevent citystates from dropping down there if already allied.

The problem is the AI-programmer seemed to overlook the strategy of burning excess gold on less-important citystates. Spending gold on suboptimal ones is better than letting the gold sit uselessly in the bank. This is what I'm aiming to fix.



Low priority is given to extremes like super-angry (bad investment) or super-allied (game core handles that). This priority is multiplied by the other factors of distance, militarism, etc. A very close and useful citystate might be good to bribe even if influence is low.
 
I only brought this up because I seem to recall having seen, quite often, AI Civs fail to take back CSs whose Alliances I overtook, even when they had much larger Treasury and gold per turn/net income. But I think it's fair to say it seems you've thought this through and have it under control, Thal. :lol:
(If beta testing suggests there's room for improvement here, that can be dealt with later. I generally play with the Diplomatic victory condition disabled anyhow. If this eventually fixed the AI enough to make the Diplo VC meaningful, I'd be ecstatic!)

The big picture is, this has the potential to greatly improve the AI's play. I assume options A, B, C will be calibrated to each happen a decent % of the time?

One other suggestion: maybe the AI should be more likely to pick up a CS Ally (preferably one with a new luxury resource) if its :c5happy:Happiness is below 0?
 
I have this line:
happinessMod = 1.1 ^ (10 - happiness))


This makes an AI with 10:c5angry: seven times as likely to purchase happiness as an AI with 10:c5happy:. If no happiness buildings are affordable, it uses the fallback of bribing a citystate.
 

Attachments

  • Priority Happiness.PNG
    Priority Happiness.PNG
    10.8 KB · Views: 3,145
Once again it seems you've thought this through much more carefully than I thought! Sounds exactly like, if not better than, what I would've thought of given a few hours and knowing how things worked inside the mod.

Props! Should be lots of fun to try out. (I don't understand how Firaxis manages without someone with your expertise and focus doing what you do!)
 
If it works well enough, in fact, I suspect we'll have to tone back the AI's gold bonuses to keep difficulty in check.

This is what I said originally, but since the ideal game is one in which the AI is competitive without bonuses, lately I've been wondering whether a better answer may be to drop down a difficulty level or two.

Another issue to consider is that, since the AI cannot be competitive militarily or aggressive in building SS parts, it may be in a gray area where its edge in pursuing diplomatic and cultural victories could call for close to "Prince" level play, while the other two still require significant AI bonuses.

All of this is separate from whether game facets like tech research and cultural expansion are balanced at a "fun" level, regardless of the AI.
 
@Dunkah
I skip the unit options if the AI is over its supply cap:
local overSupply = (GetCurrentUnitSupply(player) > GetMaxUnitSupply(player))

...

if overSupply and DoFlavorFunction[row.FlavorType] == PurchaseUnitOfFlavor then
-- skip
I also have priorities set up to favor air units (if the AI has flight), which have no stacking problems.
 
Where do unit upgrades fit in this - offense/defense?
 
Good Point, the AI is always walking around with old units...

Another thing would be to make the AI workers build tile improvements...

So, this system looks perfect! Like a breakthrough, just need to test it now ... ;)
 
Unit upgrades would be feasible, but a different system from purchasing things in cities, so it'd take extra code. I'm hoping to debug what's completed so far before moving on to new things. Altering the tactical AI (for things like giving workers orders) is not feasible.
 
So when is this coming available?

I can't totally speak for Thal, but "When it's ready". He still (as yesterday) hasn't received any feedback from Valve/Firaxis regarding the installation issue so he can't test at the moment which makes development quite hard.
 
Nice that someone else will tackle gold problem. I tried to look it as what XML mods offer but I did not get good grip. I think CS stuff is ok in vanilla. Unit baying and promotions need a lot of work. There are few XML lines which looks like they could operate these things but I am not sure. When source eventually get released baying need to be coupled with AI city production.

Next a bit of rant which is related to topic somehow:

General economic AI sucks in vanilla. Leading to overflow gold and happiness. AI does not have enough maintenance which eats most of the money.

I also like to comment about workers. No worker started after turn 25 because economic AI is bad. This is followed by problem that AI loses them to bards.

Joltis

Ps. I mean this happens at prince difficulty. General economic AI means city building, tech and policies.
 
Great idea! I always wondered why the AI had thousands and thousands of dollars of gold per turn late in the game, and did nothing with it.

One gripe I have, if you can fix it, would be when the AI colonizes far off land. Instead of sending a settler, creating a city, then buying a worker with their tons of gold, they drag a worker along with them through the long journey, and it takes forever for them to start building at that new far off city.
 
Top Bottom