Introduction
Cookie Clicker is a silly Javascript based web game. Here is a brief description of what you do: (description taken from this question: Explain a surprisingly simple optimization result)
You have an initial production capacity $p_0$ and a number of improvements $A, B, C, \ldots$ to build in some sequence you can choose. Each improvement $X$ has a cost $c_X$ and will take time to build proportional to its cost and inversely proportional to your capacity. When finished it will increase your production capacity by a given amount $p_X$. You can only build one improvement at a time. Which sequence should you build in in order to get all improvements as quickly as possible?
Background
However, there are a few twists in the game, not mentioned by that description:
- Heavenly Chips
- Essentially, the more cookies you have produced in all runs combined, the faster you can produce chips beginning with the next playthrough.
- The amount of cookies required for the next Heavenly chip increases linearly.
- Specifically, the first chip requires 1 trillion cookies baked all time, the second 2 trillion, the third, three, etc.
- Therefore the total number of chips you will have after a reset is the next triangular number, multiplied by 1 trillion.
- the Chocolate Egg.
- When you buy the Chocolate Egg (which costs a relatively negligible amount of cookies), you gain cookies equal to $5%$ of your current supply of cookies - not counting the cookies you spent to buy buildings and upgrades.
- You may sell buildings for half of what you paid for them. This does not affect your cookies produced total.
- Each new building of the same type costs $1.15$ times more than the previous building of that type.
So, late in a round of cookie clicker, buildings begin to cost an astronomical amount of cookies.
Consider the following scenario:
- You build a building, which costs $c_X = 10^{21}$, and has a production rate of $1.5*10^{14}$ cookies per second. You now have $0$ cookies.
- You immediately sell it (after $t=0$ seconds), so you get a refund of $5*10^{20}$.
- You buy Chocolate Egg, which gains you (approximately) $2.5*10^{19}$ cookies. You then reset, gaining the appropriate amount of extra Heavenly chips for that bonus amount.
- If you had not built the building, you would have gained $5*10^{19}$ cookies.
- However, if you had allowed the building to produce for some number of seconds, it would have eventually produced enough cookies to pay for the lost Chocolate Egg cookies, plus all the cookies it will continue to produce after that point.
The Question
Towards the end of a run, you might often let the game produce cookies for awhile, without building more buildings. This is because of the phenomenon described above - if you don't let the building produce for long enough, you will lose potential Chocolate Egg cookies. So here's the question:
For simplicity, assume there is only one type of building. Given:
- Current bank of cookies $B_0$
- Initial production $p_0$
- Incremental production $p_X$
- Incremental cost $c_X$, where $c_{X+1} = 1.15 \cdot c_X$
- Current time $t_0$
- Planned time to reset $t_{reset}$
How long before $t_{reset}$ should you stop making new buildings and start banking cookies?
t_reset = num_cookies / cookie_per_sanyway, easy enough. But I got to a point where I realized that the only thing that mattered was getting that stacked golden cookie and it was super boring to wait around for it for hours and hours so I stopped playing. – durron597 May 16 '16 at 21:20