Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Please read the forum rules before posting.

Check if you are posting in the correct category.

The Off Topic section is not meant for discussing Cookie Clicker.

The mathematics of Cookie Clicker

bob_32_116bob_32_116 Member Posts: 770 ✭✭✭
edited August 2016 in General Discussion
It is depressing if you think too much about it.

I tried Cookie Clicker Classic, and realised very quickly why it was superseded and had to be improved.

The rate of production is proportional to the number of buildings. Hence, the time taken to acquire each new building is proportional to C/n where C is the cost of each building and n is the number of buildings already owned.

If C were constant, elementary maths tells us that time increases with log(n), or, turning it around, n increases exponentioally with T. Whacko!

Of course C is not constant. In the current version of the game there is an inflation factor of 15%, i.e. each new building costs 1.15 times the previous one. C increases exponentially with n, and this completely overpowers the effect of dividing by n in the expression C/n. Time now also increases exponentially with n, or equivalently we can say that n, and therefore the rate of production, increases only logarithmically with T.

Let's put this in layman's terms. Say you have been playing CC classic for two months, and on the second day (between T = 1 day and T = 2 days) you were able to get 50 buildings. (This is just a guess, I do not know what the actual number is.)
How long will it take you to get the next 50? Nearly two days. After a month of playing, how many buildings will you get in the second month? Thirty times as many? Nope. Only about 50. Play for 2,000 years, and you will only get about 50 between the end of the 1000th year and the end of the 2000th year. Although the total number of cookies baked will increase without limit if you let the game run long enough, it will very quickly become too boring to bother.

No wonder Orteil had to introduce building upgrades to double the output, cookie upgrades, dragon auras, wrinklers etc. All they do however is delay the inevitable.

You might think synergies would make a big difference. With a synergy, the output of one building is proportional to how many of another building you have, so the total production now starts to increase as the square of the number of buildings. Instead of C/n we have C/n^2. Sadly, n^2 (n squared) still increases much more slowly than the exponential increase of C, so the production still only increases logarithmically with time.

The effect of ascensions is interesting. I suspect that most people ascend when there is just not enough happening in the game to keep their interest, however they may choose to rationalise it. Each prestige level adds 1% to your production rate (once it is unlocked). Sounds good huh? But it takes longer and longer to get those prestige points, because it's only based on the cube root of the total cookies baked. I have not done the maths, but I am pretty sure that once again they will just leave the production rate as a logarithmic function of time.

As I said, it's depressing if you think too much about it. Maybe I should just play the game. :D


Update: After a bit more thought, I have decided that the effect of ascensions and prestige points is that the production rate is proportional to the square root of time. This is substantially better than log(T), but you have to get very many ascensions , and the maximum number of upgrades each time, before you see this effect.

I won't bore you with the analysis unless someone asks me to.
Post edited by bob_32_116 on


  • 222lawlawlawl_games222lawlawlawl_games Member Posts: 314 ✭✭
    What is the analysis?
  • bob_32_116bob_32_116 Member Posts: 770 ✭✭✭
    edited August 2016

    What is the analysis?

    OK, here we go:

    After a very long time of playing, I will have all the achievements and heavenly upgrades, and I'll get all the possible upgrades each run, and it will just be a matter of ascending periodically to increase prestige. Each prestige point adds 1% to CpS, so after a very long time with very many prestige points we can say that CpS is proportional to prestige points.

    Prestige points in turn is proportional to the cube root of the total number of cookies baked all time. This leads to a differential equation:


    C = total cookies baked
    t = time
    P = prestige level


    dC/dt = k * P
    = k * C^(1/3) for some constant k

    To solve this we need to invert it:

    dt/dC = 1/k * C^(-1/3)

    Integrating with respect to C gives

    t = 3/2k * C^(2/3)

    which rearranges to

    C = (t * 2k/3)^(3/2)

    This tells us that the total cookies is proportional to time raised to the power 3/2, therefore the rate of production is proportional to time to the power 1/2.

    Post edited by bob_32_116 on
  • bob_32_116bob_32_116 Member Posts: 770 ✭✭✭
    edited August 2016
    ^^ Further to this, if we assume that on each run the player keeps going until the game reaches a plateau phase of some kind, after a very long time that plateau phase will be at about the same point for each run. "Same point" as defined by the number of each producer owned. That means the rate of ascension will simply be proportional to CpS, therefore it will also vary as the square root of time. Or in other words, length of each run will be inversely proportional to t^(1/2).

    If you keep playing long enough, eventually you will find yourself ascending every few seconds! I am pretty sure this requires something like a billion years of playing. Proof of this is left as an exercise for the reader.
  • bob_32_116bob_32_116 Member Posts: 770 ✭✭✭
    edited January 2017
    Having some serious time on my hands, I decided to construct this spreadsheet, which is a Cookie Clicker simulation to show the behaviour over a long period of time. There are a number of simplifications:

    - No ascensions; this is just a simulation of one long run.
    - Only one kind of building.
    - Initial cost of building is 1.
    - Inflation factor is 1.15 (as in the actual game).
    - Each building produces one cookie per unit time.
    - Game starts with one cookie in the bank to allow things to get started.
    - No building upgrades or cookie upgrades; these just confuse the issue without changing the long term behaviour.

    The graphs on the second sheet show the behaviour over time. Note that the time scale is logarithmic, and the vertical axis of the graph of total cookies over time is also logarithmic.

    The most interesting graph is the last one. Not surprisingly, as the run proceeds,
    the rate of acquiring buildings slows down, production becomes nearly constant, and the gap between instantaneous production and average production over the entire run becomes narrower. What is surprising is that this ratio does not appear to converge to 1; it seems to approach a value slightly higher than 1. I am not sure if this is an illusion. It would take a lot more time steps to see whether this is the case, and a spreadsheet is probably not the most suitable programming tool for investigating this. It looks as though it could approach 1.15, and I wondered if it's relevant that the inflation factor is also 1.15, but I think this is probably just coincidence.

    I have experimented with inflation factors higher and lower than 1.15, and although the numbers change, the basic shape of the graphs does not change. The last graph always shows a rise to a peak, then a smooth decay up to a certain point at which it appears to fall off a cliff. This tipping point is the point at which the increased cost of the building begins to outstrip production, so that it is no longer possible to buy another building at every time step. Finally it decays to a minimum value, which could be 1 but looks as if it may be slightly higher than 1.


    Edit: The spreadsheet seems to lose information in the process of uploading, so I'll just post images of the graphs.

    Post edited by bob_32_116 on
  • ChocolateMachineChocolateMachine Member Posts: 106 ✭✭
    Cool. Is the spike in the last graph at 4-5s just from buying the second building?

    I don't think I understand the importance of the current production to average production ratio. Why does it make sense to ascend when that gets below the prestige boost ratio? I mean, in a real game, isn't average production impacted a lot by things like golden cookies and wrinklers?
  • bob_32_116bob_32_116 Member Posts: 770 ✭✭✭
    edited January 2017

    Cool. Is the spike in the last graph at 4-5s just from buying the second building?


    I don't think I understand the importance of the current production to average production ratio. Why does it make sense to ascend when that gets below the prestige boost ratio? I mean, in a real game, isn't average production impacted a lot by things like golden cookies and wrinklers?


    Wrinklers boost both instantaneous production and average production, so they don't affect the ratio. Obviously when looking at "current production" that figure has to include what is being hoarded by wrinklers.

    As for golden cookies, if you play passively they do not enter into the equation. If you play actively then your "average production" includes everything, but your "current production" is only calculated from buildings, so yes you do need to adjust for this by mentally multiplying the "current production" by whatever factor you think is the production boost you are getting from golden cookies.


    I changed the parameters slightly so that the cost of the first building is 10 rather than 1, which gives more realistic results in the low end of the graph. I have also extended it out to 10,000 time steps. Here's the result of that on the final graph:

  • bob_32_116bob_32_116 Member Posts: 770 ✭✭✭
    edited March 2017
    I created another simulation, this time of an idealised CC game in which you can buy fractions of a building; at each time step, the player empties the bank of all the cookies produced in the previous time step, and buys as many buildings as that will allow. This gives a smooth curve:

    I'm convinced more than ever that this curve never falls to 1, but approaches a value something like 1.16. Someone with more maths skill than myself might be able to analyse the function and determine what the theoretical limit should be.


    Edit: I wrote a CC simulation in a programming language (Octave), which has the advantage that I can let it run for as many time steps as I wish, without the cumbersome task of setting up thousands of lines in a spreadsheet.

    Having let it run for 10^8 time steps (about 5 minutes), I now think maybe the ratio does approach close to 1, but it takes a VERY long time to do so. I suspect that the distance from 1 may be inversely proportional to the log of the playing time.

    Some stats:

    Time steps Final ratio

    100 ..............1.8412
    1000 ............1.2877

    this data assumes starting with one building and no cookies in the bank. Cost of the first building is 10.
    If the time steps were seconds, this would represent a run lasting about three years.
    Post edited by bob_32_116 on
Sign In or Register to comment.