Inner Mechanics of Top 5 Cities (Info Screen / F9)

Manco Capac

Friday,13 June,I Collapse
Joined
Mar 1, 2010
Messages
8,051
Demographics were intended by the developers to give an insight to players on how competitive they are versus either other players or commonly AI's.
Sadly, it turns out the use was pretty limited, but still permitted interesting deductions like guessing Mansa Musa or Hammurabi presences out of power rates. Or guessing the number of spawned charismatic leaders or what are the odds to get a GLH without much risk with the averaging of Land Areas. The main attractive aspect of demographics is the costless [corrected] view to how world goes. Graph won't do that for free since BTS espionage.

Nonetheless, there is another tab in F9 that gives free info to us about the world:
TOP 5 CITIES/WONDERS. Let's have deeper look to this information tab and especially the less obvious TOP 5 CITIES.

Usually people considers that tab to be a reference on the most cultured cities given experience shows end game cities with lots of wonders or/and legendary cities.
There is partial truth to it, but let's take a stab into the code to reveal the reality:

In your Program Files BTS folder, you'll find a sub-folder called Assets. Click onto it and then follow that path:

\Assets\Python\Screens\CvInfoScreen.py

CvInfoScreen.py is a python file that contains various lines of codes expressing many screens like demographics and TOP 5 CITIES/WONDERS.

Here is the code:

Code:
def calculateTopCities(self):

		# Calculate the top 5 cities

		for iPlayerLoop in range(gc.getMAX_PLAYERS()):

			apCityList = PyPlayer(iPlayerLoop).getCityList()
			
			for pCity in apCityList:
			
				iTotalCityValue = ((pCity.getCulture() / 5) + (pCity.getFoodRate() + pCity.getProductionRate() \
					+ pCity.calculateGoldRate())) * pCity.getPopulation()

				for iRankLoop in range(5):

					if (iTotalCityValue > self.iCityValues[iRankLoop] and not pCity.isBarbarian()):

						self.addCityToList(iRankLoop, pCity, iTotalCityValue)

						break

	# Recursive
	def addCityToList(self, iRank, pCity, iTotalCityValue):

		if (iRank > 4):

			return

		else:
			pTempCity = self.pCityPointers[iRank]

			# Verify a city actually exists at this rank
			if (pTempCity):

				iTempCityValue = self.iCityValues[iRank]

				self.addCityToList(iRank+1, pTempCity, iTempCityValue)

				self.pCityPointers[iRank] = pCity
				self.iCityValues[iRank] = iTotalCityValue

			else:
				self.pCityPointers[iRank] = pCity
				self.iCityValues[iRank] = iTotalCityValue

				return


Here is the very part that calculates the worth of a city.

Code:
iTotalCityValue = ((pCity.getCulture() / 5) + (pCity.getFoodRate() + pCity.getProductionRate() \
					+ pCity.calculateGoldRate())) * pCity.getPopulation()

Ignoring the reverse solidus (backslash) meaning a breaking of line for asthetic uses while considering the two lines as a whole for compiling code, it is simply translated as:

City Worth = Pop*(0.2*C + F + P + G)

where
Pop: City population
C: Culture accumulated; not the rate
F: Food rate
P: Production rate
G: Gold generated (nor commerce or beakers) ; Via slider,buildings like shrines or specialists

Looking at this qualitatively, this is a pretty well sum-up of a city welfare/prosperity:
Higher populations mean a people are flocking to this city
More culture is the pride of a city
Better food,production rate and gold generation are the riches of the city

Now, quantitatively, the conclusions are far from expected. Culture is not a predominant part for TOP 5 CITIES. In fact, the factor Pop is the most important one. One may grow C, F, P elements or G factor, but another population point over pop=1 makes the city worth twice!

Now, let's include experience: early game is dominated with F,P,G parameters and globally Pop factor because early culture is limited until monuments apprear or libraries. Creative leaders will make its share, but those aforementioned parameters will take big part of city worth.

Where culture shines is the late games where cities have built plenty of wonders, made culture bombs,etc. explosing the diminished by 5 culture factor comparing to F, P and G factors that are limted to what the BFC can offer.
That is why late game is dominated with heavy wonders cities or legendary ones.

What to deduce from this in practice; well, early game where all civs start with pop=1 for [8,11] turns, C, F, P are balanced to each others, making nice deductions on how one leader is starting.

Why G factor is not including is simply due to AI coded normally to put the science slider to 100% given the absence of maintenance in cities and civics. Still, from testing, even if I put the slider down to 0% science, it doesn't change at all, so basically I'll ignore that factor out of necessity and everyone is on full science early game.

The equation is simplified:

City Worth = (0.2*C + F + P)

Observations:

Culture element (C) is indeed diminished in effect, but also rounded down to make even more difficult the comparison:

For instance, For each increment of 5 :culture:, the culture parameter 0.2*C increases of 1 point.
A normal leader (non-creative) will generate 4 :culture: after 2 turns, but 4/5 is rounded down to 0.

Setting a equal comparison in F and P (quite usual), creative civs will outdo non-creative ones on T2.

F and P are gone.
Creative | Non-creative​
T0:
0 | 0​
T1:
0 | 0​
T2:
1 | 0​
T3:
2 | 1​

Therefore, looking early TOP 5 CITIES in the very early turns (without moving your capital, this SIP or simply supposing most AI's have equal F and P), we can deduce creative civs.

LIMITATIONS: the problem with the TOP 5 is actually the limitation to 5 capitals, which means the study of AI capitals work well on standard maps with 6 opponents or work best on smaller maps.
Another rising problem is how human player on par in 0.2*C, F and P are put first place out of convention, making harder the distinction cities lower than yours.

It is when we are in the middle of the TOP 5 we have the capacity to deduce something by having a reference: us.

Nonetheless, in case where we do not SIP and loses turns on settling farther, the catching up in culture (being creative) permits to spot non-creative and those who are creative. All done in the interval [8,11] turns before AI goes pop 2 and screws the comparison. If the AI goes for worker first, the comparison will do a bit longer. Still, worker first or not is a big RNG decision from the AI.

An unexpected conclusion is about how to guess the presence of EXP (expansive leaders).
Expansive leaders in BTS are nerfed from Warlord expansions from 50% workers to 25% workers. That means, for every 4 :hammers:, the expansive leader get a bonus of 1 :hammers: rate. And that is a parameter in our city worth formula. Those AI's working a forested plain hill will get another :hammers: out and thus outdo us (non-expansive or lack of FPH while being EXP).

You might think culture will get in the way, but no!
The comparison shall be done on T1! A moment where both creative and non-creative see their 0.2*C parameter rounded down to 0, annihilating the influence of culture. What about food? Well, have you seen ever an AI settling on a food resource or getting modifiers from food output? Simply no.
Finally, there is a balance between food and hammers early.
Normally, the capital generates 2 :food: and 1 :hammers: and the tile it works with the first pop is almost always 3 :food: + :hammers: output. Making F+P= 6 most of the time.

What can go wrong in that reasoning?
First, for AI's, simply plains hills under cities. It gives another hammers and can be mistakened with EXP leaders. Still, does it happen often? Not really.
Deer in forest giving an output of 4 (F+P) is another case, but even even rarer. Let's ignore that one.
And lastly, there are cases of AI working a lake, but that doesn't interest us because they are lower than us.

What about IMP leaders with a modifier of 50%?
AI's start extremely rarely on a settler in capital on IMM and below. On deity, we see that and anyways, deity screws totally the reasoning of "city worth" because of the second free settler.


Conclusion:

Cities getting upper ranks than us either have settled on a PH or are under control of a EXP leader working a forested plain hill. This must be evaluated on T1 when culture has no effect in the comparison.

Shamefully, no real practical conclusions, but that was a nice thinking process. ;)


Conclusion is under revision.
 
I previously guessed that is must be pop*culture, but I never looked at early cities.

Later in the game, the culture value will overwhelm the food/production/gold value, and 0.2 * culture * Pop is a very good approximation.

The information can be important when more than 1 AI is going for culture, since you won't be able to see this on the victory conditions screen.
 
Does it adjust on the fly if you swap your build?

For example, if you're building a warrior (at 4 hammers per turn), then change your mind and start building a worker instead (and get 5 hammers per turn because you're EXP), will that instantly bump your city up in the rankings? Or do you have to actually hit end turn for it to recalculate?
 
Nice job Tachywaxon! :)

Not all research immediatly result in meaningfull practical applications, but it's worthwhile nonetheless.
Thanks!
 
Can you not just look at the demographics and see this?

Hmm, no I think. Because Mfg. Goods part is not sifting between an AI working a grass forests (which the AI will urge to do if the automatic best tile like FP or simply +3 :food: is not available before border pop), and this will lead to erroneous conclusions.
 
Does it adjust on the fly if you swap your build?

For example, if you're building a warrior (at 4 hammers per turn), then change your mind and start building a worker instead (and get 5 hammers per turn because you're EXP), will that instantly bump your city up in the rankings? Or do you have to actually hit end turn for it to recalculate?

In fact, I tested it and I am terribly disappointed. The production rate the function is calling is the raw one. I could give a huge amount of modifiers (forge, factory, etc.), a city with same F+P will outdo (if founded earlier) the one with modifier if its F+P is the same.

Looks like Top 5 cities screen is just good for knowing if some AI's is on a PH or working a forested deer. This has few opportunies except on an early conquest game on low levels or worker stealing (because AI's starting on PH have very high tendencies to use their innate hammers bonus on archer, which will be completed almost on sync with a pop growth, then goes for a worker).

I'm a bit shameful for the impetus without thinking.

Conclusion: Top 5 cities is only useful to determine late game AI's gunning for culture other than 3 cities presented in Victory Screen. We also can make an approximation via the new formula: Culture= City Worth / Population.

Re: It does adjust on the fly with plots swapping though.

EDIT: I still don't understand "pCity.calculateGoldRate()" calling function because even with slider changes or adding a shrine, it simply doesn't changer city order. That's weird. Would you help me for this aspect?
 
Looks like Top 5 cities screen is just good for knowing if some AI's is on a PH

...which is very valuable information for super early chariot or quechua rushes where you don't have luxury to scout all the capitals. So there is an application.:)
 
Hmm, no I think. Because Mfg. Goods part is not sifting between an AI working a grass forests (which the AI will urge to do if the automatic best tile like FP or simply +3 :food: is not available before border pop), and this will lead to erroneous conclusions.

I'm pretty sure you can see if an AI is working a forested grass in the first turn.
 
...which is very valuable information for super early chariot or quechua rushes where you don't have luxury to scout all the capitals. So there is an application.:)

On a PH, or the best tile in the inner ring is forested grassland.
 
It can be useful for multiplayer. You can try to guess which of the creative opponents has the best F+P stats, especially if you are one these creative guys.

By the way. What is food rate? Food surplus or crude food (all the food collected from tiles)?
 
I think the above equations are interpreted incorrectly from the code. When I read the code and did some experimentation with different values, I deduced the following:

top_city_value = pop*(culture/5 + food + hammers + commerce)

Culture is accumulated culture in the city, not the one produced. The food, hammers, and commerce are interchangable, and uses the current turn only - it is possible to bracket the range where other cities are early game simply by trying out different tile yields.

I'm still unsure if the culture/5 is rounded before multiplication, but I think it is rounded down.

I think only permanent bonuses to hammers and commerce count. Bureucracy works, and so should a forge, but bonuses that comes from building a specific item (say wonders for IND players) aren't used.
 
Top Bottom