What is the best strategy for Cookie-Clicker-esque games?

Today, I stumbled across the game Cookie Clicker, which I recommend you avoid until you have at least a few hours of time to waste.

The basic idea behind the game is this: You have a large stash of currency, which constantly increases at the given rate. At any given time, you have a series of upgrades, each of which has a cost $c_n$ and each of which has production value $p_n$. Upon purchasing an upgrade, the cost is deducted from my bank, and the rate of income is increased by the production value.

For example, if I have $1,000$ cookies increasing at a rate of $10$ cookies per second, I could purchase an upgrade $(150,2)$ which will have an end result result of $850$ cookies increasing at $12$ cookies per second.

I stumbled across this question which asked about one possible heuristic, but the heuristic in question was proven to have some flaws. (I also stole much of my notation from there)

I found the following formula to give the "time improvement" of any single upgrade, which is the amount of time that will be saved by purchasing that upgrade.

$$\text{Time Improvement} =\frac{g-x+\text{min}(0,x-c_1)}{p_0}-\frac{g-x+\text{min}(c_1,x)}{p_0+p_1}$$ Where $p_0$ is current production rate, $x$ is my current stash, and $g$ is the goal as to how many total cookies I want to have. Basically, this takes into account how long it is expected to take at the current and future rate, and how long it will take to re-earn the spent money/wait to earn the money to spend. Also, larger values are considered better.

From this, my strategy has been to purchase the upgrade with the highest time improvement. If I do not yet have enough money to buy the required upgrade, I set that upgrade's cost as my current goal and repeat the strategy. I don't think this is optimal though.

Although the game has no defined end, I am going set a goal of $4$ billion cookies, enough to buy the antimatter condenser. Assume that I have an initial rate of $0.1$ cookies per second. Here is the list of main upgrades in the game, although there are several other powerups:

Cost per item, Increase of cookies per second
15, 0.1
100, 0.5
500, 4
3000, 10
10000, 40
40000, 100
200000, 400
1666666, 6666
123456789, 98765

Upon purchasing an upgrade, the cost of that upgrade increases by $15\%$, although the production value remains the same.

What is the best strategy for games similar to this? Given a list of upgrades, how should I make my purchases to minimize the time it takes to reach four billion?


You said you were looking for the best time improvement, but the object of the game is to maximize your cookie count. With a long-term strategy you can play the game in bursts by periodically choosing an optimal investment, then letting it run by itself in a background tab for the subsequent period of time.

So let's choose an idle period $T$ of 1 hour or 3600 seconds. The goal then is to maximize your score $C(t)$ at $t=T$ by investing in terms that contribute to $C$, but with the restriction that $C(t) \ge 0$ always. The terms of $C$ correspond to the investments in factories (cursor, grandma, ...).

You can invest in a term $nBt$ where $B$ is the factory's base yield (e.g. grandmas are 15) and $n$ is the number of factories you invested in. However the $i$th factory costs $P\times(1.15)^{i-1}$ where $P$ is the first price. The cost then of $n$ factories is the sum of exponenentials:

$$\sum_{i=1}^n P\times(1.15)^{i-1} = P {1 - (1.15)^n \over 1 - 1.15} \\ = {P\over 0.15} \times (1.15^n - 1) $$

Assuming you had no factories to start with, and you want to purchase (unknown) $n$ factories to leave it alone for (known) $T$ seconds. Your net gain $G(n)$ at that time is

$$ G(n) = nBT - {P\over 0.15} \times (1.15^n - 1) $$ The best $n$ in this isolated case is probably found where $G'(n)=0$: $$ BT - {P\over 0.15}{(1.15)^n \ln 1.15 } = 0\\ n = {\ln 0.15 - \ln\ln1.15 \over \ln1.15}+ {1\over \ln1.15}\ln({BT\over P})\\ n = 0.505822 + 7.155 \times \ln({BT\over P}) $$

So, the sweet spots for T=3600 are

Factory       B          P      n (for T=3600)
--------  -----   --------   ----
Cursor      0.1         15   23.2
Grandma     0.5        100   21.1
Farm          4        500   24.5
Factory      10       3000   18.2
Mine         40      10000   19.5
Shipment    100      40000   16.2
Alchemy     400     200000   14.6
Portal     6666    1666666   19.6

This roughly says that a strategy for maximizing cookies is to buy about 20 of the current best factories, go away and then come back in an hour then sell everything. Of course it doesn't cover how you get to afford the $n$ units in the first place. So I have to admit this is at best a first step towards a more complete strategy.