As requested, here is the current AI valuation for strategic and luxury resources, converted into pseudocode plaintext.
If forumgoers can suggest/agree on a better valuation, I can code it, within reason.
Strategic Resource - AI is Buying
Strategic Resource - AI is Selling
Luxury Resource - AI is Buying
Luxury Resource - AI is Selling
If forumgoers can suggest/agree on a better valuation, I can code it, within reason.
Strategic Resource - AI is Buying
Code:
Current Game Era = Average era of all majors. 0 in Ancient, 1 in Classical, 2 in Medieval, etc.
STEP 0: Obsolete Resources
- Obsolete resources are worth 0.
STEP 1: Base Value
- Base value is equal to current game era + 2.
STEP 2: Flavor Value
Total Flavor Value starts at 0.
# of Flavor Values starts at 0.
Loop through all AI non-diplomacy flavors. Skip any resource with a flavor value of 0 or less.
- Check what the AI's XML flavor value is for this flavor and add it to the resource value.
- Divide the sum by 5 and then add it to Total Flavor Value.
- Add 1 to # of Flavor Values.
If Total Flavor Value is greater than 0, divide Total Flavor Value by # of Flavor Values, and multiply the base value by the quotient.
STEP 3: GPT Surcharge
Divide the AI's net GPT by 5.
GPT Bonus = floor(0.5 + square root of quotient), or the base value, whichever is lower.
Add the GPT Bonus to the value.
STEP 4: Comparative Military Might
If seller has greater military might than the AI (uses base military might stat used in the score calculation, not strength perception from diplomacy AI), then multiply value by 8 and then divide by 10.
STEP 5: Sneak Attack
If AI is planning to sneak attack the seller, divide the value by 2.
STEP 6: Proximity
If AI's proximity to the seller is CLOSE or NEIGHBORS, multiply the value by 7 and then divide by 10.
STEP 7: Aluminum Bonus
If AI has completed the Apollo Program and the resource is Aluminum, multiply the value by 10 and then divide by 8.
STEP 8: Netherlands AI
- If AI is not Netherlands, skip this check.
- If AI's monopoly % for this resource is greater than or equal to the greatest monopoly % of all players, skip this check.
- If AI does NOT have a copy of this resource (not from an import), skip this check. (??????)
- If this resource's monopoly does not increase tile yields(???), skip this check.
If this check was not skipped, multiply the value by (100 + 2x the AI's current monopoly % for this resource) and then divide by 100.
[!] This code is really weird and appears to be bugged.
STEP 9: Resource Ratio
Skip this check if AI is Netherlands and AI's monopoly % for this resource is less than the greatest monopoly % of all players.
Tally up the amounts the AI *and the seller* have of this resource, INCLUDING imports and SUBTRACTING exports (this can be higher than the amount listed in the trade screen).
Subtract the quantity being sold from the AI's amount.
Resource Ratio = (Seller Amount * 100) / AI Amount, capped between 80 and 200.
Multiply the value by 100 and then divide by the resource ratio.
STEP 10: Approach
If AI's TRUE approach towards the seller is...
- Friendly/Afraid: Increase value by 10%
- Neutral/Deceptive: No change
- Guarded: Decrease value by 20%
- Hostile: Decrease value by 50%
- Planning War: Decrease value by 50% (note: stacks with / 2 penalty for sneak attack)
STEP 11: Resource Deficit
If AI currently has a deficit for this resource, increase value by 50%.
STEP 12: Game Speed / Quantity
Multiply the value by the quantity and then by the deal duration.
STEP 13: Diminishing Returns
Calculate how many resources the AI is already receiving from existing deals with this seller.
Multiply the value by 100 - (10 * the number of existing resources, or 90, whichever is lower).
Divide the value by 100.
[!] Note: This appears bugged when it comes to deal renewals; it does not appear to exclude the amount in the renewed deal.
STEP 14: Divide by 10
Divide the value by 10, rounding down.
At this point, return the value.
Strategic Resource - AI is Selling
Code:
Current Game Era = Average era of all majors. 0 in Ancient, 1 in Classical, 2 in Medieval, etc.
STEP 0: Obsolete Resources
- If the resource is obsolete, return IMPOSSIBLE!
STEP 1: Base Value
- Base value is equal to current game era + 2.
STEP 2: Flavor Value
Total Flavor Value starts at 0.
# of Flavor Values starts at 0.
Loop through all AI non-diplomacy flavors. Skip any resource with a flavor value of 0 or less.
- Check what the AI's XML flavor value is for this flavor and add it to the resource value.
- Divide the sum by 5 and then add it to Total Flavor Value.
- Add 1 to # of Flavor Values.
If Total Flavor Value is greater than 0, divide Total Flavor Value by # of Flavor Values, and multiply the base value by the quotient.
STEP 3: GPT Surcharge
Divide the buyer's net GPT by 4.
GPT Bonus = floor(0.5 + square root of quotient), or the base value, whichever is lower.
Add the GPT Bonus to the value.
STEP 4: Last Few Copies Bonus
Tally up the amount the AI has of this resource, INCLUDING imports and SUBTRACTING exports (this can be higher than the amount listed in the trade screen).
- If after the trade the AI would have none of this resource left, return IMPOSSIBLE!
- If after the trade the AI would have 1 or 2 of this resource left, multiply value by 10.
STEP 5: Comparative Military Might
If buyer has greater military might than the AI (uses base military might stat used in the score calculation, not strength perception from diplomacy AI), then multiply value by 10 and then divide by 7.
STEP 6: Sneak Attack
If AI is planning to sneak attack the buyer, multiply the value by 2.
STEP 7: Proximity
If AI's proximity to the buyer is CLOSE or NEIGHBORS, multiply the value by 10 and then divide by 9.
STEP 8: Aluminum Exception
If AI is going for science victory or the other team has completed the Apollo Program, return IMPOSSIBLE! to selling Aluminum
STEP 9: How Much Do We Have?
Tally up the amount the AI has of this resource, INCLUDING imports and SUBTRACTING exports (this can be higher than the amount listed in the trade screen).
If after the trade the AI would have less than 10 of this resource left:
- Add (10 - # left of this resource) * (10 - # left of this resource) to the value.
STEP 10: Resource Ratio
Tally up the amounts the AI *and the buyer* have of this resource, INCLUDING imports and SUBTRACTING exports (this can be higher than the amount listed in the trade screen).
Subtract the quantity being sold from the AI's amount.
Resource Ratio = (Buyer Amount * 100) / Seller Amount, capped between 50 and 200.
Multiply the value by the resource ratio and then divide by 100.
STEP 11: Approach
If AI's TRUE approach towards the buyer is...
- Friendly/Afraid: Decrease value by 10%
- Neutral: No change
- Guarded: Increase value by 25%
- Deceptive: Increase value by 50%
- Hostile: Increase value by 100%
- Planning War: Increase value by 200% (note: stacks with 2x bonus for sneak attack)
STEP 12: Game Speed / Quantity
Multiply the value by the quantity and then by the deal duration.
STEP 13: Divide by 10
Divide the value by 10, rounding down.
At this point, return the value.
Luxury Resource - AI is Buying
Code:
Current Game Era = Average era of all majors. 0 in Ancient, 1 in Classical, 2 in Medieval, etc.
STEP 0: Impossible! Checks
- If the luxury is banned by the World Congress, deal value is IMPOSSIBLE!
STEP 1: Base Value
Base Value = ((2 + current game era) * deal duration) / 2
STEP 2: Flavor Value
Total Flavor Value starts at 0.
# of Flavor Values starts at 0.
Loop through all AI non-diplomacy flavors. Skip any resource with a flavor value of 0 or less.
- Check what the AI's XML flavor value is for this flavor and add it to the resource value.
- Divide the sum by 6 and then add it to Total Flavor Value.
- Add 1 to # of Flavor Values.
If Total Flavor Value is greater than 0, divide Total Flavor Value by # of Flavor Values, and multiply the base value by the quotient.
[!] Not actually sure this section of code does much...doesn't look like it's needed.
STEP 3: GPT Surcharge
Divide the AI's net GPT by 4.
GPT Bonus = floor(0.25 + square root of quotient), or the base value, whichever is lower.
Add the GPT Bonus to the value.
STEP 4: Global Unhappiness Bonus
If the AI's empire is unhappy and they have global unhappiness from ideology/war weariness, multiply the amount of global unhappiness by 2 and add it to the value.
[!] This is...weird. Why only factor in global unhappiness? And why so little value?
STEP 5: Netherlands AI
- If AI is not Netherlands, skip this check.
- If AI's monopoly % for this resource is greater than or equal to the greatest monopoly % of all players, skip this check.
- If AI has a copy of this resource (not from an import), skip this check.
- If this resource's monopoly does not increase tile yields(???), skip this check.
If this check was not skipped, multiply the value by (100 + the AI's current monopoly % for this resource) and then divide by 100.
[!] This code is also weird.
STEP 6: Religion Bonus
- Yield Bonus Factor: Starts at 1. If our founded/conquered religion (or majority religion if none is founded/conquered) gives a yield bonus for each luxury resource we control, add 1 to Yield Bonus Factor for each yield that gets a bonus.
- If Yield Bonus Factor is > 1, then multiply the value by Yield Bonus Factor and then divide by 2.
STEP 7: Comparative Resource Happiness
- Count the amount of Happiness each player is gaining from resources.
- If seller has more resource happiness than AI (or an equal amount), multiply value by 11 and divide by 10.
- If AI has more resource happiness than seller, multiply value by 10 and divide by 11.
STEP 8: Approach
If AI's TRUE approach towards the seller is...
- Friendly/Afraid: Increase value by 10%
- Neutral/Deceptive: No change
- Guarded/Hostile: Decrease value by 25%
- Planning War: Decrease value by 50%
At this point, return the value.
Luxury Resource - AI is Selling
Code:
Current Game Era = Average era of all majors. 0 in Ancient, 1 in Classical, 2 in Medieval, etc.
STEP 0: Impossible! Checks
- If AI is unhappy and it only has one copy of this resource, deal value is IMPOSSIBLE!
- If the luxury is banned by the World Congress, deal value is IMPOSSIBLE!
STEP 1: Base Value
Base Value = ((2 + current game era) * deal duration) / 2
STEP 2: Flavor Value
Total Flavor Value starts at 0.
# of Flavor Values starts at 0.
Loop through all AI non-diplomacy flavors. Skip any resource with a flavor value of 0 or less.
- Check what the AI's XML flavor value is for this flavor and add it to the resource value.
- Divide the sum by 6 and then add it to Total Flavor Value.
- Add 1 to # of Flavor Values.
If Total Flavor Value is greater than 0, divide Total Flavor Value by # of Flavor Values, and multiply the base value by the quotient.
[!] Not actually sure this section of code does much...doesn't look like it's needed.
STEP 3: GPT Surcharge
Divide the buyer's net GPT by 3.
GPT Bonus = floor(0.25 + square root of quotient), or the base value, whichever is lower.
Add the GPT Bonus to the value.
STEP 4: Last Copy Bonus
If this is the AI's last copy of the resource:
- Yield Bonus Factor: Starts at 0. If our founded/conquered religion (or majority religion if none is founded/conquered) gives a yield bonus for each luxury resource we control, add 1 to Yield Bonus Factor for each yield that gets a bonus.
- Multiply the value by (3 + Yield Bonus Factor).
STEP 5: Comparative Resource Happiness
- Count the amount of Happiness each player is gaining from resources.
- If buyer has more resource happiness than AI (or an equal amount), multiply value by 10 and divide by 11.
- If AI has more resource happiness than buyer, multiply value by 11 and divide by 10.
STEP 6: Approach
If AI's TRUE approach towards the buyer is...
- Friendly/Afraid: Decrease value by 10%
- Neutral/Deceptive: No change
- Guarded: Increase value by 50%
- Hostile: Increase value by 100%
- Planning War: Increase value by 150%
At this point, return the value.