Among game designers, the scientific aspect of their profession, especially the importance of mathematics for successful game design, is often neglected. (Freyermuth 2015) When browsing through renowned game developer websites such as Gamasutra or MakingGames, it is difficult to find a single article on mathematics on the front page. This paper aims to help correct this and show that mathematics is absolutely necessary for successful game design.
First, we show the importance of chance for the realization of the desired game experience. Then, the mathematical nature of chance and the basic knowledge of stochastics required for the correct handling of chance experiments are worked out and illustrated through a board game example with both dice and card mechanics.
Randomness in Play
If you compare Pac-Man and Ms. Pac-Man superficially, you might get the impression that they are completely identical (with the exception of a few art assets and pathing details). In both games, the player moves through a maze collecting points, which increase their score. Meanwhile, the player tries to avoid four ghosts that kill them when they collide. (Pittman 2017)
The core difference between the games shows itself when searching the internet for solution strategies: Good Pac-Man players memorize movement patterns that, if executed correctly, lead to success with absolute certainty and must be stoically played down (Pittman 2017). The challenge lies in learning the movement patterns and acquiring the hand-eye coordination needed to execute them. Players of Ms. Pac-Man, on the other hand, pay attention to the ghosts’ decisions, play strategically, and react accordingly (StrategyWiki 2017).
This significant difference between game experiences originates in the behavior of the ghosts. While their pathfinding in Pac-Man is strictly deterministic, Ms. Pac-Man introduced random variables that aim to make the memorization of patterns less effective. PacManPlus, an Atari 7800 & NES Developer at Midway, commented on this in a thread discussing the artificial intelligence of the ghosts:
“[…] the main difference in the Monster AI between Pac-Man and Ms. Pac-Man, is that in Ms. Pac-Man, Blinky and Pinky randomly move about the maze while in the first 7 seconds instead of going into their corners. This was probably done to make patterns almost impossible […]”
PacManPlus, 2005
“To a certain extent, games should be unpredictable” (Adams and Dormans 2012) and random chance – alongside human decisions and complex game mechanics – is one of the three major approaches that can be used to implement unpredictability in games. (Adams and Dormans 2012)
The Nature of Probability
Let’s imagine that we are developing a board game, for which we have different types of dice and card decks at our disposal. In order to implement these for the benefit of our desired game experience, we must understand their nature, and thus that of randomness itself. Only then will we be able to model and modify a system with random inputs and/or outputs so that it serves our original design intent. (Schreiber 2010)
Probability theory provides the necessary tools for this. It is a branch of mathematics and is therefore based on facts and laws. Probabilities can, at least in the cases relevant to game design, be calculated with absolute precision. As a designer, it is essential to avoid errors of reasoning that assume insufficient accuracy in probability theory, as these are a hindrance to the correct handling of random systems. (Sigman 2006)
One of the most important, categorical distinguishing features of random events is that they are either interdependent or not. Knowing which of the two sides you are on when dealing with a stochastic problem is essential to calculating probabilities correctly. (Sigman 2006)
Independent Random Events
Random events are described as independent if their probability of occurrence is not influenced in any way by other random events. For example, rolling a die twice describes two independent events, as the result of the first roll does not affect the result of the second roll, and vice versa. (Sigman 2006)
Dice Notation
A dice with six sides is also known as a d6. The d stands for dice, and the 6 for the number of faces. If there is a number in front of the d, this symbolizes the number of dice. With 2d10, for example, we are looking at 2 dice with 10 faces each. However, this designation is not limited to commercially available, actual dice; a coin can also be referred to as d2, or a digital random number generator that outputs numbers between 1 and 19 with equal probability as d19. (Schreiber 2010)
Expected Values
For our imaginary board game, we decided to use a standard d6. A characteristic property of the dice (and all other random number generators mentioned above) is that every result – every face of the cube – is equally likely to occur. This property allows us to calculate the expected value of any dX by dividing the sum of all face values by the number of faces. The expected value E of a regular d6 with the face values {1, 2, 3, 4, 5, 6} is therefore:
Our board game can therefore be balanced on the premise that the average dice roll is 3.5. (Schreiber 2010)
Probability Distributions
Let’s assume that a decision was made regarding our board game that a largest possible roll of 6 is deemed too low and should be increased to 12. We now have two options: we can either double the number of dice (2d6) or double the number of faces (d12).
These two approaches are not equivalent. This becomes clear when we view the probability distributions of a 2d6 and a d12:
The distribution of the d12, like that of the d6, is linear. For the 2d6, however, we can see that average results have a much higher probability than the extremes. This is due to the fact that throwing two dice is not a single random event but two simultaneous random events that are calculated in relation to each other. To understand this, we need to dive into probability theory. (Flick 2017)
Conditional Probability
One of the most important skills needed when dealing with randomness is calculating the probability of conditional random events – events that presuppose the occurrence of other events (Sigman 2006). They can be illustrated as a tree diagram:
In the figure above, we consider the tossing of two coins: a 2d2. We start with a marker at the top and move down the tree, with every toss being visualized as a branching between ‘heads’ (H) or ‘tails’ (T). The toss of a coin selects a branch at random and moves the marker along the chosen branch down to the level below. This step is repeated until we reach the bottom of the tree. (Sigman 2006)
The following statements can be derived from this: The probability of tossing ‘tails’ with one coin is 1/2. The probability p of throwing ‘tails’ twice and arriving at the rightmost endpoint at the bottom of the tree is therefore:
For all ndx, with n being the number of dice and x being the number of faces, this means that each potential outcome possesses a probability of 1/x at every branch. Consequently, the probability of reaching a specific endpoint at the final stage of the tree equals the probability of a single path at each branch raised to the power of the total number of branches passed: (1/x)n.
But this does not yet explain why the probability distribution of a 2d6 isn’t linear. The reason for this is that the tree diagram distinguishes between ‘heads + tails’ and ‘tails + heads’, while a summed-up roll of ‘3’ does not distinguish between ‘1+2’ and ‘2+1’.
If we assign the values ‘0’ and ‘1’ to ‘heads’ and ‘tails’, and add them up as we move down the tree – similarly to how we would add up the numbers of two dice – we can see that ‘1’ is twice as likely as ‘0’ or ‘2’, as there are twice as many endpoints with the value ‘1’. Consequently, to calculate the probability of a value, we need to multiply the probability of arriving at an endpoint with the number of endpoints of that value, which is equal to the number of combinations (k) through which the value is obtained:
With a 2d6, a ‘7’ can be rolled as the six combinations ‘1+6’, ‘2+5’, ‘3+4’, ‘4+3’, ‘5+2’, and ‘6+1′, whereas a ’12’ is only possible as ‘6+6’. This results in the following probabilities:
From this we can conclude that the answer to the question of whether a d12 or a 2d6 is more suitable for our purposes depends on the experience we aim to create: If we want increased randomness, we use few dice with many faces. If we want to compress most rolls towards the expected value, we use more dice with fewer faces.
It is also worth noting that this means that the expected impact of individual luck on the final outcome of a game will shrink the more often dice are rolled. Because the compression effect increases with the number of dice, it will also increase with the number of repetitions. This causes the combined rolls of each player to increasingly tend towards the average, meaning the difference between them will increasingly tend towards zero.
Bernoulli Experiments
With these insights, we can not only calculate the probabilities of combined dice results, but also determine the likelihood of an event occurring a certain number of times in a series of independent random experiments. For this to apply,
- the number of trials must be fixed,
- the question should define exactly two possible outcomes (event and counter-event),
- the random events need to be independent,
- and the probability of success for each event needs to remain constant.
This experimental setup is known as a ‘Bernoulli experiment’. (Sigman 2006)
Let’s revisit our imaginary board game and assume that an event challenges the player to roll at least two ‘6’s with three 2d6 rolls: What’s the probability for the player to pass this challenge?
First, we need to confirm whether this question fulfills the criteria of a Bernoulli experiment:
- Fixed Number of Trials:
- Yes, the player is performing a fixed number of trials, which is rolling the dice three times.
- Two Possible Outcomes:
- Yes, the two possible outcomes are success (rolling at least two ‘6’s) and failure (rolling fewer than two ‘6’s).
- Independence:
- Yes, each roll of the dice is independent of the others. The outcome of one roll does not influence the outcome of subsequent rolls.
- Constant Probability of Success:
- Yes, the probability of rolling a ‘6’ on each die remains constant at 1/6 for each roll.
Since all the criteria are fulfilled, the given scenario qualifies. This means we can now calculate the probability of the player passing the challenge:
Three 2d6-rolls can be summarized into 6d6. For starters, we will calculate the probability of rolling two ‘6’s with the first two dice and multiply this by the probability of not rolling a ‘6’ with any of the other:
To answer the question of how high the probability is that the player will roll two ‘6’s with any two of the dice, we multiply this result by the number of possible combinations in which the target events (rolling a ‘6’) and counter-events (not rolling a ‘6’) can occur: First and second roll a ‘6’, or first and third, or first and fourth, etc. These combinations are called permutations. (Schäfer 2012)
Fortunately, we don’t have to calculate this by hand. Combinatorics, another branch of mathematics, has a solution for this: the binomial coefficient k:
Consequently, the probability P(2) of rolling exactly two ‘6’s with 6 d6 rolls is:
However, since our board game event speaks of at least two ‘6’s, we must also calculate the chances P(3), P(4), P(5) and P(6), i.e. the probabilities of rolling three, four, five or six ‘6’s, and add them to this result:
The probability of passing the dice test is 26.4%, meaning that around 3 out of 4 dice tests fail. This knowledge helps us to implement the event in our board game in favor of the desired experience and to balance the game accordingly.
Negation
The calculation above was quite complex. In many cases, it is easier to negate the question, calculate the probability that an event will not occur and subtract that probability from 100%:
No Guarantees
Independent random events can never guarantee the outcome of a random experiment. This can cause issues in some cases.
An example: Our imaginary board game is to have a new feature. The player should press three consumable switches to open a door. The design intent is that it should not possible to predict which switch will open the door. If we implement independent randomness here, the only way to guarantee solvability is to set the chance of success of all switches to 100%, which would remove randomness entirely.
In such cases, a hybrid approach is preferable, where one of the switches is guaranteed to open the door, but which one is determined by chance. Fortunately, there exists another form of randomness that can be used to achieve this behavior.
Dependent Random Events
Dependent random events, as the name implies, are interrelated, with the outcomes of previous events affecting subsequent events within the same experiment. Card decks serve as prime examples of dependent chance. (Schreiber 2010)
Consider a deck with n = 6 cards, numbered from ‘1’ to ‘6’. The probability of drawing the ‘6’ is 1/6, as the ‘6’ is one out of six cards. After we draw a card that is not the ‘6’, there are only five cards left in the deck, meaning the probability of drawing the ‘6’ on the next draw has increased to 1/5. As we keep drawing the wrong cards, the probability of drawing the ‘6’ keeps increasing until it finally reaches 100% with the last card. We therefore know that the ‘6’ is guaranteed to be drawn when we go through the entire deck. The probability would also immediately drop to 0% as soon as the ‘6’ was drawn, as none of the remaining cards could still be the ‘6’. Not only is the ‘6’ guaranteed to be drawn, it is also guaranteed to happen exactly once. (Schreiber 2010)
These guarantees apply to every card, meaning the total result of drawing all the cards in the deck is predictable: E(total) = 1 + 2 + 3 + 4 + 5 + 6 = 21. This is relevant for balancing reasons: If a player draws a high card, they gain an advantage not only due to the card’s high value compared to the average, but also due to the fact that other players can no longer draw that value. An independent d6 would not have this effect. (Schreiber 2010)
The peculiarities of both forms of randomness can therefore have a strong impact on the game experience. Depending on the desired behavior of the game’s chance-based mechanics, the decision as to whether independent or dependent randomness should serve as a model is extremely important. For interdependent game events, such as our example with the three switches, dependent chance is well suited. For independent game events, like movement of playing pieces, most games use dice; i.e. independent chance. (Schreiber 2010)
Conditional Probabilities
The calculations for conditional probabilities use the same principles as those for independent chance: multiplying the probabilities of individual random events. However, because events are dependent on previous events, with their probabilities gradually changing, calculations must be performed step by step. (Schreiber 2010)
Let’s revisit our deck of six cards. We calculate the probability P(4) of drawing the ‘6’ with the fourth card. The events necessary for this are:
- The first card is not the ‘6’: p1 = 5/6
- The second card is not the ‘6’: p2 = 4/5
- The third card is not the ‘6’: p3 = 3/4
- The fourth card is the ‘6’: p4 = 1/3
Via multiplication, we can calculate P(4) = p1 * p2 * p3 * p4 = 1/6.
If we repeat this calculation for all P(1) to P(6), we see that P(x) is identical for all six values of x: 1/6. Again, we have a linear probability distribution of P(x) = 1/n, where n is the number of cards in the deck. This is just the math-y way of saying that the probability for a card to be in a particular position inside the deck is the same for all positions. For our board game, this means that the probability of a switch being the correct switch in a game is evenly distributed across all switches.
To simplify matters, the number of permutations is irrelevant in the case of dependent randomness, as the calculation is performed step by step. The order of the random events is determined by the multiplication chain of the respective events p(x), and k is always 1. On the flip side, this also means that dependent random events do not qualify as Bernoulli experiments, and cannot be simplified. Calculating longer chains of dependent random events can thus become extremely time-consuming. (Schreiber 2010)
Brain Teaser
Until now, the correct classification of a random experiment into independent or dependent chance was clear. It is surprisingly easy, however, to let errors in reasoning creep in, leading to incorrect probability values. (Schreiber 2010) The principle of negation is helpful in such cases; not only to reduce the computational effort needed, but also to understand complex stochastic questions with ease, allowing us to classify them correctly. (Schreiber 2010)
A good example of this is the sibling problem. The sibling problem asks the question of how high the probability is that two siblings are both girls if at least one of them is a girl (‘g’). An intuitive answer here would be P(g+g) = 1/2 . If one sibling is a girl, then the chance that the second sibling is also a girl should be 50%. However, a false conclusion has crept in here: Our human intuition places the second event ‘g’ into dependence on the first. But this dependency doesn’t exist anywhere in the question. (Schreiber 2010)
The negation of the question asks for the permutations that are eliminated by the restriction ‘at least one of them is a girl’. Of the possible combinations ‘b+b’, ‘g+b’, ‘b+g’ and ‘g+g’, only ‘b+b’ qualifies for elimination (‘b’ = boy). Three possible combinations remain, one is required. Therefore, P(g+g) = 1/3. (Schreiber 2010)
Conclusion
A certain degree of unpredictability is essential for games. Chance is one of three tools in the game designer’s toolbox with which he can lend his games this degree of unpredictability. (Adams and Dormans 2012)
However, in order to be able to create works of art using a tool – and game design is art (Schell 2016) – you need to be completely familiar with it. Even with simpler random generators, such as dice and cards, basic knowledge of stochastics and combinatorics is essential. Without mathematics, there is no safe handling of randomness; and the game designer is left without one of his most important tools.
Sources
- Adams, Ernest; Dormans, Joris (2012): Game Mechanics. Advanced Game Design.
- Flick, Jasper (2017): Anydice.com. Probability Calculator. Available online at http://anydice.com/.
- Freyermuth, Gundolf S. (2015): Games | Game Design | Game Studies. An introduction.
- PacManPlus (2005): Pac-Man ghost AI question. Ed. by atariage.com. Available online at http://atariage.com/forums/topic/68707-pac-man-ghost-ai-question/?hl=%20pacman%20%20dossier, last checked on 26.11.2017.
- Pittman, Jamey (2017): The Pac-Man Dossier. Available online at https://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php?print=1, last checked on 24.12.2017.
- Schäfer, Frederik (2012): http://www.poissonverteilung.de/binomialverteilung.html, last checked on 11.12.2017.
- Schell, Jesse (2016): The art of game design. Designing and developing better games.
- In collaboration with Maren Feilen. 2nd edition. Frechen: mitp (Safari Tech Books Online).
- Schreiber, Ian (2010): Game Balance Concepts. Level 4: Probability and Randomness. Available online at https://gamebalanceconcepts.wordpress.com/2010/07/28/level-4-probability-and-randomness.
- Sigman, Tyler (2006): Statistically Speaking, It’s Probably a Good Game, Part 1: Probability for Game Designers. Edited by Gamasutra. Available online at https://www.gamasutra.com/view/feature/130218/statistically_speaking_its_.php?page=3.
- StrategyWiki (2017): Ms. Pac-Man/Walkthrough, last updated 02/11/2017, last checked 12/24/2017.
- Bild von macrovector auf Freepik: https://de.freepik.com/vektoren-kostenlos/vintage-casino-elements-set_9586621.htm#fromView=search&page=1&position=47&uuid=df2446b9-efe0-4390-bf14-f94cc797e8c2