Question re: new commerce cities

k is farm % (not including special food source)
FSB is food source bonus
N is desired city size, n is current city size
C_k is cottage turns accumulated until reaching size N
T_k is number of turns to reach size N
T is the total number of turns we are considering
F_total is total amount of food (with granary) to reach size N

Basically, we have food needed to grow/food supply, and we integrate that to find total number of turns to reach size N, T_k.

If we know the farm %, since the total amount of food to reach size N is constant, we can calculate the number of grassland farm turns by subtracting our other food source. Knowing grassland farm turns we can calculate cottage turns, C_k.

And then cottage turns from turn 1 to T_k (max size) + cottage turns from turn T_k to T is the total number of cottage turns.

The graph is k vs C_k - N*T_k, whereas the total cottage turns is C_k +N*(T-T_k), so I'm ignoring N*T since it's independent of k.
 
Gr8scott, I think your formula (T_C-T_F)*R > T_F is using different approaches on each side and may be a little inconsistent.

If we assume that once we choose to run a cottage we will run it to max pop, then if we run the test till a cottage choice would reach max size, that one cottage accumulates T_C*R cottage turns. The farm choice will gain nothing, but we are free to run whatever number of cottages after T_f*R turns, so the inequality would be farm is (T_C-T_f)*R*cottages run at max pop > T_C*R.

If we assume that once we grow once more, then there's no difference between reaching there by an extra cottage or farm, you're arguing in the short run the first T_f turns the cottages extra turns, which kind of makes sense, but i think it might be misleading.
 
There's a good chance the debate does not have the intuitive answers described, because of how towns grow. If they changed the parameters a little, there could be a large change in how the answer works.

With a granary, the growth rate is (10+n)/(food_source_bonus+n-1) with grassland farms, 2(n-1) with flood plains or biology, or with a ratio of k farms to 1-k cottages, (10+n)/(FSB+k*(n-1)).

Then we integrate from 1 to N, our target population, to obtain the total number of turns to grow with respect to k:

T_k=((N-1)/k+11*ln((F+k*(N-1))/F)/k)-F/k^2*ln((F+k*(N-1))/F).

Now the total amount of food to grow to size N is F_total=(N-1)/2*(10+1+10+N-1))=(N-1)*(N+20)/2

We can figure out the total number of worked cottage turns until max size C_k by the ratio of non food source farm food to cottage turns,
(F_total-FSB*T_k)/C_k = k/(1-k). This is exact, as long as T_k is exact. In the long run, if you work your size 15 city long enough to be all towns, all your cottages will have to go through the cottage/hamlet/village phase.
So

C_k=(F_total-FSB*T_k)*(1-k)/k
and total commerce up to T turns (assuming T > 40+T_k) is
(town or whatever bonus)*(C_k+N*(T-T_k)), that is, cottage turns until target size then all cottages at that target size.

Therefore the total commerce is bonus*((N+20)*(N-1)/2*(1-k)/k-FSB*T_k*(1-k)/k+N*T-N*T_k) or
bonus*(N*T + T_k*(-FSB*(1-k)/k-N) + (N+20)*(N-1)/2*(1-k)/k)
If we plot this, we find that cottage turns is maximized when you farm everything. This is assuming once you reach size 15 with a (5 food source) you cottage everything, and there is continuous growth. As for the total number of cottage turns till growth, it peaks at k=0.09, something like cottage everything except at size 11. I think I eliminated all the - sign mistakes. So farm to 15.



OK, I'm going to answer you with a different example.

For everyone's sake, I'll keep the math to a minimum.

Player A and Player B both farm to city size 14, with the same +5 Rice resource in the original example.

Let's call the turn at which 14 pop is reached Turn 0.

Now, it takes 48 Food total to go from 14 to 15 pop, and only 24 Food with a Granary.
Let's assume both A and B have Granaries.

Player A then builds 13 Cottages and works them, but still works the +5 Rice.

Player B builds another Farm and grows to 15 pop.


A's food surplus remains +5, and B's food surplus is +18.

So B's city grows to 15 in 2 turns (or 1 1/3 turns if you like to keep fractions).

And A's city grows to 15 in 5 turns (or 4 4/5 turns if you like to keep fractions).

After they grow to 15, both build Cottages to have 15 Cottages each (let's assume they don't work the Rice anymore).

Now, let's count cottage turns. But first we must assume when the last Turn is. Let's assume 20 Turns.

Player A
13 Cottages, 20 Turns = 260 cottage turns
2 Cottages, 15 Turns= 30 cottage turns
total = 290 cottage turns

Player B
15 Cottages, 18 Turns = 270 cottage turns


Or, if you want to keep fractions we can count it a different way.

Player A
13 Cottages, 20 Turns = 260 cottage turns
2 Cottages, 15 1/5 Turns = 30.4 cottage turns
total = 290.4 cottage turns

Player B
15 Cottages, 18 2/3 Turns = 280 cottage turns


So Player A has more Cottage turns, both for the non-fraction and fraction case.

Now, what about Commerce?

Player A
13 Cottages, 13 * 10 * 1 + 13 * 10 * 2 = 390 commerce
2 Cottages, 2 * 10 * 1 + 2 * 5 * 2 = 40 commerce
total = 430 commerce

Player B
15 Cottages, 15 * 10 * 1 + 15 * 8 * 2 = 390 commerce

So Player A also generates more commerce than Player B, assuming 20 total turns.
 
Very interesting. Unfortunately, my calculation assumes a ratio of farms to cottages and growth from size 1 (although the latter can be changed by adjusting integration parameters, and I suspect as long as the growth is large, the results will not change). It also doesn't allow for cottage growth, since in 80 turns, they'll all be towns.

Also the integration is continuous whereas population is not, and I'm assuming it will not affect the numbers greatly.
 
I tested these numbers more, and assuming we can be flexible with the number of cottages:

Turns to grow T1_n= (10+n)/(FSB+a), where a is the number of farms.
n-1-a is the number of cottages.
Then T1_n*(n-1-a)-T1_n*N is our measure for cottage turns.
T1_n*(n-1-a-N)=-T1_n*(a+(N-n+1))=-(10+n)*(N-n+1+a)/(FSB+a)

The curve changes at the breaking point N-n+1=FSB, so for N=15, FSB=5, n=11, so all cottages (other than food source) is better at n>N+1-FSB, invariant at that number, and all farms is better below. This is similar to artichokes R and S, except it actually doesn't have to do with maintaining a total food surplus, but the initial food bonus.
As for my ratio calculation, the losses due to growing without all farms up to size N+1-FSB probably outweights the gain from going all cottages past it (note artichoke was getting only 10-20 more cottage turns). I'll have to think if this is what gr8scott did.

and with farms getting +2 food, except for 1 size below optimal, you probably want to farm: (N-n+1+a)/(b*(5/b+a)), so it's dependent on whether N-n+1 or 5/b is greater. Once you start running plains, then you subtract each one from the food bonus, and flood plains you add.
 
An example:
Suppose your food surplus is 4 and you are pre biology. You can work a farm or a cottage and you need to add 10 pop worth of cottages to the city. Should you farm or cottage?

taking food from 4->5 is a 25% increase. 10 * 25% = 2.5 >1 ==> farm away.
Suppose you grow. Add a cottage or a farm?
Now you are at 5 surplus and and have 9 pop left to go.
5->6 gives a 20% increase and 9 cottages = 1.8 > 1 ==> add a farm

1/6 * 8 > 1 ==> farm
1/7 * 7 = 1 ==> toss up
1/8 * 6 < 1 ==> cottage

So in this example, this rule of thumb would have you work 3-4 farms before starting to add cottages. As you approached the desired size, you would also go back and cottage over farms that were no longer sufficiently helping your percent growth.

Very nice approach to this sort of problem, but I think you are making a small mistake in your application of it. (but I could be overlooking something)

When you are making a decision to trade a cottage for a farm you look at how many turns earlier you will get future cottage tiles - this seems valid to me. But then when you grow you only consider the decision for the new tile, and take the farm from the previous decision as given. But that farm is one more potential cottage tile that you want to switch over earlier.

At each population level take all your 'free' population that can work farms or cottages to be working cottages, and consider the benefit of switching to a farm one tile at a time. You'll find you slightly undervalued farms, and (at least for grassland farms/cottages) the shift from farms to cottages happens suddenly, it isn't gradual.
 
Well, there is another way to solve the problem, and that is by brute force...but I'm not going to do it myself.

Basically, the problem is defined as 15 steps. Each step is defined as the number of each tile improvement

you will be working in the optimal case, at each population count.

If the 15th step is assumed to be defined as:

15: C15, F0, R0

Then the 14th step can be found by calculating the improvements which maximize cottage turns (or commerce) from pop 14 to pop 15. The 13th step can be found from the 14th and 15th steps. The 12th step can be found from the 13th, 14th, and 15th steps. And so on...


If you want to maximize Commerce, you'll need to define the number of turns played after maximum population is attained.
 
Very nice approach to this sort of problem, but I think you are making a small mistake in your application of it. (but I could be overlooking something)

When you are making a decision to trade a cottage for a farm you look at how many turns earlier you will get future cottage tiles - this seems valid to me. But then when you grow you only consider the decision for the new tile, and take the farm from the previous decision as given. But that farm is one more potential cottage tile that you want to switch over earlier.

At each population level take all your 'free' population that can work farms or cottages to be working cottages, and consider the benefit of switching to a farm one tile at a time. You'll find you slightly undervalued farms, and (at least for grassland farms/cottages) the shift from farms to cottages happens suddenly, it isn't gradual.

However, with Slavery, the value of keeping spare Farms even at high pop count still needs to be recognized, so that population can be grown to replace lost pop count more quickly.

So this exercise may become purely theoretical, I'm afraid...
 
I tested these numbers more, and assuming we can be flexible with the number of cottages:

Turns to grow T1_n= (10+n)/(FSB+a), where a is the number of farms.
n-1-a is the number of cottages.
Then T1_n*(n-1-a)-T1_n*N is our measure for cottage turns.
T1_n*(n-1-a-N)=-T1_n*(a+(N-n+1))=-(10+n)*(N-n+1+a)/(FSB+a)

The curve changes at the breaking point N-n+1=FSB, so for N=15, FSB=5, n=11, so all cottages (other than food source) is better at n>N+1-FSB, invariant at that number, and all farms is better below. This is similar to artichokes R and S, except it actually doesn't have to do with maintaining a total food surplus, but the initial food bonus.
As for my ratio calculation, the losses due to growing without all farms up to size N+1-FSB probably outweights the gain from going all cottages past it (note artichoke was getting only 10-20 more cottage turns). I'll have to think if this is what gr8scott did.

and with farms getting +2 food, except for 1 size below optimal, you probably want to farm: (N-n+1+a)/(b*(5/b+a)), so it's dependent on whether N-n+1 or 5/b is greater. Once you start running plains, then you subtract each one from the food bonus, and flood plains you add.

Right, because you're trying to balance Food Surplus with Remaining Cottages, not Remaining Pop Count (although they could end up being the same, by coincidence).

Remaining Cottages is:

C - c

where C = final cottage count
c = current cottage count

But this is the same as:

C - (n-f-1)

or

C - n + 1 + f

where n = current pop count
f = current farm count (a 1 is subtracted to account for the Food Resource)

Food Surplus is:

B + f (pre-Biology)

and

B + 2*f (post-Biology)

where B = the Food Yield of the Food Resource (this assumes only 1 Food Resource is used...if k Food Resources are used, then the above '1' should be changed to a 'k', and 2 should be subtracted for each k higher than 1, to account for the -2 Food accrued from eating)

So, without assuming a certain number of farms for pop count n,

C - n + 1 + f = B + f

or

C - n + 1 = B

With C=15, B=5,

15 - n + 1 = 5

n = 15 - 5 + 1 = 11

Or, you could go 14 Cottages and work the Rice...

Then C=14, B=5,

14 - n + 1 = 5

n = 14 - 5 + 1 = 10
 
Gr8scott, I think your formula (T_C-T_F)*R > T_F is using different approaches on each side and may be a little inconsistent.

If we assume that once we choose to run a cottage we will run it to max pop, then if we run the test till a cottage choice would reach max size, that one cottage accumulates T_C*R cottage turns. The farm choice will gain nothing, but we are free to run whatever number of cottages after T_f*R turns, so the inequality would be farm is (T_C-T_f)*R*cottages run at max pop > T_C*R.

If we assume that once we grow once more, then there's no difference between reaching there by an extra cottage or farm, you're arguing in the short run the first T_f turns the cottages extra turns, which kind of makes sense, but i think it might be misleading.

Would the formula be correct if it were changed to:

(T_c - T_f) * R > T_c

instead of T_f?

Because the number of cottage turns lost is actually 1 times the growth time assuming a cottage is built, not a farm.

OK, I see your point...the extra cottage turns accrued by having the Farm would be independent of the remaining pop growth, but solely dependent on the maximum number of cottages.

So, it would be:

(T_c - T_f) * C > T_c

where C is the max number of cottages.

But, doesn't this make the assumption that there were 0 Cottages at the current pop count?

Because, C should represent the number of remaining cottages, not total cottages.
 
The city


Presumed:
BtS
1 Worker for the city
Techs in place (Pottery/Agriculture/Writing/Currency)
Epic speed
Enough Hapiness/Health to reach size 15.
Culture from someplace to pop the borders (no need to rush the lib)
Constant techrate of 70%
Swap the Rice for a Grass cottage at size 15

1) Farm Rice, Cottage the place, Build Library
Needed worker turns:
Farm Rice 8
15 Cottages = 15*6 = 90, total 98.
By turn 200 this city will have:
5332 beakers
1366 gold
A library and 65 hammers left over

2) Farm Rice, Cottage the place, Whip Granary asap, Build Library
Needed worker turns:
Farm Rice 8
15 Cottages = 15*6 = 90, total 98.
By turn 200 this city will have:
5451 Beakers
1381 Gold
A granary, Lib and 65 hammers left over.

Conclusion: Whipping a granary is a good thing

3) Farm Rice, Cottage the place, Whip Granary asap (2 pop), Whip Library asap (2pop)
Needed worker turns:
Farm Rice 8
15 Cottages = 15*6 = 90, total 98.
By turn 200 this city will have:
6301 beakers
950 gold
A Granary, Lib and 155 hammers left

My conclusion:
At the expense of 431 gold we gain 90 hammers and 850 Beakers.
Whipping Granary and Library ASAP is a good thing

4) Add 1 farm, Whip the Granary asap (2 pop), Whip Libary asap (3 pop)
Needed worker turns:
Farm Rice 8
Farm 8 (to be cottaged at size 15)
15 Cottages = 15*6 = 90, total 106.
By turn 200 this city will have:
6078 beakers
904 gold
200 hammers

Conclusion:
Less beakers, less Gold, but more hammers
Not an improvement on anything, but more hammers.... for a Market or University?

5) Add 1 farm, Whip the Granary asap (2 pop), Whip Libary but delay 4 turns compared to 4 (2 pop)
Needed worker turns:
Farm Rice 8
Farm 8 (to be cottaged at size 15)
15 Cottages = 15*6 = 90, total 106.
By turn 200 this city will have:
6198 beakers
932 gold
155 hammers

Conclusion:
Adding a farm is sub obtimal, atleast if you keep it to size 15

6) Add 1 farm, Whip the Granary asap (2 pop), Whip Libary but delay 4 turns compared to 4 (2 pop)
Needed worker turns:
Farm Rice 8
Farm 8 (to be cottaged at size 6 after the Lib whip)
15 Cottages = 15*6 = 90, total 106.
By turn 200 this city will have:
6380 beakers
957 gold
155 hammers

Conclusion:
The best so far, when counting beakers/Gold. And still doable with just 1 worker.

7) Presuming INFINATE Workers. First farm everything to size 15. Then start cottages. Whipping granary for 2 and Lib for 2.
6165 beakers
924 Gold

Conclusion:
Doesnt help

8) Again INFINATE Workers. Farm everything untill whipping the Granary and Library and growing to size 9. Then Cottage everything.
6364 beakers
952 gold

Conclusion:
Doesnt help

For now... option 6 seems to win, and that with only 1 worker...
 
(T_c - T_f) * c > T_c

Where T_c is number of turns to grow, if a new cottage is built
T_f is number of turns to grow, if a new farm is built
c is the remaining number of cottages to be built

So, finding the values of T_c and T_f:

T_c = G / (B + f)

T_f = G / (B + f + 1)

Where G is the amount of Food required for growth,
B is the food bonus of the single Food Resource
f is the current number of Farms

So,

(G/(B+f) - G/(B+f+1) ) * (C - (n-f-1-1) ) > G/(B+f)

where n is the current pop count
C is the final number of cottages

Now, divide both sides by G and multiply by (B+f):

(1 - (B+f)/(B+f+1)) * (C-n+f+2) > 1

or

(1 - (1- 1/(B+f+1) ) * (C-n+f+2) > 1

or

1/(B+f+1) * (C-n+f+2) > 1

or

C - n + f + 2 > B + f + 1

Subtracting (f+1) from both sides gives us:

C - n + 1 > B

or

n < C - B + 1

Resulting in the the same formula arrived at by vicawoo.

So, this means, with C=15, B=5, you should Farm when:

n < 15 - 5 + 1

n < 11


Note that this result is independent of both G (the food cost of pop growth) and f (the current number of farms), even though they were used in the inequality.
 
So, I should farm my way up to size 10 and then cottage the rest changing farms to cottages as my pop continues to increase? I'm not very math-savvy :lol:
 
So, I should farm my way up to size 10 and then cottage the rest changing farms to cottages as my pop continues to increase? I'm not very math-savvy :lol:

That seems to be the case. From 1 to 10, Farms look more favorable. At 11 pop count, Farms and Cottages are about equal. From 12 to 15, Cottages look more favorable.

However, using Slavery would easily change the whole picture. This would make extra Farms more useful, even at higher pop count.
 
Very nice approach to this sort of problem, but I think you are making a small mistake in your application of it. (but I could be overlooking something)

When you are making a decision to trade a cottage for a farm you look at how many turns earlier you will get future cottage tiles - this seems valid to me. But then when you grow you only consider the decision for the new tile, and take the farm from the previous decision as given. But that farm is one more potential cottage tile that you want to switch over earlier.

At each population level take all your 'free' population that can work farms or cottages to be working cottages, and consider the benefit of switching to a farm one tile at a time. You'll find you slightly undervalued farms, and (at least for grassland farms/cottages) the shift from farms to cottages happens suddenly, it isn't gradual.

He assumed that all higher pop counts would adopt an all-cottage strategy.

But that assumption, in itself, is wrong, because it implies that if you Farm at pop count n, you will adopt an all-cottage strategy at pop count n+1...which could result in a sub-optimal result at the final pop count of N.

That is, if the formula says to Farm when pop count = 5, the assumption was that pop counts of 6 and higher would adopt an all-cottage strategy. But that is not necessarily the case for the optimal solution.
 
I wrote up this Python script.

[see next post]

The result was essentially, it doesn't really matter as long as you farm the food resource.

Now I'm not sure my script is perfect... but it should work. ^^


edit:

Might as well post my findings:
Code:
City #	Commerce
0:	7644
1:	9143
2:	9302
3:	9418
4:	9458
5:	9484
6:	9515
7:	9522
8:	9518
9:	9505
10:	9514
11:	9508
12:	9502
13:	9502
14:	9502
15:	9502
City # works a maximum of # farms till it's grown to size 15. At size 15, every city replaces every farm tile with a cottage.

I modified simulation() to this to get this output

[see next post]

Like I said, the code isn't perfect. So these are estimates.

edit2: Notes: I'm fixing bGranary right now. And iMode does nothing at the moment.

edit3: Bah, noticing more bugs. But, it does give you a general idea.

edit4: Updated the code. bGranary should work now. See next post. Probably won't bother to add more modes though. Right now it runs till all tiles worked by all Cities are Towns.
 
Code:
iStartSize = 1 # Starting city size
iTargetSize = 15 # Happiness Cap... Target Size for Growth
bGranary = False
bEm = False # Emancipation: +100% Cottage growth rate
bFS = False # Free Speech: +2C from Towns
bBio = False # Farms give +2F instead of +1F
iRivers = 0 # How many tiles are riverside, riverside gives +1C
bPP = False # Printing Press: Towns and Villages +1C
iCot_C = 1
iHam_At = 10
iHam_C = iCot_C + 1
iVil_At = iHam_At + 20
iVil_C = iHam_C + 1
iTow_At = iVil_At + 40
iTow_C = iVil_C + 1
iFarms = 1 # Number of farms
iFoodResources = 1 # Number of food resources
iExtraBaseFood = 1 # Extra base food yield, ie 1 = rice
iExtraFarmFood = 1 # Additional extra food yield with farm, ie 1 = rice
# pBonus[0] "bHasBonus" is Boolean, pBonus[1] "iExtraBaseFood" is Integer, pBonus[2] "iExtraFarmFood" is Integer
iBaseGrowth = 20 # Food required for 1 -> 2
iPopGrowth = 2 # Extra food required to grow per additional pop beyond 1

iMode = 0 # 0 = runs till all Cities have iTargetSize towns,
"""
iMode
0 = Runs till all Cities have iTargetSize number of Towns
>0 = Runs this many turns
-1 = Runs till all Cities have grown to iTargetSize
"""

#simulation()

class Tile:
    def __init__(self, bFarm, bRiver, pBonus):
        bHasBonus, iExtraBaseFood, iExtraFarmFood = pBonus
        self.bHB = bHasBonus
        self.iEBF = iExtraBaseFood
        self.iEFF = iExtraFarmFood
        if bFarm:
            self.iCot = -1
        else:
            self.iCot = 0
        self.bRiver = bRiver
        
    def setCot(self):
        if self.iCot < 0:
            self.iCot = 0

    def setFarm(self):
        self.iCot = -1

    def isFarm(self):
        if self.iCot == -1:
            return True
        else:
            return False

    def isTown(self):
        if self.iCot >= iTow_At:
            return True
        else:
            return False

    def getYields(self):
        iRet = [0, 0]
        iRet[0] = 0 # Food
        iRet[1] = 0 # Commerce

        if self.bHB:
            iRet[0] += self.iEBF

        if self.bRiver:
            iRet[1] += 1

        if self.iCot >= 0:
            # is a Cottage
            # Now I'm not sure if this is correct:
            if self.iCot >= iTow_At:
                # Town
                iRet[1] += iTow_C
                if bPP:
                    iRet[1] += 1
                if bFS:
                    iRet[1] += 2
            elif self.iCot >= iVil_At:
                # Village
                iRet[1] += iVil_C
                if bPP:
                    iRet[1] += 1
            elif self.iCot >= iHam_At:
                # Hamlet
                iRet[1] += iHam_C
            elif self.iCot >= 0:
                # Cottage
                iRet[1] += iCot_C
        else:
            # is a Farm (-1)
            iRet[0] += 1
            if bBio:
                iRet[0] += 1
            if self.bHB:
                iRet[0] += self.iEFF
                
        return iRet

    def doTurn(self):
        dtRet = self.getYields()
        if self.iCot >= 0:
            self.iCot += 1
            if bEm:
                self.iCot += 1
        return dtRet
        

class City:
    def __init__(self, iFarms, iFoodResources):
        self.iFR = iFoodResources
        self.iFarms = iFarms
        self.iTotC = 0
        self.iSize = iStartSize
        self.iFood = 0
        self.pTile = []

        # Create Bonus Tiles
        pBonus = [True, iExtraBaseFood, iExtraFarmFood]
        for i in range(0, iFoodResources, 1):
            if i < iFarms: #remember, i starts at zero while iFarms = zero means no farms
                bFarm = True
            else:
                bFarm = False
            if i < iRivers: #same here
                bRiver = True
            else:
                bRiver = False
            self.pTile.append(Tile(bFarm, bRiver, pBonus))
        # Create Normal 'Grassland' Tiles
        pBonus = [False, 0, 0]
        for i in range(iFoodResources, iTargetSize, 1):
            if i < iFarms: #remember, i starts at zero while iFarms = zero means no farms
                bFarm = True
            else:
                bFarm = False
            if i < iRivers: #same here
                bRiver = True
            else:
                bRiver = False
            self.pTile.append(Tile(bFarm, bRiver, pBonus))

    def totalFoodToGrow(self): # Returns Integer
        return (iBaseGrowth + (self.iSize - 1) * iPopGrowth)
    
    def foodLeftToGrow(self): # Returns Integer
        return (self.totalFoodToGrow() - self.iFood)
        
    def doTurn(self):
        self.iFood += 2 # City tile gives +2F
        for i in range(0, self.iSize, 1):
            if self.iSize >= (iTargetSize - 1) and self.foodLeftToGrow() <= 0:
                if self.pTile[i].isFarm():
                    self.pTile[i].setCot()
            iRetF, iRetC = self.pTile[i].doTurn()
            self.iFood += iRetF
            self.iTotC += iRetC

        if self.iSize < iTargetSize:
            if self.foodLeftToGrow() <= 0:
                if bGranary:
                    self.iFood = (self.totalFoodToGrow() / 2) + (self.iFood - self.totalFoodToGrow())
                else:
                    self.iFood = self.iFood - self.totalFoodToGrow()
                self.iSize += 1

        if self.iSize >= iTargetSize:
            for i in range(0, self.iSize, 1):
                if self.pTile[i].isFarm():
                    self.pTile[i].setCot()

    def isAllTowns(self):
        for i in range(0, self.iSize, 1):
            if self.pTile[i].isTown() == False:
                return False
        return True

    def getSize(self):
        return self.iSize

    def getCommerce(self):
        return self.iTotC
        

def simulation():
    pCity = []
    for i in range(0, iTargetSize + 1, 1):
        pCity.append(City(i, iFoodResources))

    bLoop = True
    iTurn = 0
    #print repr(iTurn)
    while bLoop:
        iTurn += 1
        bLoop = False
        sMsg = "Turn " + repr(iTurn) + ":\t"
        for i in range(0, iTargetSize + 1, 1):
            pCity[i].doTurn()
            sMsg += repr(pCity[i].getSize()) + "\t"
            sMsg += repr(pCity[i].iFood) + "\t"
            sMsg += repr(pCity[i].getCommerce()) + "\t"
            if pCity[i].isAllTowns() == False:
                bLoop = True
        #print sMsg

    iLowestC = pCity[0].getCommerce()
    for i in range(1, iTargetSize + 1, 1):
        if pCity[i].getCommerce() < iLowestC:
            iLowestC = pCity[i].getCommerce()
    

    print "Turn " + repr(iTurn) + ": All tiles worked by all Cities are now Towns."
    print "City #\tC.Adv%\tC.Adv\tC.Tot\tC./Trn"
    for i in range(0, iTargetSize + 1, 1):
        sMsg = repr(i) + ":\t"
        iAdv = pCity[i].getCommerce() - iLowestC
        fPerc = iAdv * 100.0 / iLowestC
        sMsg += "%.2f\t" % fPerc
        sMsg += repr(pCity[i].getCommerce() - iLowestC) + "\t"
        sMsg += repr(pCity[i].getCommerce()) + "\t"
        sMsg += "%.2f" % (pCity[i].getCommerce() * 1.0 / iTurn)
        print sMsg
    
    
        
simulation()

Sample Output:
Code:
Turn 224: All tiles worked by all Cities are now Towns.
City #	C.Adv%	C.Adv	C.Tot	C./Trn
0:	0.00	0	7770	34.69
1:	15.70	1220	8990	40.13
2:	17.50	1360	9130	40.76
3:	18.33	1424	9194	41.04
4:	18.84	1464	9234	41.22
5:	19.10	1484	9254	41.31
6:	19.20	1492	9262	41.35
7:	19.20	1492	9262	41.35
8:	19.15	1488	9258	41.33
9:	19.15	1488	9258	41.33
10:	19.10	1484	9254	41.31
11:	19.00	1476	9246	41.28
12:	18.84	1464	9234	41.22
13:	18.84	1464	9234	41.22
14:	18.84	1464	9234	41.22
15:	18.84	1464	9234	41.22

City # means farms worked during growth.
 
However, with Slavery, the value of keeping spare Farms even at high pop count still needs to be recognized, so that population can be grown to replace lost pop count more quickly.

So this exercise may become purely theoretical, I'm afraid...

It's not any more theoretical than gr8scott's simplifying assumptions. But the examples people have been posting have been incorrectly applying his basic idea. They are losing cottage-turns by forgetting the previous farms.

Example: the city can grow to size 6, it has only farmable grassland tiles. No granary.

By the logic people have been using, at pop 1 and 2 we want farms. At pop 3, we are going from a 4 to 5 surplus and have only 3 pop left so we want to cottage. I will also cottage all of the other farms at this point, even though it was suggested you gradually switch them over as you approach pop 6.

pop food farms turns overflow cottage-turns
1...22...1.....8.....2........0
2...22...2.....6.....2........0
3...24...0.....12....0........36
4...28...0.....14....0........56
5...30...0.....15....0........75


167 cottage-turns after 55 turns

Now I suggest, when your pop remaining is greater than your 'fixed' food surplus, farm all your free tiles, when it is less, cottage all of it.

pop food farms turns overflow cottage-turns
1...22...1.....8.....2........0
2...22...2.....6.....2........0
3...24...3.....5.....1........0
4...27...4.....5.....0........3 (avoiding overflow)
5...30...0.....15....0........75


78 cottage-turns after 39 turns, or 174 cottage-turns after 55.

Like I said, it's a small mistake, but I think it's important conceptually to not forget about the previous farms.
 
I think Gr8Scott had sound "basic" logic, but his application of the formula to the numbers was incorrect.

You are correct in saying that making the change from Farms to Cottages in a more sudden manner is probably the most efficient way to go.

The logic of the formula:

(T_c - T_f) * c > T_c

which is a variant of Gr8Scott's original formula, uses the parameter 'c' to represent remaining Cottages, instead of Gr8Scott's 'N' parameter for remaining pop growth.

The reason it should be 'c' instead of 'N' is that no assumption has been made regarding the current number of Farms, so there "could have been" Cottages built already at this point.

However, "if" (that's a big "if") Cottages have already been built up to this point in city growth, it would mean that building a new Farm would not contribute to cottage turns for the cottages that have already been built.

So, your general intuition is correct...if you have already built Cottages mixed in with the Farms, but your city is still lacking in growth, the next Farm you build will not increase the cottage turns of the Cottages you already built...it would only help speed up the creation of future cottages.

As for the consideration of multiple Farms, they will actually figure in to the T_c and T_f calculations.
You can assume that your current city already has some number of Farms. That number of Farms will directly affect the values of T_c and T_f.

The number of Farms your current city has will also affect the number of Remaining Cottages, because for each Farm you are working (and also the Food Resource) it means you are not working a Cottage.

In the end, the equation actually becomes independent of the 'f' parameter (the number of Farms).
Thus, when the decision is made to switch from Farms to Cottages, it should not be based on the number of existing Farms. The only remaining parameters are C (the desired number of cottages) and B (the Food bonus of the Food Resource).
 
Back
Top Bottom