Section 1.1 Calculus in Incremental Game Mechanics
December 12th, 2021
Incremental games, perhaps better known under the misnomer idle games, are video games whose gameplay centers on the acquisition of in-game currency.
Roughly speaking, the player spends in-game currencies to increase the rate at which they generate said currencies, which the player then uses to further increase the rate at which they generate said currencies.
...which they then use to further increase the rate at which they generate said currencies.
Though not the first game in the genre, the popularity of Orteil's Cookie Clicker in 2013 led to a surge of interest in incremental games, particularly on the flash game site Kongregate. Notable incremental games released since then include Adventure Capitalist, Realm Grinder, and Antimatter Dimensions, among others.
The history of incremental games is largely beyond the scope of this reading — we're here to do math, not ramble about Cookie Clicker. In this section, we'll take a look at two applications of calculus in incremental games:
Optimizing Happiness in Kittens Game, and
Modeling Replicanti Growth in Antimatter Dimensions.
The relevant gameplay mechanics in these examples will be explained, so it is by no means necessary to have previously played either of these games. They are, however, very entertaining, and so I highly recommend anyone to go give them a try.
Subsection 1.1.1 Optimizing Happiness in Kittens Game
Since its release in 2014, Kittens Game,developed by bloodrizer, has gone on to become a cult classic among works in the genre. In Kittens Game, the player is tasked with managing a village of kittens.
One mechanic in Kittens Game is the management of happiness. Every kitten in the village shares the same happiness value, which is expressed as a percentage.
Relative to a kitten at 100% happiness, a kitten whose happiness is 50% is only half as productive. Contrast this with a kitten at 120% happiness, who is 120% as productive, somehow. Assuming the player wishes to maximize productivity, it is evident that low happiness is detrimental.
There are many factors which influence the happiness of the player's kittens, but the main one we will focus on is the mechanic wherein every kitten's happiness goes down by 2% for each kitten 'in excess of 5'. Kittens don't like overpopulation!
For example, in a village of 6 kittens, each kitten will have a happiness of 98%. This is because the population is 1 greater than the pre-determined threshold of 5. Increasing the population to 16 will decrease every kitten's happiness to 78%.
Mathematically, this as interpreted as \(h = 1 - 0.02(p - 5)\) 1 , where \(h\) is the quantity denoting each kitten's happiness, and where \(p\) represents the population.
The happiness of the entire village is consequently
Those looking to maximize production will therefore wonder: What village population is the most productive? A village with a low population will lack enough kittens to do anything, but a village with too high a population will get nothing done.
We can feasibly imagine that there is a 'sweet spot' somewhere in the middle, with regard to the population. Let's now go about finding it. First, let \(h_{total}\) be notated as a function of \(p\text{:}\)
Since this is a quadratic function, we could complete the square to rewrite \(h_{total}(p)\) in vertex form, but instead, let's find the maximum using calculus. We'll employ the first derivative to find stationary points, and the second derivative to verify extrema. 2
A little bit of differentiation:
If we solve for \(h'_{total}(p) = 0\text{,}\) we see that \(p = \frac{1.1}{0.04} = 27.5\text{.}\) For this value of \(p\) (actually, for all values of \(p\)), the second derivative is negative, so there is definitely a local maximum at \(p = 27.5\text{.}\)
We can't exactly have half of a kitten (at least, not without raising serious ethical concerns), so this means that either 27 or 28 kittens is the optimal population for the player's village.
Alternatively, we know from pre-calculus that the vertex of a parabola is located at \(p = \frac{b}{2a}\text{,}\) so we could've eschewed the use of calculus by simply calculating \(p = \frac{1.1}{2 * 0.02} = 27.5\text{.}\)
To round off this section, let's consider a different mechanic. Luxury items are another factor which affects kitten happiness — for each luxury item in stock, the happiness of every kitten increases by a flat 10%. What effect would these items have on the value of the 'sweet spot'? I'll let you ruminate on that...
Subsection 1.1.2 Modeling Replicanti Growth in Antimatter Dimensions
In Antimatter Dimensions, developed by Hevipelle, the player's goal is to produce antimatter. Antimatter is produced by the titular Antimatter Dimensions, whose efficiency can be increased through the purchase of Infinity Dimensions (it's quite complicated, so don't worry about it).
Replicanti are a mechanic that further increases antimatter production. When an in-game tick elapses, every replicanti has a chance to replicate. The duration of an in-game tick, as well as the chance of replication, can be improved with upgrades. Simply put, more replicanti leads to more antimatter.
Let \(r(i)\) be the function expressing the amount of replicanti present at a time \(i\) in ticks, and let \(i(t)\) be the function representing the number of in-game ticks elapsed at this same time \(t\text{,}\) but now in seconds. Suppose the constants \(p\) and \(d\) represent the probability of replication and the duration of an in-game tick, respectively. 3
Our goal is to find an equation for \(r(i)\) which accurately models the growth of replicanti. To find said equation, let's approach the problem by taking a look at its derivative, \(\frac{dr}{di}(i)\text{.}\)
We know that the rate at which replicanti grow is proportional to the amount of replicanti already present:
This is, in fact, a differential equation. In fact, it's one of the simplest examples of a differential equation — you may already know what the answer is. Let's multiply both sides by \(di\text{:}\)
Divide both sides by \(r(i)\text{:}\)
Integrate both sides:
Almost there:
And finally,
There is one caveat, however. We wanted \(r(t)\text{,}\) not \(r(i)\text{.}\) Luckily, \(i\) and \(t\) are closely related through the function \(i(t)\text{,}\) so our function should actually resemble the following:
As it turns out, \(i(t) = \frac{t}{d}\text{.}\) For example, if \(t = 10\) seconds and \(d = 0.5 \) seconds, \(i(t)\) would assume a value of \(\frac{10}{0.5} = 20\) ticks.
Therefore, we arrive at a final equation for \(r(t)\text{:}\)
I bet it's not every day that video games make you think of calculus!