Statistically Speaking, It's Probably a Good Game, Part 1: Probability for Game Designers
Veteran designer Tyler Sigman contributes a witty, practical guide to probability for video game designers, from figuring out orc nostril hair drop rates (!) to the hilarities of 'converse probability'.
Quiz Time — Whoopee!
Q1) You are designing a new MMORPG, and you set a particular item — Orc Nostril Hair - to drop 10% of the time when a certain species of monster is killed. One of your testers reports back that he killed 20 of the monsters, and found the Orc Nostril Hair 4 times. Another tester killed 20 of the monsters and never found a single Orc Nostril Hair. Is there a programming bug?
Orc Nostril Hair Follicle
Image of Similar Hair Courtesy Wikipedia
Q2) You are designing a combat system for a game and have decided to include a critical hit mechanic. If the character lands a successful hit (say 75% base chance to hit), then you roll another hit check. If the second hit check is successful, the player will do double damage (2x). However, if this happens, you roll another hit check, and if that’s successful, then the damage is upgraded to triple damage (3x). As long as each hit check is successful, you keep making new checks, and the damage multiplier keeps increasing until a hit check is missed. What percentage of the time will the player get at least double damage (2x)? What percentage of the time will the player get quadruple damage (4x) or better?
Q3) You have decided to include a gambling mini-game in your latest magnum opus RTS-FPS-tamagotchi-sports hybrid game. The gambling mini-game will be very simple: the player can wager rubies on whether a coin flip will come up heads or tails. The player always receives even money on his winning bets. You will make the coin flip as fairly programmed as possible (50%/50%), but you will include an extra feature for the player: a list of the last 20 coin flip results will be shown on the right side of the screen. Should you beg the programmers to include any extra logic to prevent the player from taking advantage of this 20-flip history and using it to bankrupt your entire in-game economy?
We’ll attack the answers to these captivating questions at the end of this piece (if you’re still awake).
Game Designers - Renaissance People and Anti-Experts
Designerus Gamus
Being a designer in this day and age requires a pretty wide variety of skills. Designers are the generalists of the development team, needing to bridge the gap between Art and Engineering, competently communicating with each — or at least competently faking it. A good designer requires a basic understanding of a lot of different things, because game design is a haphazard amalgamation of subjects.
It’s pretty common to hear designers debating or waxing poetic on the finer points of linear or non-linear storytelling, human psychology, control ergonomics, or the integration of non-interactive sequences; less often do you catch them mulling over the bare bones details of the hard sciences like calculus, physics, or statistics. Sure, there are the Will Wrights, determined to find fun in celestial goo and the dynamics of city traffic planning. Most, though, wince when equations start breathing down their necks.
Probability + Statistics = Cool
Probability (P) and Statistics (S) are two hard sciences that are hugely important to game designers—or at least should be! They go together like peas and carrots, but like those yummy veggies, they aren’t the same thing. Coarsely put:
Probability: predicts the chance that an event will happen
Statistics: draws conclusions based upon events that have already happened
Taken together, P and S allow you to perform amazing parlor tricks: you can both predict the future and analyze the past! What power! Remember, though: “With great power comes great responsibility.”
P and S are simply tools in your Designer’s Toolbox (you know—the one under your desk). You can and should use them to your advantage to design games that are better balanced and ultimately more fun!
Good and Bad Things Come in Threes
There are lots of scary, thick textbooks out there about P and S, and this discussion isn’t meant to be a substitute for you going out, doing your due diligence and reading them. (Note: falling asleep with them on your chest *does not* count as learning.)
What this series of 3 articles *will* do is give you a basic understanding of some key topics from both P and S. Specifically, we’ll focus on things that designers should give a rat’s behind about.
Part 1 (You’re reading it, buster): Probability for Game Designers
Part 2: Statistics for Game Designers
Part 3: Shaping Game Mechanics with Probability and Statistics
Remember, being a well-rounded designer doesn’t mean you have to be an expert in these things; you just have to be able to fool anyone else who isn’t!
TIP: Increasing your usage of “theoretically”, “codify”, and “taxonomy” will most certainly impress your coworkers towards these ends. Other disciplines love it when designers use big words! You can thank me for this wisdom later.
The Ivory Tower in Which Designers Live
Ok, enough beating around the bush — on to the good stuff!
P R O B A B I L I T Y
Most games have one or more elements of probability incorporated into their base mechanics. Even chess requires the flipping of a coin to determine who takes white. Usually, we call probabilistic mechanics “random events”. Of course, the term random really might mean “completely random” or “sculpted random.” Regardless, whether you’re talking Texas Hold’em, World of WarcraftTM, or BombermanTM, random events are integrated into key game mechanics.
Probability: It’s not Just a Good Idea...It’s the Law!
You’ve probably heard the term “according to the laws of probability.” The key word in the phrase is “laws.” Probability is all about indisputable facts, not guesses. Ok, technically it’s all Probability Theory, but for the purposes of game design you can compute probabilities absolutely. When you roll a six-sided die, the chance of rolling a “6” is 1/6 = 16.7%—assuming a fair ‘throw’ and a perfectly manufactured die, of course. This 16.7% is not a guess, nor anything of the like. It is as good as fact*. Many of the most common thought errors that people make concerning probability have to do with the belief that probability is not based on laws, but rather on approximations or guidelines. Don’t fall into the traps! I’ll mention a few of the most common ones below, and try to draw some big DANGER! signs around them.
*I guess there might be quantum mechanical concerns that make the 16.7% not exactly fact. I mean, the die could suddenly warp out of existence or maybe your act of looking at it unfairly forces it to collapse its wave function (a severe inconvenience, to be sure).
Independent and Related Events
Let’s start our whirlwind tour of Probability’s Greatest Hits with a key distinction: whether events are independent or related. It’s vital to know before you can start calculating probabilities.
Independent Events: The chance of each event occurring does not depend in any way on what happened in the other event. For example, rolling a six-sided die (event #1) and then rolling it again (event #2) are independent events. The first and second rolls are not related in any way. The number you rolled in event #1 has absolutely zero influence on event #2 (see the “Fallacy of Equipartition”, later). Another example of independent events is drawing a card from a poker deck and then drawing a card from a second, totally different deck.
Related Events: the chance of each event happening is related in some way to the other event. For example, drawing a card from a poker deck (event #1) and then drawing a second card from the same deck (event #2). The chance of drawing a Jack on event #2 is affected by event #1—if you drew a Jack on event #1, then there’s a smaller chance of getting one in event #2 because there are less Jacks remaining in the deck.
Conditional Probability
One of the most useful bits of probability to know is how to calculate the chances of conditional events—that is, events that rely on other events occurring. For example, I used to play lots of old WarhammerTM tabletop games which are d6 based. According to the “to Hit” charts, if you had a somewhat unskilled warrior (with a low Weapon Skill) matched up with a superior enemy, you might have to roll a “6” followed by a “6” in order to hit. Just what is the chance of rolling a “6” followed by another “6”?
Well, first things first, you have to get the first “6” out of the way (a 1/6 chance). Then, you need to roll another “6” (a 1/6 chance again). Whenever one event depends on another’s success, you multiply the chances to get the cumulative chance of both occurring. In this case, it’s a 1/6 x 1/6 = 1/36 chance to roll a “6” followed by a “6”. (Note: If you have an irrational fear of rational numbers—har har—then you can always convert the fractions to decimals by using your calculator. In this case, 1/36 = .028 = 2.8%)
Armed with this newfound power of Conditional Probability, it’s very easy to calculate the chances of crazy dice throws. What are the chances that you can roll four “6”s in a row? The answer is 1/6 x 1/6 x 1/6 x 1/6. Or more simply, (1/6)4 = .0008 = .08%. How about ten “2”s in a row? (1/6)10 = AnIncrediblySmall%.
Incontrovertible Visual Proof that Four “6”s is Possible
Ratcheting up the difficulty, how about the chances of rolling a “3” or above followed by a “5” or above? It’s just 4/6 x 2/6 = 8/36 = 2/9 = 22.2%. Now we’re rockin’ the free world!
Superstition and the Fallacy of Equipartition — aka “The Gambler’s Fallacy”
One of the most common and widespread thought errors that people make concerning probability is blurring the line between independent and related events. This typically takes one of the following forms:
BAD THINKING AHEAD!
Mistake 1: Believing that a “5” is less likely than normal to appear again because the last dice roll was a “5”.
Mistake 2: Believing that a “6” has a very high chance of being thrown because 10 rolls have gone by without a “6” being thrown. Dressed in another outfit, this is believing that “red” is due on a roulette wheel because it has been several spins since the last “red” hit.
Mistake 3: After flipping a coin 10 times and getting 8 heads and 2 tails, believing that the next 10 flips will have more tails then heads in order to “even out.”
These all loosely fall under the appropriately well-named “Gambler’s Fallacy.” Basically, this is just the name for confusing independent and related events. Another name for this fallacy is “I just lost all my money at roulette because the Laws of Probability defied me Fallacy.” It is closely related to the lesser-known “Why do casinos allow me to keep a written log of the recent roulette spins — surely they know that I’ll be able to figure out the pattern and beat the wheel Fallacy?” (Note: that last fallacy typically is followed quickly by the previous one.)
Don’t fall into these traps! Rolling a die multiple times or spinning a roulette wheel are independent events, pure and simple. Let’s examine each of the above mistakes more closely:
Mistake 1: The chance of rolling a “5” on a d6 is 1/6 = 16.7% This never changes. It doesn’t matter if you’ve thrown eight “5”s in a row or haven’t seen a “5” since Gilligan’s Island premiered. 16.7% is still the magic number. “Dice don’t have memory” is a common phrase overheard...and it’s correct!
Mistake 2: Same as above. The chance of rolling a “6” or hitting “red” has absolutely nothing to do with the rolls or spins that came before. Roulette wheels don’t have memories either (unless they are actually magnetized and “Vinnie the Spinnie” is making sure that your number never comes up).
The most common argument that people make for mistakes 1 and 2 goes something along these lines:
GAMBLER’S FALLACY, scene 24b:
INT. HALLWAY — NIGHT
The moon shines in, bathing the office in silvery luminescence.
Game developers roam the halls like zombies, crunching for a
milestone. Or crunching human bones...
Mr. Faulty bumps into Probability Stuffshirt; both jolt out of
their zombie-like zombified zombie trances.
MR. FAULTY
(wryly)
Surely you agree that rolling
three “5”s in a row is unlikely.
PROBABILITY STUFFSHIRT
Yes. The chances are 1/6 x 1/6 x
1/6 = 1/216 = less than 0.5%, to
be exact.
MR. FAULTY
Well I’ve just rolled two “5”s in
a row, so my chance of rolling
another “5” right now is surely
very, very small! Less than
normal!
PROBABILITY STUFFSHIRT
Actually, your chances of rolling
another “5” right now are 1 in 6 =
16.7%.
MR. FAULTY
How can I have a 16.7% chance if
there is only a 0.5% chance of
rolling three 5’s in a row? I’ve
got you!
A well-dressed, distinguished looking NARRATOR emerges from a
small space behind the water cooler. He addresses the camera
directly.
NARRATOR
Mr. Faulty is making a patently
bad but sadly common argument.
Let’s hear why...
PROBABILITY STUFFSHIRT
Not so fast. You have already
rolled two “5”s in a row. The
chances of that were a mere 1/6 x
1/6 = 1/36 = less than 3%. You’ve
already done the hard part. Now
all you have to do is roll another
“5”, and you have a 1/6 chance to
do it. If you succeed, then that
completes the 1/6 x 1/6 x 1/6 =
1/216 = 0.5% Take that!
MR. FAULTY
(pointing wryly)
What could that be over there!
(escapes to cubicle)
The Law of Averages Got Vetoed
Mistake #3 (from back before Scene 24b) is a similar, but extended error: believing that over the long run, everything will “even out” — the Law of Averages. It’s true that, out of 1000 flips of a coin, you’d expect to see roughly 50% heads and 50% tails. But there is no such thing as a “correction.” If you flip a coin ten times and get 8 heads against 2 tails, there is no global essence or power that is going to squeeze a few more tails into the next 10 flips. You would be making a grave philosophical error to assume that “tails are due”, and an even graver error to put big money on it. Peter Webb has an excellent short discussion on this subject at his website (see recommended reading at the end of this article).
The gist is, if you flip a coin 1 million times, you’ll expect the heads and tails split to be close to 50%. But don’t expect the NUMBER of heads flips to equal the NUMBER of tails flips — in fact, it’s very likely that they will be off by hundreds or even thousands. Remember, you could have 10,000 less heads than tails and the division would still be very close to 50%/50% (49%/51%, to be exact). So don’t put money on assuming that an 8-to-2 heads lead (+6 heads) will be corrected as you flip more coins! It’s very likely that even if the heads/tails split will be close to 50%/50% in the long run, the actual difference between number of heads and number of tails will probably grow as the total number of flipped coins grows.
Converse Probability
It’s easy to find formulas that will help you calculate the chances of independent or related events. Sometimes, though, it can be very, very difficult to calculate more involved probabilities. One trick that you can pull out of your hat to save the day is the concept of “converse probability.” To calculate converse probability, instead of trying to determine the chances that something will happen, you instead calculate the chances that something won’t. Then, you subtract this number from 1.0 (100%) to get the probability that you are looking for.
Converse Prob 101: Easy Example
You are about to roll a six-sided die. What are the chances that you’ll roll a “6”? Although we already know the answer, we’ll use converse probability to verify it. The chances you won’t roll a “6” are 5/6 (5 out of 6 of the die sides are not a 6). Therefore, the chance of rolling a “6” is 1 – 5/6 = 1/6, or the familiar 16.7%. In other words, if you won’t roll a “6” 5 out of 6 times, then you will roll a “6” 1 out of 6 times. That almost makes sense!
Converse Prob 201: Flush with Excitement
Here’s a situation where converse probability really is a money saver. It’s Texas Hold’em, and you are four cards to a heart flush with two cards to come. In other words, if a heart comes on the Turn or the River, you’ll complete your flush**. What are the chances this will happen?
**Given the choice between the two, I recommend completing your flushes on the River — this has the greatest chance of psychologically destroying your opponents and sending them into apoplectic fits. Nobody likes getting Rivered.
It’s very easy to calculate the chances of a heart coming on the next card. There are 9 hearts remaining “in the deck” that have not been flipped up yet (13 to begin with minus the 4 already showing between the flop and your hand). There are 47 cards total in the deck (52 minus the two in your hand and the three flopped on the board). Therefore, the chances of flipping a heart on the next card are 9 out of 47, or 9/47. If that card isn’t a heart, then the chance of flipping a heart on the following card is 9/46 (there are still 9 hearts remaining, but one less card total in the deck).
Great, we’re off to the races! Only problem is, how can we easily calculate the total chance of flipping a heart, accounting for both cards? It would be easy to make the mistake of assuming that it would be 9/47 + 9/46. Not true, however. This is the same mistake that can lead you down the dark path of believing that the chance of rolling a “6” on a six throws of the dice is 1/6 + 1/6 + 1/6 + 1/6 + 1/6 + 1/6 = 1.0 = 100% = SureThingTM. Unfortunately, there is not a 100% chance of rolling a “6” on six throws of a die***.
Turns out that the solutions to both of these problems are made easier by using converse probability. We must ask “what are the chances we won’t draw a heart?” For the first card (the turn), the answer is (47 - 9)/47 = 38/47. For the second card (the river), the answer is (46 – 9)/46 = 37/46. From a study of conditional events (see earlier in this article), it’s easy to calculate the chances of BOTH of these events happening. In other words, we must calculate the chance that no hearts are drawn on either card. This is just the product of 38/47 x 37/46 = 65.0%. Since we are actually interested in the chances of making the flush, we just subtract this result from 1.0 to get it. 1.0 – .65 = .35 = 35% So there is a 35% chance of drawing the flush. Now do you go all-in?
***Note: the answer to the little dice problem is figured out the same way. The chance of rolling at least one “6” in six throws is found by looking at the chance of rolling no “6”s. On each throw, the chance of no “6”s is 5/6. Cumulatively, in order for no “6”s to come up in six throws, the chance is just the product of all six throws: 5/6 x 5/6 x 5/6 x 5/6 x 5/6 x 5/6 = .33 = 33%. So, the chance of at least one “6” coming up is 1.0 – .33 = .67 = 67%. Thus, you should see at least one “6” on six throws about 2/3 of the time. Now go use this to make money off somebody.
I didn’t mean to get all “mathy” above, and I was a little sneaky with my blitzkrieg treatment of Hold’em odds. The important thing to remember about converse probability is that sometimes it’s much easier to figure out the chance of something NOT happening than it is to figure out whether it WILL.
An Aside on Random Number Generators
Another thing all digital game designers should know about probability: random number generators are not random! Random number algorithms require a “seed number,” which is a base from which the algorithm can get all medieval on itself and do gyrations that ultimately result in a seemingly-random number. Most of the time, programs sample the CPU clock time or something similar to use as the seed number — this helps the algorithm be pretty darn random. But for high-intensity games with tons and tons of random number generations, sometimes that’s not random enough. Take for example online poker providers. Players (who often gamble for real money) need to know unconditionally that there are no underlying patterns to the random numbers that control card shuffling. In extreme cases like this where money is riding on the outcome, programmers must get super-fancy and start doing things like using CPU heat and entropy as seed numbers instead of clock times.
The take-home here is just that digital games don’t have truly random numbers. Most of the time, that’s fine, but if your game crunches insane amounts of numbers, then beware of patterns.
Quiz Show Redux
If you’ve read this far, then we’re both exhausted. Hopefully, though, we have also developed a nice golden-brown brain tan. So let’s revisit the questions from the beginning of this article.
Q1) Orc Nostril Hair Drop Rates
It’s too early to panic. Never panic unless you are sure you should panic. If you are sure you should panic, then panic, and panic well.
In this case, both testers’ results are certainly within the realm of probability. If there is a base 10% chance of finding the Orc Nostril Hair (ONH) on each monster-slaying, then the chances of finding at least 4 ONH in 20 tries is 13.3% Where did I get that number, you might ask? Well, I cheated and used an advanced concept called Binomial Distribution, but sadly (or happily?) it is beyond the scope of this article.
The chance of finding zero ONH at all through 20 tries is determined through converse probability:
10% chance of finding item on each kill means 90% chance of not finding it (0.90).
Chance of not finding it through 20 kills = (.90)^20 = 12.2%
So there is about the same chance of finding 4 ONH in 20 tries (13.3%) as there is finding zero ONH in 20 tries (12.2%). Not yet cause for justified panic.
To really determine if you should panic, you need more info. You need lots of data points from your testers in order to draw an informed, statistically-based conclusion (OK, I’m jumping ahead to part 2. Indulge me.)
Let’s say you collect info on 100 play sessions, each of which involve 100 kills. That’s a respectable amount of data. If out of those sessions, players are finding ONH a lot less or a lot more than 10% of the time, then you probably have a bug that is affecting your reward rates. In that case, panic with all haste! Tip: Sprinting around the office screaming “No!” generally gets quick results.
Q2) 2x-3x-4x+ Critical Hits
The chances of doing at least 2x damage are found by the conditional probability of hitting twice in a row:
Chance of 2x or better = 0.75 x 0.75 = 56.3%
Chance of 4x or better = (0.75)^4 = 31.6%
Wow. Players will do 4x or better damage almost 1/3 of the time. Fix your system, dude/dudette! Either drop the base hit percentage or make the successive critical levels harder to achieve.
Q3) Will Flip Coins for Money
This question is a silly trap, not-so-elaborately laid. First you give the player help by showing them the last 20 flips, then you need to shore-up your system to present exploits. Sheesh!
The answer, of course, is that providing the player with this 20-flip history changes nothing about the fact that each coin flip is a 50/50 proposition****. Let the player wreck himself with the Gambler’s Fallacy.
Heck, I even recommend paying out less than even money every time a player bets “heads” after 2 successive “tails” results. Just tell ‘em you are adjusting to their unfair advantage of knowing “heads” is due. They’ll believe you, they will...
****Natch, discounting any flaws in your random number generator that simulates the coin flip.
What are the Chances that this Article was Interesting?
I may be a gambling man, but I won’t dare to give odds on that.
If you survived the last few thousand words or even enjoyed them, stay tuned. In Part 2, we’ll explore the “Two-Drink Minimum” science of Statistics. And finally, in Part 3 (the riveting conclusion), we’ll look at the anatomy of a number system and explore how your choices as a game designer can sculpt a game’s mechanics into a true work of art. No, really!
Recommended Reading:
Peter Webb’s “Layman’s Guide to Probability”:
http://www.peterwebb.co.uk/probability.htm
The Wizard of Odds (lots of great gambling prob calcs):
http://www.wizardofodds.com
Brian Alspach’s Poker Computations:
http://www.math.sfu.ca/~alspach/computations.html
Read more about:
FeaturesAbout the Author
You May Also Like