Calculation of Approval Rating, Family Size and Productivity

Gowron

Chieftain
Joined
May 21, 2007
Messages
62
Approval Rating

The approval rating of a civilization is given by

[Appr. Rating in %] = ([happy]*2 + [content]) * 50 / ([pop] + 1)

where [pop] is the total number of citizens, [happy] the number of happy citizens and [content] the number of content citizens.

The result is cut at the decimal point.


Family Size

The family size is given by

[F. Size] = 4 * (([food] + 2) / ([pop] + 1)) - 6

or, in a different form,

[F. Size] = (4*[food] - 6*[pop] + 2) / ([pop] + 1)

where [pop] is the total number of citizens and [food] the combined food output of all cities, ignoring unit maintenance.

The result is cut after the first decimal place.


Productivity

The productivity is given by

[Productivity] = [output]*10 / ([pop] + 1)

where [pop] is the total number of citizens and [output] the sum of the combined food, industry and trade outputs of all cities, counting in all trade routes, but ignoring both corruption and unit maintenance.

The result is cut at the decimal point.
 
nice analysis :)

though productivity was more trivial about what its based on, but never thought of family size deoends on food. thanx gowron!
 
Thank you for your legwork on this. Approval rating and family size are no surprises, but I didn't expect to see such an aggregate in Productivity. While the basic math looks good, we're missing overflow conditions. I've experimented a bit with Family Size.

Real world scenario:
food = 2015
population = 598
==>

Fsize = 4 * (2015 + 2) / (598 + 1) - 6 = trunc[7.46911...] = 7.4

So far so good, right?

food = 2016
population = 598
==>

Fsize = 4 * (2016 + 2) / (598 + 1) - 6 = -3.-4

Whoops. I've had family sizes of 12, so it's not Fsize that's overflowing. It must be whatever food operation performed that fails. Somehow, food is multiplied by roughly 16.25 before proceeding further. Also, this value seems to be derived by two equations due to the overflow of two integers.

EDIT:

My rationale cannot be true because at end game family size normalizes to 2.0, which is logically the correct answer. However, total food is much greater at this point. Hmm...
 
Sorry for replying late, was kinda busy ^^

Thank you for your legwork on this. Approval rating and family size are no surprises, but I didn't expect to see such an aggregate in Productivity. While the basic math looks good, we're missing overflow conditions.

Yep, I couldn't be specific about overflow conditions before since I do not have any suitable savegames. But thanks to your example I can give you the answer :)

From the overflow points at 7.4 and -3.4 it follows that a 2 is added at the end of the calculation. The overflow happens before that and makes 5.4 become -5.4

So, with the +2 at the end, the formula becomes
[F. Size] = 4*([food] - 2*[pop]) / ([pop] + 1) + 2

The numerator overflows when it becomes greater than 3276, which is exactly what heppened in your game.

Normally you'd expect that value to overflow when it exceeds 32767, but it is multiplied by 10 at some point, in order to get one decimal place without floating-point operations.
 
Thanks again!

This equation makes more sense. Now it's obvious the +1 in the denominator prevents undefined division and the +2 tacked onto the end guarantees "maintenance" birth for maxed out civilizations.

Overflow condition, simplified:

5*([food] - 2*[pop]) < 4096

Next I'll annoy you by breaking the other two equations in my spare time.
 
Next I'll annoy you by breaking the other two equations in my spare time.

Looking forward to it :)

As I said, I do not have any suitable saves to test the overflow behaviour, so every overflow example will be helpful :)
 
I did a little pregaming with a few minutes of spare time. Finding a test case for Productivity won't be difficult, but the jump in happiness from 0% luxuries to 10% is enormous. Hopefully I'll be able to decrease happiness at 10% enough to avoid permanent overflow; otherwise it's mass Elvis time under 0% to find a test case for Approval Rating.
 
The Approval Rating and Productivity equations are correct. Predictably, they overflow once the numerator exceeds 32767. For approval rating:

=> 50 * (2 * happy + content) < 32768
=> 25 * (2 * happy + content) < 16384
=> (2 * happy + content) < 656

Example:

=> 50 * (2 * 183 + 289) / (597 + 1) => 54%
=> 50 * (2 * 183 + 290) / (597 + 1) => -54%

For Productivity:

=> 10 * (food + industry + trade) < 32768
=> 5 * (food + industry + trade) < 16384
=> (food + industry + trade) < 3277

Example:

=> 10 * (1398 + 882 + 996) / (597 + 1) => 54
=> 10 * (1398 + 883 + 996) / (597 + 1) => -54

What's interesting is that while Family Size is tough to overflow and normalizes over time, Approval Rating and Productivity bounce between positive and negative in big games as they overflow time and again. In my biggest game, Approval Rating overflows a full six times!
 
I love it when the math geeks pick the game apart. I get to see the break down of the algorithms and how they function. Very interesting.
 
What about life expectancy?
 
Does life expectancy overflow? Otherwise, as given in Rome on 640K a Day, it's

(1500 / (20 + Robust)) - (Pollution * (10 / Size))

Robust = 50 * Size / (Size + Life)

Robust is halved after acquiring Medicine.

"Life" is a variable that tallies city sizes of those that contain Granaries and/or Aqueducts.
 
I've wondered how they calculated those. Did you find it out using the game code, or just by observing the values in different situations? (I'm guessing the latter would be extremely tedious and useless, since you could use the former.)
 
I assume Wilson & Emrich derived them empirically. I don't know whether Gowron had access to the book, but apparently he has experience with doing this kind of work empirically. But, yes, one can also use a debugger. The challenge there is finding where in the runtime the formulas are calculated, and 16 bit segmented DOS code can make that very challenging.
 
Back
Top Bottom