This is an excerpt from my upcoming article Mathematics of Balance: Part 1 in the new print game development magazine Wireframe. Issue 1 is out 8th November.
What Is It? Probability is the mathematical definition of how likely something is to happen. For example, how often a dice will land on a six.
Why Is It Important? Most games are non-deterministic, meaning that there are random events that impact the course of play. These random events add excitement, but if they happen too frequently (or too infrequently) they will ruin a player’s experience.
Games are full of random elements, from weapon drops to dice rolls. But just because they’re random doesn’t mean that we can’t or shouldn’t quantify them. In fact, good game balance relies not just on the chance of an event but the value of it and all of its permutations. Very rare but highly valuable events can put a game out of whack as quickly as an event that’s too common.
Let’s start by looking at the simplest example of a probability: a coin flip. On a given flip, what is the probability (or chance) a coin will land head up? As there are two outcomes (heads and tails) which are both as likely, we can say the chance is 50%, or 0.5 or 1/2. All of which say the same thing: we expect heads to land on half of all coin tosses and so tails to land on the other half.
What now if someone makes you a wager: you toss a £1 coin, and if it comes up heads they keep your coin, if it comes up tails they give you another £1 coin. Is that a fair bet? In half the tosses we expect to lose a pound and in the other half we gain a pound. The below table shows how we can calculate an average winning by multiplying the chance with the benefit to give us a contribution (the value we can expect from that outcome). When summed, our contributions give us our average expected winnings.
|Outcome||Chance||Winnings||Average Winnings Contribution|
Table 3: Winnings table for coin toss wagering.
We can see that this bet is fair because nobody comes out ahead on average. However, this doesn’t mean that every toss we make will result in £0 winnings, but over many tosses we’d expect to see regression to the mean. Regression to the mean is the phenomena where the more often the same random event happens the more likely that the outcome will match the average.
We can plot the same coin toss wager as a probability tree over three tosses:
A probability tree maps the probability space — that’s to say all potential outcomes of a series of linked random events. Over our three coin tosses, we can see there are eight outcomes and each is as likely as the other to occur, so we can say any given outcome has a 1/8 (or 0.125 or 12.5% chance) of occuring. Another way we can calculate the ultimate outcomes’ chances is with the product of each event’s probability:
0.5 * 0.5 * 0.5 = 0.125
0.5^3 = 0.125
We can see that for the three tosses we never reach our calculated average outcome of £0, because there’s no way to give and take £1 three times to reach £0. Instead, we see a range of outcomes with winnings from -£3 to £3, but not all winnings are as likely happen.
We can link all of the coin toss outcomes by their winnings into events. Events are sets of outcomes that have their own probability — in our example, we can say that -£3 is an event comprised of one outcome and so 1/8 (0.125) probability, whereas the £1 event has two outcomes and a probability of 2/8 (0.25).
As our coin toss probability space grows with more tosses the number of winnings events increases, but the extreme outcomes become less and less probable. For example, it’s possible for us to flip the coin twenty times, land only heads and end up with -£20 but it is highly unlikely. We can calculate the probability of a -£20 run as:
0.5^20 = 0.000000953674316 = 1/1,048,576
Let’s now look at a common game scenario: You would like to give players 500 gold every day. You could simple add 500 gold to their balance, but wouldn’t it be more exciting if they opened a chest that had a random amount inside? Let’s look at how you might balance that using a loot table:
|Reward||Chance||Gold||Average Gold Contribution|
|Average gold per day||500|
Table 4: A loot table calculating average gold winnings based on a random reward.
A loot table is a list of rewards from which only one is chosen based on a “roll” (a random number generated in code) which is checked against the probability. Our above loot table makes use of the same average winnings contribution from our coin toss example which can be summed to give us an average gold reward per day.
This process is the basis of balancing most random events in games. All we need is the chance and the outcome of each event to create an average outcome. From this, we can balance our values such that events happen frequently enough (and no more) and are rewarding enough (and no more) to be exciting without breaking anything. We can easily scale up the method to build loot tables with thousands of items or balance complex combat procs (programmed random occurrences) for multiple classes.
However, as your game gets bigger and lots of random events have an impact on multiple systems, then you’ll become less certain about a player’s path. In this case, there’s another tool we can use: Monte Carlo simulations. Monte Carlo simulations can be made in a spreadsheet using scripting or with modified game code; either way, the basic premise is always the same: simulate the game being played, including random events, multiple times and analyse the outcomes by looking at averages and ranges.
Monte Carlo simulations, although a lot of work to make, are super helpful when your game gets complex and playthroughs take a lot of time. Running some kind of script that simulates a playthrough lets you quickly modify values and see their impact within minutes. These simulations can also let you catch edge cases, like a player getting a super rare drop early and racing through the game.
Keep in mind when working with chance in your games that humans are not naturally good at thinking in probability, so don’t worry if you struggled to follow some of this section on your first read. This probability irrationality leads to all kinds of interesting behaviours, such as superstition and belief in luck, but most importantly, the right rewards and probability ratios can lead to very strong compulsions to play. This makes mastery probability a super powerful game design tool.
Try this: For our gold reward example (see Table 4) we could say that the outcome is rather “spikey”. Spikey random events are ones where the outcomes have high variance and so create a value graph with lots of spikes.
Build a spreadsheet and rebalance the loot table so that the reward variance is reduced from 100x (100 gold to 10,000 gold) to 10x keeping the average gold per day the same.
Which loot table do you think players would prefer and why?