In my game I have a rank system. You start at rank A, and then you can level from level 1 to level 10. When you reach level 10, you get promoted to rank B, and you go from level 1 to 10 again, and then you get promoted to rank C, etc etc.

Getting from rank A to rank B takes a pre-determined amount of experience, which translates to a predetermined amount of real-world time. For example: getting from rank A to rank B costs 1200 experience, which translates to a week of game time.

What I'd like to achieve however, is to make leveling up early on in the rank easier than later on, so that when you rank up, its easier to achieve the first few levels, and the later levels are harder/take more time. Almost a bit like an exponential curve.

So really what I'm trying to do is divide the total amount of experience it takes to the next rank (total amount: 1200xp) by 10, into some kind of exponential-like curve, in a way that finally it'll still add up to 1200xp.

Does anybody know of such a formula/piece of code?


1 Answer 1


If you want a progression where the cost to level up from \$L_n\$ to \$L_{n+1}\$ increases by some ratio \$r\$ each time:

$$L_1 = a,\quad L_2 = a \cdot 4, \quad L_3 = a \cdot r^2, \quad ... L_n = a \cdot r^{n-1}$$

That's called a geometric sequence. (We say it grows "geometrically")

If you add up a bunch of terms, that's called a geometric series, and there's a handy formula for it:

$$\displaystyle \sum_{i=1}^n L_i = \frac {a (1 - r^n)} {1 - r}$$

We'll arbitrarily choose a value for \$r\$ to decide how curvy we want our curve: values closer to 1 give us a flat line, and higher values make steeper curves. But watch out - you might be tempted to reach for a value like 2 or 3 here, but the exponential stacking will quickly turn this into a gruelling slog by the end (\$2^8 = 256\$, so your final level of a rank would take two hundred times more work than the first!).

Let's choose a really shallow \$r\$ for starters, like 1.02 (each level costs 2% more XP than the previous). We can change this later if we like.

Here we want \$n = 9\$ (because once we level up from level 9, we cross over to the next rank and go back to level 1). So subbing those into the formula above, we get:

$$\displaystyle \sum_{n=1}^9 L_i = \frac {a (1 - r^9)} {1 - r} = \frac {a (1 - 1.02^9)} {1 - 1.02} \approx \frac {a (-0.195093) } {-0.02} \approx 9.754628 a$$

And now it's a simple matter to solve for \$a\$ to make the total equal to the total XP you want between ranks A and B:

$$\begin{align} 9.7546284311155456 a &= 1200\\ a &= \frac {1200} {9.7546284311155456}\\ a &\approx 123.018525 \end{align}$$

Ah, but here we run into a bit of a problem. All this math is for continuous real numbers. But for XP targets, we usually want integers. And we might even have other constraints, like wanting each XP threshold to be a nice round multiple of 10 or 50 or 100. There's probably a fancy integer programming solution to that, but myself, this is where I'd head to a spreadsheet.

Spreadsheet snapshot

In this Google Sheet (on the "WeekXP" tab), I've implemented the formula above, and added a column where I round the XP numbers to the closest integer.

You can see that using \$r = 1.2\$ in this example, the rounding doesn't quite work out - we total up to 1 XP higher than we meant to. So, you can either play with the numbers a bit or add a rounding bias until the number comes out to exactly the value you want, or just fudge the numbers by hand (for instance, subtracting the error from the last level in the sequence).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .