Strategic Resource Valuation – The Formula

axatin

Prince
Joined
Jul 24, 2022
Messages
478
I've been asked to explain the formula used by the AI to calculate the Deal Value of Strategic Resources (@saamohod). This formula could probably be improved, so feel free to suggest changes to it.

Preliminaries:
- On Standard Speed, 1 GPT always corresponds to a Deal Value of 40
- I will describe valuation from the AI perspective, so "Sell Price" refers to the price used when the AI sells a resource
- I will skip some technical details of the formula, which shouldn't have much of an effect


There are 4 steps to calculate deal valuation:

1. Base Value for a single Resource Item
Spoiler :

Each Strategic Resource has a base Deal Value of 50, scaling by 25 per era. Or, in terms of GPT: 1.25 GPT, scaling by 0.625 GPT per Era.

EraAncientClassicalMedievalRenaissanceIndustrialModernAtomicInformation
Deal Value5075100125150175200225
GPT1.251.8752.53.1253.754.37555.625


2. Increase for excess GPT
Spoiler :

Prices are increased based on the excess Gold per Turn of the paying player. The formulas:

If the AI is buying, prices are increased by: sqrt((excess GPT of AI player)/4)*5
Excess GPT of AI Player10501002005007501000
Deal Value8182535566880
GPT0.20.450.630.881.401.711.97

If the AI is selling, prices are increased by: sqrt((excess GPT of Human player)/5)*5
Excess GPT of Human Player10501002005007501000
Deal Value7162232506170
GPT0.180.40.560.791.251.531.76

The value added can not exceed the Base Value.


3. Modifiers
Spoiler :

Prices are multiplied by some modifiers:

Uranium Resource:
Buy and Sell Price: *2

Human Player has a stronger military than the AI:
Sell Price: *1.45
Buy Price: *0.8

The players are neighbors:
Sell Price: *1.1
Buy Price: *0.7

AI is going for a Science win:
Sell Price Aluminum: always NA
Buy Price Aluminum: *1.25

Some Modifiers for Netherlands [skipped]

Resource Ratio:
Sell Price increased if the AI has less total Resources of that type than we have, and vice versa
Buy Price increased if the AI has more total Resources of that type than we have, and vice versa (why is that? the AI pays more if it already has a lot?...)
Sell/Buy price are multiplied with the ratio of the number of resources, lower bound *0.5, upper bound *1.25 (buying) or *2 (selling)

Modifiers based on AI opinion
For example: Friendly approach:

Sell Price: *0.9
Buy Price: *1.1


4. Valuation for each Resource Entity in the Deal
Spoiler :

For each entity of the resource in the deal, the value calculated in steps 1-3 is modified based on the amount of excess resources the AI would have after buying/selling it.

AI Buying:
Excess Amount of Res. after the deal-1012345+
Modifier1.51.510.850.70.550

AI Selling:
Excess Amount of Res. after the deal0123+
ModifierNA10101


Example:
Spoiler :

Industrial, Turn 257, abundant Resource settings, I'm trading with Theodora.

For 3 Horses, Theodora offers me a Deal Value of 294 (8 GPT).
Screenshot (401).png

Let's follow through the steps of how this value is calculated:
StepDeal ValueGPTComments
1. Base Value1503.75Industrial Era
2. Adjustment for excess GPT1604Theoroda has only 26 excess GPT, so she's not willing to pay much
3. Military Might1253.125Theodora is weaker than me, so she pays less to not support me even further
3. Resource Ratio1303.25Theodora has 31 Horses in total, I have 29, so Theodora is willing to pay a bit more
3. Approach1403.5We are friends, so I get favorable trade offers

For each Horse Item, we therefore have a value of 140. Theodora currently has 1 excess Horse, so the 3 Horses added would be number 2, 3, and 4. Following the table in Section 4, the deal values for these items are multiplied by 0.85, 0.7, and 0.55.
The total resource valuation is therefore 140*(0.85+0.7+0.55) = 294, which corresponds to 8 GPT (rounded up).

If I wanted to buy 3 Iron from Theodora, the Deal Value would be 1,575 (40 GPT).
Screenshot (400).png

StepDeal ValueGPTComments
1. Base Value1503.75Industrial Era
2. Adjustment for excess GPT2255.625I have 845 excess GPT, so I have to pay much more for everything
3. Military Might3208Theodora is weaker than me, so she doesn't want to sell strategic resources at a low price to me
3. Resource Ratio58514.625I have 108 Iron in total, Theodory only 59, so the selling price is modified by 108/59 = 1.83
3. Approach52513.125We are friends, so I get favorable trade offers

Theodora currently has 24 excess Iron, the 3 Iron sold would leave her with 23, 22, 21 after the deal. As she still has much excess Iron left, she doesn't ask for higher prices, the modifiers are 1, 1, and 1.
In total: Deal Value of 525*(1+1+1) = 1575, or 40 GPT (rounded up)
 
Last edited:
I've been asked to explain the formula used by the AI to calculate the Deal Value of Strategic Resources (@saamohod). This formula could probably be improved, so feel free to suggest changes to it.

Preliminaries:
- On Standard Speed, 1 GPT always corresponds to a Deal Value of 40
- I will describe valuation from the AI perspective, so "Sell Price" refers to the price used when the AI sells a resource
- I will skip some technical details of the formula, which shouldn't have much of an effect


There are 4 steps to calculate deal valuation:

1. Base Value for a single Resource Item
Spoiler :

Each Strategic Resource has a base Deal Value of 50, scaling by 25 per era. Or, in terms of GPT: 1.25 GPT, scaling by 0.625 GPT per Era.

EraAncientClassicalMedievalRenaissanceIndustrialModernAtomicInformation
Deal Value5075100125150175200225
GPT1.251.8752.53.1253.754.37555.625


2. Increase for excess GPT
Spoiler :

Prices are increased based on the excess Gold per Turn of the paying player. The formulas:

If the AI is buying, prices are increased by: sqrt((excess GPT of AI player)/4)*5
Excess GPT of AI Player10501002005007501000
Deal Value8182535566880
GPT0.20.450.630.881.401.711.97

If the AI is selling, prices are increased by: sqrt((excess GPT of Human player)/5)*5
Excess GPT of Human Player10501002005007501000
Deal Value7162232506170
GPT0.180.40.560.791.251.531.76

The value added can not exceed the Base Value.


3. Modifiers
Spoiler :

Prices are multiplied by some modifiers:

Uranium Resource:
Buy and Sell Price: *2

Human Player has a stronger military than the AI:
Sell Price: *1.45
Buy Price: *0.8

The players are neighbors:
Sell Price: *1.1
Buy Price: *0.7

AI is going for a Science win:
Sell Price Aluminum: always NA
Buy Price Aluminum: *1.25

Some Modifiers for Netherlands [skipped]

Resource Ratio:
Sell Price increased if the AI has less total Resources of that type than we have, and vice versa
Buy Price increased if the AI has more total Resources of that type than we have, and vice versa (why is that? the AI pays more if it already has a lot?...)
Sell/Buy price are multiplied with the ratio of the number of resources, lower bound *0.5, upper bound *1.25 (buying) or *2 (selling)

Modifiers based on AI opinion
For example: Friendly approach:

Sell Price: *0.9
Buy Price: *1.1


4. Valuation for each Resource Entity in the Deal
Spoiler :

For each entity of the resource in the deal, the value calculated in steps 1-3 is modified based on the amount of excess resources the AI would have after buying/selling it.

AI Buying:
Excess Amount of Res. after the deal-1012345+
Modifier1.51.510.850.70.550

AI Selling:
Excess Amount of Res. after the deal0123+
ModifierNA10101


Example:
Spoiler :

Industrial, Turn 257, abundant Resource settings, I'm trading with Theodora.

For 3 Horses, Theodora offers me a Deal Value of 294 (8 GPT).
View attachment 666497
Let's follow through the steps of how this value is calculated:
StepDeal ValueGPTComments
1. Base Value1503.75Industrial Era
2. Adjustment for excess GPT1604Theoroda has only 26 excess GPT, so she's not willing to pay much
3. Military Might1253.125Theodora is weaker than me, so she pays less to not support me even further
3. Resource Ratio1303.25Theodora has 31 Horses in total, I have 29, so Theodora is willing to pay a bit more
3. Approach1403.5We are friends, so I get favorable trade offers

For each Horse Item, we therefore have a value of 140. Theodora currently has 1 excess Horse, so the 3 Horses added would be number 2, 3, and 4. Following the table in Section 4, the deal values for these items are multiplied by 0.85, 0.7, and 0.55.
The total resource valuation is therefore 140*(0.85+0.7+0.55) = 294, which corresponds to 8 GPT (rounded up).

If I wanted to buy 3 Iron from Theodora, the Deal Value would be 1,575 (40 GPT).
View attachment 666498
StepDeal ValueGPTComments
1. Base Value1503.75Industrial Era
2. Adjustment for excess GPT2255.625I have 845 excess GPT, so I have to pay much more for everything
3. Military Might3208Theodora is weaker than me, so she doesn't want to sell strategic resources at a low price to me
3. Resource Ratio58514.625I have 108 Iron in total, Theodory only 59, so the selling price is modified by 108/59 = 1.83
3. Approach52513.125We are friends, so I get favorable trade offers

Theodora currently has 24 excess Iron, the 3 Iron sold would leave her with 23, 22, 21 after the deal. As she still has much excess Iron left, she doesn't ask for higher prices, the modifiers are 1, 1, and 1.
In total: Deal Value of 525*(1+1+1) = 1575, or 40 GPT (rounded up)
[/SPOILER

I always appreciate insight into the formulas thank you.

a couple of questions:

1) In the first example: I got the following:

Base: 150
Excess GPT: 26, SQRT(26/4) = 2.5495, *5 = 12.748
150 + 12.748 = 162.7 = 162 (my assumption is that the decimal is dropped?)

Military Might: .8
162 * .8 = 129.6 = 129


So I'm getting a bit different than you are. Is there some rounding going on somewhere in the formula?


2) The resource ratio to me didn't make sense. Can you walk through the actual math in the first example? Its the upper and lower bound multipliers that are throwing me off.
 
Also just confirming, does the base value actually scale at classical? (normal era scale formula has ancient = classical, so just confirming if that was a mistake or if the formula is a unique era scaling)
 
Thanks for posting this!

Some quick brainstorming on some of these values:

  • Sort of minor but if I recall correctly other instances of "scaling with era" start after Classical.
    • One idea might be to tweak this progression to mirror other mechanics while up-valuing later game resources. E.g. Ancient - 50; Classical - 50; Medieval - 100; Renaissance - 150; Industrial - 200; ...
  • Might be worth taking a look at other resources to give a base price bump along with uranium. Coal and oil come to mind.
  • The sell/buy modifiers seem off in a number of ways.
    • If my military is stronger than the AI, I get that they might sell high to me, but shouldn't they also buy high from me, to cut into my combat capabilities?
    • Same thought with neighbors, if they are next to me wouldn't they be in favor of fewer premium units in my army?
    • As you noted, the resource ratio is weird. I can't think of a strategic or tactical reason it matters if they have more or less than me of a certain resource, unless you're just trying to do monopoly things like prevent everyone in the world from fielding swordsmen (which seems like it should be captured in the excess amount calculations instead).
    • The ratio of resources relative to the global total makes some amount of sense, because it reflects your ability to source those items elsewhere, but there might be some tuning opportunity (especially relative to era? you aren't really comparing resources the other continent has until crossing the ocean).
  • The valuations seem fairly aggressive on the selling angle. Maybe it's needed though, hard to say.
  • I'm curious about a few more of the specific AI opinion modifiers.
    • I feel like being friends should matter quite a bit to whether I can trust a civ not to turn these resources against me.
    • That said, if they were to take their superior army and turn on me, they'd lose the trade deal that helped support their army, so I'm not sure in practice how that might play out.
 
Is there some rounding going on somewhere in the formula?
For all the calculations in step 1-3, the deal values in each step are rounded down to the next multiple of 5.

Also just confirming, does the base value actually scale at classical?
It indeed scales at classical, unlike the era scaling used in other contexts.

The resource ratio to me didn't make sense. Can you walk through the actual math in the first example? Its the upper and lower bound multipliers that are throwing me off.
Theodora has 31 horses, I have 29, so the value from the previous step is multiplied by 31/29. We then have 125*31/29 = 133.62, rounded down to 130.
The bounds only mean that the value that's multiplied with can't be lower than 0.5, even if the real resource ratio is. And it can't be higher than 1.25 (or 2, respectively).

I'm curious about a few more of the specific AI opinion modifiers
Spoiler Selling :

case CIV_APPROACH_FRIENDLY:
iItemValue *= 90;
iItemValue /= 100;
break;
case CIV_APPROACH_AFRAID:
iItemValue *= 90;
iItemValue /= 100;
break;
case CIV_APPROACH_NEUTRAL:
iItemValue *= 100;
iItemValue /= 100;
break;
case CIV_APPROACH_GUARDED:
iItemValue *= 125;
iItemValue /= 100;
break;
case CIV_APPROACH_DECEPTIVE:
iItemValue *= 150;
iItemValue /= 100;
break;
case CIV_APPROACH_HOSTILE:
iItemValue *= 200;
iItemValue /= 100;
break;
case CIV_APPROACH_WAR:
iItemValue *= 600;
iItemValue /= 100;
break;

(0.9 for friendly, 1.0 for neutral and so on)

Spoiler Buying :

case CIV_APPROACH_FRIENDLY:
iItemValue *= 110;
iItemValue /= 100;
break;
case CIV_APPROACH_AFRAID:
iItemValue *= 110;
iItemValue /= 100;
break;
case NO_CIV_APPROACH:
case CIV_APPROACH_NEUTRAL:
iItemValue *= 100;
iItemValue /= 100;
break;
case CIV_APPROACH_GUARDED:
iItemValue *= 80;
iItemValue /= 100;
break;
case CIV_APPROACH_DECEPTIVE:
iItemValue *= 100;
iItemValue /= 100;
break;
case CIV_APPROACH_HOSTILE:
iItemValue *= 50;
iItemValue /= 100;
break;
case CIV_APPROACH_WAR:
iItemValue *= 25;
iItemValue /= 100;
break;
}
 
Why only human? What about AI-AI trades?

The increase for excess GPT on the sell price is redundant. It's already factored in the (perceived if human) buy price, where it makes sense. This is already removed from luxury valuation, I believe.

Coal is just as important as Uranium.

By "excess amount of resources after the deal", does it count the resources imported/exported in other deals or from CS? I think it shouldn't for the selling part.
 
Last edited:
Excellent, thank you.

Ok so a few thoughts off the bat:

  • I honestly think a simple era scaling really doesn't account for the scarity/need of certain resources. For example, horses should have highest value in Medieval due to knights. Iron should have very high value in Industrial due to cruisers and field guns being such an important unit. So I think there should be some more situational modifiers for those (if iron and age = industrial, value = x2, kind of thing)
  • Total resource consideration to me is a non-factor. I'm never trading strategics based on how many exist in the world. I care about what one thing.....do I need horses, and who can give me horses? So I think that modifier should be removed.
  • The buy and sell modifiers seem flipped to me. I would expect my neighbor to value the strategics they sell to me more than normal, as they are taking on increased risk.
  • I would make uranium like 3 - 4x honestly, its rare and super powerful in the late game.
  • for excessive resource, I don't think I would allow any modifier that pushed it past +2. I generally don't stockpile strategics, if I need more (aka I build the units) than I will go out and seek more trades. But I'm not buying 5 horses just because.
  • Coal probably should have a unique need mechanic as its very specific.
    • up till 8 coal (aka 2 coal in my core 4 cities): Coal is SUPER VALUABLE. AIs should be offering me truckloads to take coal off my hands at this point.
    • up to 2 per city: Coal is REALLY valuable.
    • past 2 coal per city: Coal's value to me plummets.
 
Excellent, thank you.

Ok so a few thoughts off the bat:

  • I honestly think a simple era scaling really doesn't account for the scarity/need of certain resources. For example, horses should have highest value in Medieval due to knights. Iron should have very high value in Industrial due to cruisers and field guns being such an important unit. So I think there should be some more situational modifiers for those (if iron and age = industrial, value = x2, kind of thing)
  • Total resource consideration to me is a non-factor. I'm never trading strategics based on how many exist in the world. I care about what one thing.....do I need horses, and who can give me horses? So I think that modifier should be removed.
  • The buy and sell modifiers seem flipped to me. I would expect my neighbor to value the strategics they sell to me more than normal, as they are taking on increased risk.
  • I would make uranium like 3 - 4x honestly, its rare and super powerful in the late game.
  • for excessive resource, I don't think I would allow any modifier that pushed it past +2. I generally don't stockpile strategics, if I need more (aka I build the units) than I will go out and seek more trades. But I'm not buying 5 horses just because.
  • Coal probably should have a unique need mechanic as its very specific.
    • up till 8 coal (aka 2 coal in my core 4 cities): Coal is SUPER VALUABLE. AIs should be offering me truckloads to take coal off my hands at this point.
    • up to 2 per city: Coal is REALLY valuable.
    • past 2 coal per city: Coal's value to me plummets.
Oh yeah, some special clause:
After every horse unit obsoletes, horses should be worth nothing (IMPOSSIBLE!) after 2x per city (for Agribusiness). I've set Rocketry to be the tech that AI stops buying horses (in complete-merge), but it can be more finely conditioned in the DLL.
Coal should always be worth nothing if you have more than 2 per city.
 
In my game the AI will buy with the same price for a single repeatedly, but will buy for less for each sucessive in a stack. So 4 horse will sell for 2 each if I sell them individually, but in a stack of 4 will only sell for 5. This way its never good to sell more than one at a time.
 
Why only human? What about AI-AI trades?
For AI-AI trades, the same formula is used. Both AI players calculate their valuation of the deal, and a deal is only made if the deal value is positive for both sides.

Gold always has the same valuation, so a Resource vs. GPT trade isn't possible between AI's.
 
Last edited:
Thanks for the information, what are the conditions required for the AI to initiate a trade deal with the player?
  • At least 20 turns must have passed after the last accepted offer
  • Relationship mustn't be hostile
Then, the AI loops through all strategic resources of the other player and checks the following conditions:
  • AI must have no more than 2 excess of the resource
  • The amount of resources currently used mustn't exceed twice the number of cities the AI has
  • The resource isn't being exported to another civ
Out of all the resources that remain, the AI calculates the one with the highest trade value using the formula from above, and offers a deal to the other player if possible. That means, a deal is offered if the AI finds something to put on the other side of the deal such that the total deal valuation is 0 for the AI (if the other player is human) or the total deal valuation is positive for both players (of the other player is another AI).
 
Oh yeah something I need to suggest for the eventual deal rework:
If the AI wants to buy something and sends a trade request to a human, don't let the human remove the requested item.
 
Imagine you want to buy Sugar from the AI on your turn, but the AI completely changes it to Salt and force accepts it.
 
Force? AI cannot be forced. It can always refuse.
They don't refuse any luxury resources. The main problem is you (the human) get to trade what you want on their turn.
 
They don't refuse any luxury resources. The main problem is you (the human) get to trade what you want on their turn.
They can refuse if the trade is not satisfactory to them. One turn difference (or closer to half a turn actually) is very minor imho.
 
They can refuse if the trade is not satisfactory to them. One turn difference (or closer to half a turn actually) is very minor imho.
And then they're blocked from asking anything for 20 turns.
 
Top Bottom