# Hidden research bonuses?

Discussion in 'Civ4 - Strategy & Tips' started by sampsa, Apr 4, 2018.

1. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
We start a game. Difficulty level does not matter I think. We SIP by a river and work a floodplain while building a worker. We select and de-select a tech at the start of every turn (i.e. put no to any tech until T5), then we choose agriculture and end turn.

If you already weren't doing this, start doing it for reasons that you will soon understand.

So we have generated 10 every turn. How much is put into agriculture after we click end turn?

Expectation:
Spoiler :
66. On T6, we have researched for 6 turns since the game starts T0. You get one extra every turn no matter what your slider position is. So 6*10+6=66.

Reality:
Spoiler :
That is correct.

What if on T5 we meet an AI that already has agriculture? There is a hidden +5% bonus for every AI that knows the tech you are researching.

Expectation:
Spoiler :
6*10*1,05+6=69

Reality:
Spoiler :
68.

Anyway, you've just won 2 by select/de-select and meeting an AI. Congratulations.

Meet two guys that have agri:

Spoiler :
Expectation 6*10*1,1+6=72, reality 70. Same goes on when adding more met civs, you get 2 less than expected, until you've met 6. Expecting 6*10*1,3+6=84, reality 81 so now the difference is 3.

Can anyone explain why and what the correct formula could be? I double checked my tests and there doesn't seem to be any human error. Maybe code diving is required, but that is something way beyond my abilities.

Then there is the 20% bonus per pre-requisite that I also want to investigate. Based on my previous experience it is not additive with 5% bonuses, but calculated separately.

Kaitzilla likes this.
2. ### SnowbirdPrince

Joined:
Feb 2, 2017
Messages:
417
IIRC, 5 % bonus for each is a bit of civfanatics mythology...

Some tests (you might repeat this)
--- 10 beakers and 2 known civs >> real output 10+1 hidden... 5+5% does not trigger (you need few beakers more to trigger)...
--100 beakers (builder engineering - on DR- to avoid roundings) --
1 civ 106 (100*1.05+1)
2 civ 109 (*1.08?) (6*10*1.08+6=70.8 in your example - so goes rounded down to 70)
3 civ 113 (*1.12?)
4 civ 118 (*1.17?)
5 civ 122 (*1.22)
6civ 126 (*1.25) (6*10*1,3+6=84>>6*10*1,25+6=81)
7civ-??

I think we will need code reader to know exactly wtf is going on...

edit: I've tried map with 17 opponents... and 1 known civ gave +1 beaker (from 100 base)
so maybe 25%*known civs/all civs with some wierdo roundings?

Last edited: Apr 5, 2018
3. ### gramm87Chieftain

Joined:
Sep 25, 2015
Messages:
41
Gender:
Male
The according code, I think:

Spoiler :

int CvPlayer::calculateResearchModifier(TechTypes eTech) const
{
int iModifier = 100;

if (NO_TECH == eTech)
{
return iModifier;
}

int iKnownCount = 0;
int iPossibleKnownCount = 0;

for (int iI = 0; iI < MAX_CIV_TEAMS; iI++)
{
if (GET_TEAM((TeamTypes)iI).isAlive())
{
if (GET_TEAM(getTeam()).isHasMet((TeamTypes)iI))
{
if (GET_TEAM((TeamTypes)iI).isHasTech(eTech))
{
iKnownCount++;
}
}

iPossibleKnownCount++;
}
}

if (iPossibleKnownCount > 0)
{
iModifier += (GC.getDefineINT("TECH_COST_TOTAL_KNOWN_TEAM_MODIFIER") * iKnownCount) / iPossibleKnownCount;
}

int iPossiblePaths = 0;
int iUnknownPaths = 0;

for (int iI = 0; iI < GC.getNUM_OR_TECH_PREREQS(); iI++)
{
if (GC.getTechInfo(eTech).getPrereqOrTechs(iI) != NO_TECH)
{
if (!(GET_TEAM(getTeam()).isHasTech((TechTypes)(GC.getTechInfo(eTech).getPrereqOrTechs(iI)))))
{
iUnknownPaths++;
}

iPossiblePaths++;
}
}

FAssertMsg(iPossiblePaths >= iUnknownPaths, "The number of possible paths is expected to match or exceed the number of unknown ones");

iModifier += (iPossiblePaths - iUnknownPaths) * GC.getDefineINT("TECH_COST_KNOWN_PREREQ_MODIFIER");

return iModifier;
}

So it seems that the game calculates the percentage of met civs knowing the tech then calculates the bonus by taking this percentage from TECH_COST_TOTAL_KNOWN_TEAM_MODIFIER, which seems to be a global define set to 30.

So the bonus per civ met on standard seems to be 1/7 * 30 = 4,28% bonus per civ met. In practice considering integer division the bonus is usually 4% per player met (7 players game): (0, 4, 8, 12, 17, 21, 25). Note that you can't reach 30% bonus since that would mean you know the tech already (unless I read the code wrong).

The bonus depends only on the total number of players (actually number of teams, but typically 1 player = 1 team).
In summary,
bonus in percent = 30*R , with R the ration of alive players met having the tech, over the total number of alive players
.

For example in a game with 60 players, 20 of which have the tech, and you met 5 of them, the bonus would be 30*5/60 = 2% bonus (2.5% rounded down to 2%).

@sampsa : as the code shows the two bonuses are calculated separately then summed.

Edited for clarification

Last edited: Apr 5, 2018
4. ### SnowbirdPrince

Joined:
Feb 2, 2017
Messages:
417
Huh?
Spoiler :

that is more understandable for me.....
Code:
```for (int iI = 0; iI < MAX_CIV_TEAMS; iI++){
if (GET_TEAM((TeamTypes)iI).isAlive()){
if (GET_TEAM(getTeam()).isHasMet((TeamTypes)iI)){
if (GET_TEAM((TeamTypes)iI).isHasTech(eTech)){
iKnownCount++;
}
}
iPossibleKnownCount++;
}
}
```

isHasMet is not checked for iPossibleKnownCount... just isAlive. so Percentage of alive civs...

5. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
This is very important imo and my tests support that it's correct. The bonus% is rounded down first, then applied. So indeed the list 4, 8, 12, 17, 21, 25 is the answer. Thank you!

6. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
I started to investigate the +20% pre-requisite bonuses. Immediately I stumbled on something that I don't understand. We have agri+hunting and we are researching AH. We produce 12 per turn. So I thought we'd get 12*1,4+1=17,8 rounded down, 17 towards AH. Wrong. We get 18. Why? Haven't met any AI.

Edit: If 11 produced, get 11*1,4+1=16,4 rounded down, 16. Correct. One strange possibility is that here the +1 free is added before the bonus?

Edit2: Tests match with "+1 free added before calculating +40% bonus" i.e. I was expecting that the jumps happen at 10,13,15,18,20 . Instead they happen at 9,12,14 etc. @gramm87 does code verify this?

Last edited: Apr 9, 2018
7. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
OK, tested it a bit more and +1 free is added before bonuses also in "+4% for every AI that knows the tech"-bonus, too. So things seem to be adding up.

So here is a spreadsheet on how many you need to get a benefit from each bonus. For example, you are researching sailing (one pre-req) and have met two AIs that know the tech (+8%). If you put 12 towards the tech (i.e. the number next to your -slider is +12) , you will get a +1 bonus from AI's and +2 bonus from pre-reqs as shown by the spreadsheet. Thus next turn you have gained 12+1+2+1=16 towards sailing. The last +1 is the free beaker you get every turn.

I was rather sure we should be aiming for even numbers and probably numbers dividable by 10, but it seems that due to the way it's calculated and the free beaker per turn, bonuses kick in at many integers. Note though that there is not a single 10, 20 or 30 there. So the result was pretty much the opposite than what I intuitively thought.

The good news is that you don't need to micro it, unless you really really want to do it when you can probably win one here and there by doing non-binary research. The issue is that many non-binary slider positions already lead to the loss of 1... Overall, I'd just strongly recommend doing binary research and select/de-select tech for the first 5 turns.

I would share the spreadsheet, but can't attach *.ods here it seems.

8. ### gramm87Chieftain

Joined:
Sep 25, 2015
Messages:
41
Gender:
Male
Nice post Sampsa! Even though as with my "beaker overflow" post the conclusion is "well you can't really do much except working 0%/100%"

Maybe you might want to give a title just above the table to make it easier to interpret ("Minimum number of bpt to produce to get the equivalent bpt bonus" or something like that). Also does the indicated bpt contains the hidden +1bpt (so is it the tech rate you see from the tech slider, or the tech rate-1, since the +1bpt is not visible in the indicated slider tech rate)?

sampsa likes this.
9. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
Yes, kinda forgot to explain it better. See below.

True. I think this is partly due to good game development. For a game this complex, there is not much to micromanage in the -system. Just work the best tiles and use binary research basically. However, you can sometimes slightly improve on this. One example was pointed out by Sno... Soirana here: https://forums.civfanatics.com/threads/how-fast-to-expand.484940/page-4#post-12150053. I'll do my best to explain this example below.

Better chart explanation:

On the left, "AI's" mean "met AI's that know the tech you are researching". "Pre-reqs" mean "how many techs are leading to the tech you are researching". This requires that these techs are connected by an arrow in the <F6>-screen. For example, for pottery you can get +40% bonus if you have both agriculture and fishing. Wheel is also required, but gives no bonus. Writing is the only tech with 3 pre-reqs (AH, pottery, priesthood).

+x research on the top row means "minimum required per turn to get +x bonus ". This does not contain the hidden +1 i.e. you should simply use the amount you see on the top left corner by the slider.

Examples on how to use the chart and how to beat binary research:

Soirana's example.
Spoiler :
Assumptions: "5 city empire 35 per turn, 0 gold in bank. At 40% slider breaks even. Teching writing (so no library), one prerequisite - Animal Husbandry, no city growth planned on next ten turns. You are isolated."

Binary:
6T 0% slider -> create just the free 1pt -> 6
4T 100% slider -> (35+1)*1,2=43,2 rounded down to 43 -> 43*4 -> 172
total: 178

10T 40% slider -> (35*40%)=14 -> (14+1)*1,2=18 -> 18*10 -> 180
total: 180

Why?? Under what circumstances is this possible to do?

There are two requirements. Firstly, you must not lose due to rounding when running 40% slider. Check, 35*0,4=14 is a whole number.

Secondly, you must hit integers in the chart better than the binary route does. So, one pre-req, no AI's know the tech. We are looking at the 3rd row from the bottom, so trying to hit 4,9,14,19,24... Bingo, Steady is creating 14pt, while Binary creates 35pt, misses by one so it loses one fifth of per turn.

Like Soirana notes, it should be possible to create a scenario where the difference is even bigger. However, the big practical problem is that our / output is hardly ever static for 10 turns, but even getting one optimal turn of -output here and there does win a bit.

More ideas on when and how:
Spoiler :
Because we are talking about fractions of gained per turn, we must be looking at the very early game mostly to make anything lucrative out of this. Before settling a 2nd city it's pretty hard to do anything else than run 100% slider, though there could be cases where it makes sense to run 90% slider when you are making 10 per turn to hit the 9 (one pre-req row) and bank one per turn to be able to run 100% immediately when settling 2nd and hitting 14 (+1 city center, +2 trade routes, +1 tile worked).

At two cities it is often hard to run non-binary because you are making more than 10 but less than 20 so it's hard to come up with slider positions (other than 50% at even amounts) that don't lose due to rounding. There is 15 though, @60% hits the 9 (which I think is a key integer because so many techs have 1 pre-req) so that could be useful. So instead of a typical 1-2 turns 0%, then 100%, 60/100 is worth something.

At three cities you might make 20 and 70% slider to hit 14 might be useful.

I think it's pretty hard to really benefit from "AI's that know the tech"-bonus. Best one I can come up with is normal binary research to let them get the tech before you start putting into it. This also kind of suggests these non-binary slider shenanigans are of more use when isolated.

In total, the result is underwhelming but there are some ideas to squeeze a few extra in the early game.

Last edited: Apr 10, 2018
Kaitzilla likes this.
10. ### Pedro78King

Joined:
Oct 20, 2016
Messages:
987

I used to use some of these "tricks", but I didn't know the "+5% per AI" thingy was wrong.

Overall I find it a bit complicated (and boring) to factor all these informations in slider management for most games. However, the main use I see for your spreadsheet in regular games is in tile management, i.e. "does adding one commerce add 1 or 2 bpt?". This can help when choosing between a cottage and a mine, for example.

btw Sampsa there are many converters online if you want to change your .ods to a pdf or xls and upload it here

11. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
Agreed. Once you get good enough doing this tile management to hit optimal -numbers it becomes automatic and stops feeling boring. It feels just... automatic, like select/de-select tech for the first 5 turns.

Dang, have to check it out.

12. ### DhoomstrikerGirlie Builder

Joined:
Aug 12, 2006
Messages:
13,408
The typical approach used on this forum is to add your file into a .zip file and attach the .zip file. There are many third-party compression programs for making .zip files, but Windows Explorer ("Windows key" + e) should have default integration to let you right-click on a file or on a group of selected files and choose an option such as: Send to -> Compressed (zipped) folder.

I like where you are going with trying to come up with scenarios to use generically.

As you say, it's a lot easier to come up with examples where you don't have fractional values or else don't have large fractional remainder values when you are only working with one City. But, I think that it would be quite helpful if you were to spend the time to come up with scenarios for empires with 2 Cities and empires with 3 Cities, where you minimize lost fractional Gold and Flasks but still get good base Flask values for receiving efficient numbers of bonus Flasks.

For example, you might say something like: with a capital having X Commerce and City 2 having Y Commerce, besides Binary Research, you can also use a Z% Science slider value to minimize fractional loss while allowing you to earn an extra bonus Flask for a tech with a 20% Research bonus.

Another micromanagement fun factor to throw into the equation is that on the last turn of researching a tech, the numbers go out of the window, due to how the fractional carry-over value gets calculated. In practice, what I have seen is that you often end up losing 1 base Flask out of Flasks that carry over.

As an example, let's say that you only needed 1 more Flask to complete a tech. Let's also say that we're on a Standard-sized map with the normal 6 Opponents. Let's say that you're researching a "first column" tech Fishing, The Wheel, Agriculture, Hunting, Mysticism, or Mining) which does not get any "white arrow pointing to it 20% bonus Flasks" that most other techs in the tech tree get, with a few exceptions, such as Astronomy, Divine Right, and Flight, since they, too, don't have "white arrows" pointing to them on the F6 Tech screen.

I wasn't quite clear whether we are supposed to use 4.28% or 4% for meeting 1 AI who knows that tech, but I'll try to use small enough numbers where the difference won't matter. Please feel free to clarify which number is the actual number to use.

We're making 11 Commerce in our capital (8 from the Palace, 1 from the City Centre, and 2 from working an Oasis or water square). We're researching Agriculture, so, with the free Flask, we're making 12 base Flasks per turn. We meet De Gaulle of the French, who starts off knowing Agriculture, but since floor ( 12 * 1.0428 ) = floor ( 12.5136 ) = 12 final Flasks, we don't achieve 13 final Flasks and we still only earn 12 final Flasks per turn, i.e. the number of final Flasks that we earn is equivalent to the number of base Flasks that we earn.

I started my example on Deity, so I need 151 Flasks to complete Agriculture. After 10 turns, we have 10 * 12 = 120 final Flasks. After 11 turns, we have 132. After 12 turns, we have 144 / 151 final Flasks. So, how many base Flasks will carry over?

After learning Agriculture, I switch to 0% Science and select Mysticism, which, via the World Builder, I have confirmed that De Gaulle does not know, and I end the turn again. I end up with 5 Flasks. 1 Flask was from the free Flasks on the turn after learning Agriculture, so only 4 base Flasks carried over.
151 + 4 = 155 total Flasks (a mix of final and base Flasks)
155 - 144 = 11 Flasks (a mix of final and base Flasks) pocketed on the last turn of learning Agriculture
What?
Where did my 12th Flask go?
It's gone!

When it came to learning Agriculture, the game said something like:
"You needed 151 - 144 = 7 final Flasks to complete the tech."
"That means that there are 12 - 7 = 5 final Flasks remaining."
"Now, we need to convert these final Flasks back into base Flasks, so that the bonus percentage used for this tech doesn't get used on the next tech."
floor ( 5 final Flasks / 1.0428 ) = floor ( 4.79 ) = 4 base Flasks will carry over

That fact doesn't sound so bad, since it SEEMS fair for the game to remove the bonus percentage from your current tech, calculate how many base Flasks remain, and then on the following turn, the base Flasks that carried-over will receive the bonus percentage of whatever tech you have selected at the end of the turn. But, in practice, it means that you're going to lose a base Flask due to carry-over flooring.

Thus, despite the fact that you didn't get any bonus Flasks from knowing De Gaulle, the game actually took away an extra base Flask from you on the final turn of learning a tech due to you knowing De Gaulle.

In many games, you're busily learning Hunting and then when you're about to finish research on Hunting, you meet an AI who knows Hunting, giving you a non-zero bonus, which makes you lose a Flask for having met an AI who knows the tech! That situation of taking away your Flask is quite far away from what people would expect when it comes to the concept of "receiving bonus Flasks for meeting AIs who already know such a tech."

What can you do about this situation? Well, you can think of that the 1 free Flask as immune to being taken away. So, if we were to have 150 / 151 Flasks and go to a 0% Science slider, I will still learn the tech at the end of the turn.

Another option, when receiving more than 1 Flask on the last turn of learning a tech, is to have no overflow Flasks. For example, let's say that I'm on a Duel-sized map, with the normal 1 opponent. I'm on Deity again, so all of the AIs actually know Agriculture to begin with, meaning that our multiplier for knowing that AI should be about 1 / 2 * 30 = 0.5 * 30 = 15%, but I only need 117 Flasks to complete Agriculture.

I'm making 9 Commerce with a 100% Science slider, so that's 9 Flasks + 1 free Flask = 10 base Flasks
For 4 turns, I don't meet the AI, so I make 4 * 10 = 40 / 117 Flasks, leaving 77 Flasks needed to complete Agriculture
On Turn 4 (counting the first turn as Turn 0), I meet the AI, so I start making floor ( 10 * 1.15 ) = floor ( 11.5 ) = 11 Flasks per turn
51, 62, 73, 84, 95, and 106...
I'm now another 11 Flasks away from completing research on Agriculture.
If I earn 9 Commerce, I'll make 11 final Flasks, and I'll complete research on Agriculture with 0 overflow Flasks.

But, what if I were to switch which square my citizen is working so that I earn 10 Commerce?
floor ( 11 * 1.15 ) = floor ( 12.65 ) = 12 final Flasks
"You needed 117 - 106 = 11 final Flasks to complete the tech."
"That means that there is 12 - 11 = 1 final Flask remaining."
"Now, we need to convert that final Flask back into base Flasks."
floor ( 1 final Flask / 1.15 ) = floor ( 0.87 ) = 0 base Flasks will carry over

If, on the other hand, we earned 11 Commerce, say by switching to working a Coast square, such as a Clam, and we earned 2 more Commerce than on previous turns, we'd have:
We earn floor ( 12 * 1.15 ) = floor ( 13.8 ) = 13 final Flasks
"You needed 117 - 106 = 11 final Flasks to complete the tech."
"That means that there are 13 - 11 = 2 final Flasks remaining."
"Now, we need to convert those final Flasks back into base Flasks."
floor ( 2 final Flasks / 1.15 ) = floor ( 1.74 ) = 1 base Flask will carry over

From this example, we see that switching your citizen to working a square that offers +1 Commerce would have actually netted us +0 Flasks, while switching your citizen to working a square that offers +2 Commerce would only net us +1 carry-over base Flask.

Now, it's possible that on the following turn, that +1 base Flask could combine with other base Flasks to push you up over a break point so that you receive another bonus Flask, but at best, you've just earned 1 Flask for the 1 Commerce, and in practice, you won't earn anything for the 1 Commerce. Still, if you don't mind thinking ahead to a future turn what you will be researching and how much Commerce you'll be earning on the turn following the turn that you completed research on your current tech, this approach can be one strategy to employ, as you can essentially plan to earn back the Flask that you lost by having carry-over Flasks in the first place.

As a take-away from this example, let's look at the situation from the opposite perspective, and say that when you are close to completing research on a tech, in the early game when you are trying to squeeze out every last Flask, you could be better off working a square that earns you more Food or more Hammers in place of Commerce that would otherwise disappear.

For example, if you start with Fishing but are not Financial, you might have the choice between working a Clam square for 2 Food + 2 Commerce or a Grassland Forest square for 2 Food + 1 Hammer. If you could complete research on the tech exactly by working the G For square, and you have at least one bonus to research on the current tech (the 20% "white arrow" bonus or the "know at least 1 AI who already knows the tech" bonus), then you might say that earning +1 Hammer is better than earning +1 Flask and missing out on 1 Commerce when on other turns, you could have traded that +1 Hammer for +2 Flasks.

Last edited: May 2, 2018
Kaitzilla, sampsa and Pedro78 like this.

Joined:
Dec 16, 2008
Messages:
1,721
14. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
@Harv that is very interesting and I can't explain it. I certainly didn't test extensively when making that chart, it's based on very simple math. (6+1)*1.4=9.8 so it shouldn't be yielding a +3 bonus, unless the formula is wrong. I'll check into this extensively.

15. ### sampsaGhost

Joined:
Jan 1, 2006
Messages:
3,187
Location:
Finland
Solved it. It's quite simple and actually very intuitive, no idea why I thought it wouldn't work like this.

Spoiler :
Start a game as Hatty, emperor (not that it matters) give myself hunting for 40% bonus and pick AH. We are generating 10 (8 palace, 1 city center, 1 silk), running 60% slider. According to the chart, 6 gives a bonus of 2 with 40% pre-req bonuses, so I'd expect to make 6+2+1=9 towards AH. AH costs 156 and 156/9=17,333 so 18T seems correct. Definitely not getting one extra here like Harv did in his example.

70% slider - according to the chart, 7+3+1=11 and 156/11=14,1818 i.e. 15T as expected, no flaw in the chart detected yet.

Met Joao via worldbuilder and gave him AH. Now 60% is 2T faster! A rational explanation is that both pre-req and AI's met -bonuses are calculated first, then rounded down, not rounded down in between as I thought.

(6+1)*1,4*1,04=10,192 leads to the correct result! However, this can only be proven by looking at the code.

Also, it was important to end the turn after giving Joao AH in the worldbuilder, otherwise I wouldn't get a bonus.

Unfortunately this makes the whole shenanigan even more difficult to use to your advantage. However, winning 1 in just two turns compared to binary research is nothing to sneeze at. I still wouldn't trouble myself too much with this, as that one rarely has an affect in the course of the game, while many other decisions do.