April 26th, 2023, 20:10
(This post was last modified: April 27th, 2023, 19:03 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
For AI Survivor, there's been some interest in how AIs pick there tech. This thread is an attempt to make this slightly more comprehensible. However, this calculations is VERY VERY long and complex and also very abstract - because Civ 4 was heavily designed for modding and the tech valuation has to consider that.
Here's what I plan to do: - Part 1: The first posts will be raw bits of the formula translated into something most people can probably understand. They will reference things from the various XML files, largely. I will put these up a few at a time as I dig into specific sections of the function. This will provide a method for following along with the AI, but you won't see things like "How much is pottery worth to the AI?"
- Part 2: After that, I will follow on with listings of interesting techs in situations people are interested in - like early tech choices and worker paths. Here the idea will be to provide an actual number for the game techs, or at least a simple way of calculating it based on the AI's situation. This section might include intermediary values for things like Improvements.
Part 0: Terms
AI Yield %: The amount an AI desires a particular yield. This is 100% for Food and Commerce, and 110% for Production. Production is further boosted by 6.6% every age after the Classical Age
AI is in Financial Trouble when it's total maintenance is more than 60% of its beaker+gold income. It's allowed to go higher during wars, up to 72%. An AI in Financial Trouble tends to value commerce more highly.
Part 1.1: The Basics and FLAVOR
Tech Value is calculated anew every time the AI thinks about choosing tech (generally only when it finishes an existing tech). This includes things like random rolls, which are redone each time.
1. Tech Value starts at 1
2. Pick a random number between 0 and 2000. Add that value
3. For every flavor the tech and the AI shares, add 20 * the product of the AI's flavor emphasis and the tech's flavor value.
Okay, we started easy, but it's about to get REALLY mathy.
April 26th, 2023, 20:10
(This post was last modified: May 11th, 2023, 21:21 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
Part 1.2 - Worker stuff
Does the tech enable a new improvement
Calculate Improvement Value starting from 300 - all calculations inside this block should be treated as acting on improvement value
If it "acts as a city" (for healing?) add 100 (only forts seem to have this value)
If it can only be built on a hill, add 100 \
If it can only be built next to freshwater, add 200 \
If it gets additional bonuses when built orthagonal to a river, add 100 (water mills, basically) All these are weird, as they mean a narrowly defined improvement is worth more than one that can be built everywhere
If it spreads irrigation, add 300 /
For every entry in TerrainMakesValid or FeatureMakesValid (in the improvement XML) add 50 /
For each yield change granted by the raw improvement:
Yield value = 200 * yield change + 100 * extra yield change next to a river + 100 * hills yield change + 150 * irrigated yield change
If the yield is food and this isn't a water improvement, multiply yield value by 1.5
If the yield is commerce and the AI is in financial trouble, multiply yield value by 2
Multiply the yield value by the AI Yield %
Add the Yield value to the Improvement Value
For each bonus the improvement relates to that the AI owns one or more copies of in its culture:
Calculate bonus value
If it makes the bonus valid for yields, add 450 to the bonus value (always true in normal Civ 4)
If it makes the bonus for trade, add 45 * (AI Bonus Value) to the bonus value (always true in normal Civ 4) - Bonus value is usually 10 but is higher for ivory + strategics based on what the AI can build with them
For each yield the bonus improves:
Yield value = raw impovement * 300 + irrigated improvement * 200
If it's food, double the yield value
If it's commerce and we're in financial trouble, add 33% to yield value
If it isn't either of those two scenario, subtract 25% from yield value
Multiply the yield value by the AI Yield %
Add the yield value to the bonus value
Is it a land bonus?
Scale the bonus up by 33% for each copy the AI has beyond 1.
Is it a water bonus?
If the AI only has one, reduce by 25%
If the AI has more than two, add 25% for every copy more than 2
Add the bonus value to the improvement value.
Is this improvement a water improvement?
Scale improvement value from 0-200% depending on how many of the AI cities are coastal (break-even at 50% of cities)
Add improvement value to overall tech value
Does it increase the yield of an existing improvement by X? - Add (X * how many of this improvement the AI has built * 50 * AI Yield %
Enables a route (road/railroad)?
Add 200
If the AI has no routes currently allowed, add 700 * total city count
If it does, add 200 * total city count
Does the new route give direct yield bonus? (Don't believe this is true for any vanilla)
Add 100 * direct yield bonus * AI Yield %
Does the new route add yields to any existing improvements? (i.e. mines/lumber mills for railroads)
Add 50 * the total yield improvement to all such improvement types (does NOT consider number of such improvements AI has)
Enables feature clearing (forest/jungle)?
Add 100
If the feature lowers health, or has a total yield modifier < 0 (these are both true for jungle)
Add 25 for each of the features currently in one of the AI's cities
April 26th, 2023, 20:11
(This post was last modified: April 27th, 2023, 19:40 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
Part 1.3 - Revealing New Resources
If the tech reveals a new resource:
Base Reveal value = 150
Add 50 * the AI value for the resource (see below) to the Reveal Value
If the resource revealed is one of the early three strategics (Horses, Copper, Iron) or the late three Strategics (Aluminum, Oil, Uranium), and the AI can already see at least one other of these resources and doesn't have a copy of every one it can already see:
If the AI can see one of the other strategics in this class and doesn't have it
Multiply the Reveal Value by 1.66
If the AI can see both of the other strategics in this class and doesn't have either
Multiply the Reveal Value by 3
If the AI can see both of the other strategics in this class and has one of the two
Multiply the Reveal Value by 1.25
If the AI has more than 3 cities, multiply the Reveal Value further by 1 + (0.33 * number of cities more than 3)
Add the Reveal Value to the Tech Value
How much does the AI value strategics?
For every unit the strategic unlock, add base value 40
Add an extra 50% if the unit is from the era the currently in (Example: Axemen for Bronze Working are worth 60, since it's enabled by the same tech)
Divide by the number of era the AI is away from reaching that unit if that is more than 1 (Example: Macemen for Bronze Working are worth 20, since Macemen are Medieval and the AI is presumably Ancient)
If it's a sea unit and the AI has no coastal cities, reduce value to 0. Otherwise, if it's a sea unit, scale by how many of the AI cities are coastal (0-200%, with break even at half of the AI cities being coastal)
For every building/wonder the strategic unlocks, add base value 20 (using the same era modifiers), unless it provides power - then use 60 instead
Then Divide the total by 10.
Let's look at a few examples about how this works out with copper, and assume the AI is in the Ancient Era. We're also ignoring Sitting Bull, who has resourceless Axes and whose calculations will be slightly different.
Copper enables: - Axemen (worth 60)
- Spearmen (60)
- Macemen (20)
- Privateers (0 if the AI only has non-coastal cities, 13 is the AI has half their cities coastal, 26 if the AI has all their cities coastal)
This yields a likely total of 140, 153, or 166 depending on early AI coastal cities.
With a value of 140, that's 700 points of Tech value (plus the base value of 150)
If the AI had revealed horses but didn't own any and had 3 cities or less, now we're looking at 1411!
April 26th, 2023, 20:11
(This post was last modified: May 1st, 2023, 22:25 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
Part 1.4 - Units Unlocked
Note: This post is focused on AI Survivor conditions. There are additional complications when the AI is on an continent alone,
or has cities on multiple continents, that I am leaving out for the sake of simplicity.
For every unit unlocked at the tech:
Compute the Unit Value and Military Value of the unit from the table below
Notes:
1. Add all applicable military values (i.e. if the AI is both in a warplan and has STRATEGY_DAGGER, add all three columns for military values
2. All sea units are worthless if the AI has no coastal cities
Now perform the following adjustments:
If the AI hasn't met any other players, reduce the Military Value by 50%
Add Military Value to Unit Value.
If this unit is the Unique Unit for the AI, add another 600 to Unit Value.
If the AI does not currently have any units with this type(note that Grenadiers share a type with Catapults despite being in different rows):
Double the Unit Value
If it's an Explorer, add 400 * the number of exploration units the AI thinks it needs*
If it's a Caravel, add 400 + 200 * the number of unmet players
Now add 200 to Unit Value.
The total Unit Value is then added to the tech value
Repeat for all other units unlocked at this tech.
*Number of Exploration units the AI thinks it needs:
1. Take the smallest of the following numbers: Number of unrevealed tiles on its home continent / 150, (Number of Cities+2)/3, or 3
2. If the number was 0, add one for all unmet players on that continent
April 26th, 2023, 20:12
(This post was last modified: May 10th, 2023, 19:19 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
Part 1.5 - Buildings, Wonders, Projects, and Processes
BUILDINGS:
For each building added, add the following values:
Granary: 900
Cathedrail, Temple, Monastary, Bomb Shelter: 125
All others: 150
If it's a UB: +600
If the AI is in AI_STRATEGY_CULTURE2(only possible in at least Classical or Medieval Era):
Add 150 x raw culture notes produced by building ( x 3 if it's a wonder, national or world)
Add 4 x cultural production rate increase ( x 3 if it's a wonder, national or world)
If the AI is in financial trouble:
Add 15 x raw gold produced by building
Add 8 x raw commerce produced by the building
Add 15 x the maintenance modifier produced by the building (Note: this modifier is usually negative, so I think this actually lowers the value of Courthouses, probably not intentionally)
If the building requires a religion to build:
Multiply the building value by 4 + (number of cities of that religion I currently have)
Divide the building value by 4 + (number of cities I own)
Divide the building value by 7
If we're over 90% of the way to Domination and the building increases health:
Add 150 * amount of health increase
If the building is an unbuilt world wonder and the tech is immediately available and the AI has total empire pop of at least 5 and the AI is in AI_STRATEGY_CULTURE1 or higher:
Add 500
If it's a water building, scale the value by -50%-50% depending on how many of the AI's cities are coastal
At the end, add the value of the best building again.
If there's at least one culture producing building unlocked and the AI doesn't already have at least 2 non-wonder cultue-producing buildings unlocked:
For the first unlock, add 450 for every AI city beyond the first
For the second unlock, add 150 for every AI city beyond the first
If at least one building was an unbuilt world wonder and the tech is immediately available and the AI has total empire pop of at least 5:
Add 500 + a random number between 0 and 800
PROJECTS:
Add a random number between 0 and 200
PROCESS:
Wealth: 300 (+1500 if the AI doesn't have the ability to build Research and is in Financial Trouble)
Research: 350 (+1500 if the AI doesn't have the ability to build Wealth and is in Financial Trouble)
Culture: 150 (+100 if the AI is in AI_STRATEGY_CULTURE1
April 26th, 2023, 20:12
(This post was last modified: May 1st, 2023, 22:34 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
Part 1.6 - Civics
If the tech unlocks a new Civic:
Add 200 to Tech Value.
If the civic is the AI's favorite Civic, add 600 to Tech Value.
If the AI values the new Civic more highly than its current Civic for that category, add up to 2400 to Tech Value proportional to how much higher it values it, maxxing out as "twice as valuable"
Note: The Civic value calculation is long and almost as complicated as the tech value calculation. I may do this in another post later. But until then, you can probably assume max value for civic categories the AI doesn't have any of,
and guesttimate the rest based on how you as a human would value the civic.
April 26th, 2023, 20:20
(This post was last modified: May 1st, 2023, 22:44 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
Part 1.7 - Religions, Corporations, and one-time bonuses
Note: All first-time bonuses (religions, corps, Great People, etc) further than 2 away are totally ignored
RELIGION:
Roll a random number between 1 and 2400
If the tech is immediately able (no beeline required), multiply the value by 1.5
If the AI is in STRATEGY_CULTURE_1, add 500, and another 1000 if the AI currently has no holy city.
If the AI is not in STRATEGY_CULTURE_1, divide by (1+number of current holy cities)
If the AI has no religions at all, multiply by 2 and then add 500
If the AI is in STRATEGY_DAGGER, divide by 2.
The final value is the value added to the tech calculation
CORPORATIONS:
Roll a random number between 1 and 2400.
Add 100 to this value.
The final value is the value added to the tech calculation
GREAT PEOPLE:
Roll a random number between 1 and 3200.
Add 200 to this value.
The final value is the value added to the tech calculation.
FREE TECH:
Roll a random number between 1 and 3200.
Add 200 to this value.
Multiply this by the number of free techs granted.
The final value is the value added to the tech calculation
April 26th, 2023, 20:23
(This post was last modified: April 26th, 2023, 23:49 by aetryn.)
Posts: 624
Threads: 2
Joined: Mar 2018
Part 1.8 - Miscellaneous enables and final calculations
Things that are enabled and their worth - Defensive Pact - 400
- Permanent Alliance - 200
- Vassal States - 200 (does NOT check if Vassal states are allowed)
- Bridge Building - 200
- Chaining Irrigation - 400
- Ignoring Irrigation Requirements - 500
- Work water tiles - 600 * number of coastal cities
- Allows trading on rivers: 1000
- Centers the map: 100
Tech Properties and the value they add: - Bonus for clearing features: 2 * bonus (example, Mathematics has a bonus 50%, so its value is 100)
- Bonus for worker speed: 4 * bonus (example, Steam Power has a bonus 50%, so its value is 200)
- Bonus for movement speed on routes (i.e. roads): -100 * the bonus (Engineering is -10, so this would be 1000)
- Bonus for extra air or sea moves: 200 * the bonus
Does the tech grant extra water vision?
Does the AI have a coastal city?
Add 100
Is the AI the only player in its area?
Add 400 more
Does the tech make the entire map visible or allow map trading?
Add 100
Is the AI the only player in its area?
Add 400 more
Does the tech allow tech trading and is that option available in this game?
Add 500 * (1 + number of AIs already met)
Does the tech allow gold trading?
Add 200
Has the AI met another player?
Add 400 more
Does the tech allow open borders and has another player been met?
Add 500
Does the AI have a coastal city?
Add another 400
Does the tech provide bonus trade routes?
Let multiplier be either the number of foreign cities connected by trade route + 1, or the AI's personal city count + 2, whichever is higher
Is the AI in financial distress?
Add 200 * multiplier * number of bonus trade routes added
If not
Add 100 * multiplier * number of bonus trade routes added
Does the tech provide raw health (like Genetics)?
Is the AI 90% of the way to domination?
Add 350 * amount of raw health provided
Otherwise
Add 200 * amount of raw health provided
Does the tech enable a commerce slider option?
Add 100
Is the commerce slider option Commerce and is the AI pursuing AI_STRATEGY_CULTURE2 (second stage culture victory)?
Add 1000
Does the tech enable trade network on a particular terrain type?
Is that terrain type a non-water type (does not occur unmodded)?
Add 1000
Is it a water type?
Add 50
Does the AI have coastal cities?
Add 350 more
Are there no other players on the AI's area (continent)?
Add 600 more
Final modifiers: - Is this a repeat tech (i.e. Future Tech)? If so, Divide total by 10
- Are we picking a "free" tech (i.e. from Oracle or Liberalism)? If so, multiple the value by the number of turns it would take to research this tech and divide by 10
- Is this tech able to be completed in one turn? 20% of the time, multiply the value by 100000.
Posts: 4,609
Threads: 31
Joined: Nov 2016
(April 26th, 2023, 20:10)aetryn Wrote: Does the tech enable a new improvement
Calculate Improvement Value starting from 300 - all calculations inside this block should be treated as acting on improvement value
If it "acts as a city" (for healing?) add 100 (only forts seem to have this value) Forts acts as cities in more ways than healing though: Attack bonuses (City Raider/Guard), ship movement, air stationing, trade-port, etc.
(April 26th, 2023, 20:10)aetryn Wrote: If it can only be built on a hill, add 100 \
If it can only be built next to freshwater, add 200 \
If it gets additional bonuses when built orthagonal to a river, add 100 (water mills, basically) All these are weird, as they mean a narrowly defined improvement is worth more than one that can be built everywhere
If it spreads irrigation, add 300 /
For every entry in TerrainMakesValid or FeatureMakesValid (in the improvement XML) add 50 /
My guess is that this is because improvements that can only be built in narrow situations tend to be the best available, and thus should be prioritized.
|