How much beakers are YOU losing to integerrounding?

Note that as soon as you start having scientist specialists in your cities, you produce beakers even at 0%. Thus, you can lose rounded beakers even at 0%...
 
Eh, Oyzar, the line you looked at is in the vanilla code. I'm looking at the BTS code:

Spoiler :

Code:
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;
}


The base one beaker per turn, the prereq modifier of 20, and the known-team modifier of 30 are all defined in XML files.

I'm still trying to find where the rounding happens...
 
There's another discussion of binary research (for Vanilla) in this article in the War Academy. The focus there is on rounding losses with multipliers in a city. The conclusion is that the technique almost always gives you a gain and that running specialists can re-introduce rounding losses.

I just spent about half an hour reading the game's code
A serious loss of in-game time. ;) I haven't looked at the code, but I expect the basic idea isn't any different for BTS because running 100/0 and 0/100 should still eliminate at least some of the rounding loss. Even if the savings aren't huge, using binary research helps keep me focused on my game management.
 
CvPlayer::calculateBaseNetResearch returns
[pre]((GC.getDefineINT("BASE_RESEARCH_RATE") + getCommerceRate(COMMERCE_RESEARCH)) * calculateResearchModifier(eResearchTech)) / 100[/pre]BASE_RESEARCH_RATE is the one free beaker


Rounding occurs (specified for oyzar's 90/10 example):
  • getCommerceRate(COMMERCE_RESEARCH) drops the fractional beakers: 12*0.9 = 10.8 --> 10
  • the ResearchModifier can be subject to a minimal rounding error, but not here: 100 + (30*8)/15 + 1*20 = 136
  • result of division by 100 will be floored: ( (1+10)*136 ) / 100 = 14.96 --> 14

oyzar: I only get 17 beakers per turn in the 100/0 example too. :confused:
( (1+12)*136 ) / 100 = 17.68 --> 17

pigswill: with only 7 other players knowing BW the modifier will be: 100 + (30*7)/15 + 1*20 = 134 which should give the same 17 beakers per turn
( (1+12)*134 ) / 100 = 17.42 --> 17
 
I think the question to be asked here is, if we modded it up to include an extra two places of precision, would anyone play it?
 
Collectively, "Hello Kazapp". ;)

Codewarrior -- personally, only if the mod was included with another more significant mod, as more than one mod cannot be loaded at once. I suspect few would be willing to load a mod that fixes just THIS issue, at the expense of any other game improvements (such as the 40-player mod, which is a requisite for my games).

So my understanding of this formula is that, in application, players should constantly switch from 0% to 100%. What about scenarios where you have enough gold to run at 100% for more than one turn in a row? Will beakers still be lost in those cases?
 
I have noticed that when I play 0/100 and 100/0, I lose large amounts to "Hey! You have lots of money. Give me some." vs. small amounts to rounding.

I'm happy to stay with my current strategy.
 
popejubal, are you referring to single player demands by the AI?

Just slap their wrists and tell them to keep their dirty paws out of your cookie jar!
 
I have noticed that when I play 0/100 and 100/0, I lose large amounts to "Hey! You have lots of money. Give me some." vs. small amounts to rounding.

Good point, but tribute demands tend to occur most often when my military is a little thin ...

If I'm going for maximum tech speed, I usually just run 0/100 for one turn whenever gold isn't enough for another turn at 100/0. If I can get sufficient gold from trading/pillage/city capture at the right times, I'll just stay at 100/0.
 
It's not just to integer rounding or such. You also lose beakers for not getting extra multipliers from civs that knows the tech (they might discover it as you are at 0%) and you get to delay comitting to a tech for a few turns, and you sometimes have gold for events and you can get multiplier buildings up and use them to full extent (particularly libraries).

All this with only one drawback, increased possibility of opponents demanding gold tribute.
Though I'll be the first to agree that a 0->100 and 100->0 button switch that you can hotkey would be sweet.
 
( (1+12)*136 ) / 100 = 17.68 --> 17

( (1+12)*134 ) / 100 = 17.42 --> 17

The worst of it, actually, is that 0/100 --> 100/0 is not the solution to integer-rounding.
The above two examples, and all others, may need other percentage breaks to achieve the greatest possible output, and possibly percentage breaks not available to us in the 10% sliding scale.
 
Though I'll be the first to agree that a 0->100 and 100->0 button switch that you can hotkey would be sweet.

I've got the poor man's version of the integerrounding mod right here!

Just edit your GlobalDefines.xml, preferably one in your CustomAssets/xml folder, so that COMMERCE_PERCENT_CHANGE_INCREMENTS is 100.

Also, pray you don't need to nudge the culture slider.


Actually, I've figured out enough to add a couple of extra +/- buttons for min-maxing. I'll try to code it up and submit it to BUG mod.
 
I have noticed that when I play 0/100 and 100/0, I lose large amounts to "Hey! You have lots of money. Give me some." vs. small amounts to rounding.

I'm happy to stay with my current strategy.

I run into this as well. And not just when the military is a little thin but from friends begging as well. I usually stop binary research when currency shows up. By that point I usually have enough beaker production where the rounding is a very small percentage as opposed to early game when 1 commerce is roughly 5% of my empires commerce.
 
Back
Top Bottom