Research cost formula v1.29f

mydisease

Kalokagathian
Joined
Apr 8, 2002
Messages
97
This is the formula for research cost for v1.29f. I have attached an image of the formula as it is easier to visualize that way than in plain text. Also it is now simplified even more for your pleasure ;).

Research Cost = - Research done so far

I'll also write it out for those who cannot view images.

Research Cost = [MM * [10*COST * (1 - N/[CL*1.75])]/(CF * 10)] - Research done so far

Research Cost and research done so far are in gold.

Square brackets indicate truncation /rounddown

MM = map modifier(tech rate on world sizes tab in the editor)
Tiny 160
Small 200
Standard 240
Large 320
Huge 400

CF = AI cost factor(as on the difficulty tab in the editor)
For the purposes of the research cost formula, CF has a maximum value of 10.
Chieftain 10
Warlord 10
Regent 10
Monarch 9
Emperor 8
Deity 6

COST = technology cost as on the civilization advances tab in the editor.

N = number of civs on the diplomacy screen that have discovered the tech.

CL = number of civs left in the game

There is only one part of the formula that varies during the game: (1 - N/[CL*1.75]). There are two ways in which you can increase it to lower tech cost:
1. Increase N by exploring and buying comms to add civs to your diplomacy screen.
2. Decrease CL by killing civs.

NB. This formula is relevant for research cost of the AI civs, not just the human player. If you are interested in the research cost of a specific technology for a specific AI civ, N refers to the number of civs on that specific AI civ's diplomacy screen that have discovered that specific tech. In general, there are two ways in which you can increase AI tech cost:
3. Keep N low by not selling comms to AI civs.
4. Keep CL high by not killing civs.
And technically...
5. Keep N low by not getting techs yourself.

Obviously points 2. and 4. are contradictory so choose whichever fits your playing style. Personally I choose point 2. :ar15::king::queen::king::queen::king::queen:
 
GREAT WORK!!!!

I like to try to simplified this to
Research cost = MM*DM*(COST/100) *[1 - N/(CL*1.75)] - Research done so far.

This is less accurate since I drop all the roundings but easier to remember.
 
Yes, I agree with the simplification, in fact it is essentially the previous approximation to the formula that I had. But even with the simplification you still need one rounding because most of the answers will not be integers. So the simplest formula to give an integer answer is:

Research cost = DOWN{MM*DM*(COST/100) *[1 - (N/(CL*1.75))]} - Research done so far.

Indeed, I don't know why Firaxis don't use this formula as it is less complex and gives better answers.

Also I forgot to mention the changes from 1.21f to 1.29f. There were two changes:
1. CL*1.5 in 1.21f is now CL*1.75 in 1.29f. This lowers the rate at which research cost falls making researching a more viable option (as you are now more unlikely to have sufficient gold to buy techs)
2. DMs were all 10 in 1.21f, but some are now increased in 1.29f. This means techs are now more expensive for the human player on Monarch, Emperor and Deity.
 
Difficulty multipliers aren't in the editor. I had to work them out.

And hopefully I will stop now unless Firaxis change it again.
 
Originally posted by Lt. 'Killer' M.
Franses: which multiplier do you mean? it should be on the difficulty level tab.....

The one called DM in above formula. I understand from mydisease that it is not in the editor. That is a pity but shows and makes the derivation of the formula even more impressive.
 
Can you explain that cryptic comment Qitai?
And where is AI production advantage in the editor? I don't see it on the difficulty levels tab.
 
I mean cost factor. Sorry.
Cost factor = {20, 12, 10, 9, 8, 6} for the various difficulty level.
So The above gives {10, 10, 10, 11.1, 12.5, 16.7}. Slight difference from yours.
 
Yes, I think you are right. In fact the deity one should have been 16.7 when I wrote it, but I rounded down by mistake. Or 16.6recurring to be exact, but I don't know how to get the dot above the 6. That only leaves the Monarch figure and I've currently got a Monarch game on the go in the Modern Age, so I'll check it out. If you are right, then this simplifies it formula to this:

Research cost = MM*COST*MIN.1(1/CF) - UP{MM*MIN.01(1/10CF) * UP[COST*10N/DOWN(CL*1.75)]} - Research done so far

Which is slightly less complicated(especially seeing as I don't know the proper notation for rounding up to 0.1 if the figure is below that). I'll check out the figure for Monarch now, hopefully its 1/9.
 
I've tested it and the Monarch figure is 11.1 (or 1/9 with the new formula). I also tried changing the AI cost factor in the editor and research cost varied with its inverse, so the new formula is correct. Thanks Qitai!
 
Great work, mydisease! :goodjob: This is now my first subscribed thread.
 
Very nice job inferring the formula!

I think you're close, but I'm certain the actual formula is even easier.

Think a minute like a progammer. He's using *integer* math -- speed and efficiency are huge concerns. He's not using VB and functions roundoff or roundup. There is NO function used, other than the built in truncation when using integer math.

Example1 - if a programmer using integer math wants something to the nearest 10th, he'll use: [10*n]/10
The square brackets denote simple integer truncation (rounddown)

Example2 - he will NOT use any decimals whatsoever. If something looks like 11.1, it's 100/9. If it looks like 1.75, it's 4/7.
They will use min and max when needed to put bounds on factors.

Guaranteed the programmer is not using a complicated function for these things, but the simplest possible.

How does this formula fit your data?
CF = Min(AI_Production_Advantage, 10)

Research cost = MF*COST/CF * [ 10 - 40*N/CL/7 ]/10

(It might be 40*N/CL/7 or 40*N/(7*CL) or 40*N/7/CL, but it's
almost surely being done with integer math. That mean's it's not 40/7 together as that would truncate immediately to 5)

Examples from your response to GreyFox
1) Bronze Working, Regent Map, 8 of 10 civs have it:
ResCost = 240*3/10 * [10 - 40*8/10/7 ] / 10
= 72 * 5 / 10 = 36 beakers
2) Integrated defense, 0 of 10 civs know it, huge map, Monarch
ResCost = 400*360/9 = 16,000

Do your "fits" with pure integer math and truncation, no roundups or 'nearest tenth' - see if this formula is it or very close.

Charis
 
Ignoring MM/CF as it is the same in both formulae:

COST - UP.1(COST*N/DOWN(CL*1.75))
= COST - UP(COST*N*10/DOWN(CL*1.75))*0.1

You feel this can be abstracted to (square brackets denoting truncation):

COST * [10 - 40 * N/(7*CL)]/10

There are two errors in the derivation of this formula. First, you ignore the truncation of (CL * 1.75). This means that the results your proposed formula gives are too low. Secondly, you take a common factor of COST out of the UP bracket, ignoring the effect this will have on the rounding. This also means that the results your proposed formula gives too low results. This happens over the entire range of the formula:

Ex.1 Tiny Map, Regent, 4 civs, Pottery, 1 civ on your diplo screen has it
My way: UP.1(2*1/DOWN(4*1.75)) = UP.1(2/7) = .3
2 - .3 = 1.7
DOWN(1.7*160/10) = 27
Your way: [10 - 40*1/(7*4)] = [10 - 1.4] = 8
2 * 8/10 = 1.6
1.6*160/10 = 25.6 = 25
It is necessary to truncate at this point as well, as gold comes in integer values only.
Relative error = (27 - 25)/27 = 7.5%

Ex.2 Huge Map, Regent, 21 civs, Integrated Defense, 1 civ on your diplo screen has it
My way: UP.1(360*1/DOWN(21*1.75)) = UP.1(360/36) = 10
360 - 10 = 350
DOWN(350*400/10) = 14000
Your way: [10 - 40*1/(7*21)] = [10 - .27] = 9
360 * 9/10 = 324
324*400/10 = 12960
Relative error = (14000 - 12960)/14000 = 7.5%

So, clearly not the correct formula. However, I do see your point, the formula written at the top of this thread will not be how it is written in the code for civ3. But I am fairly sure that it is the simplest mathematical way to express a formula which always gives the correct results for Research Cost.
 
Top Bottom