Showing posts with label probability. Show all posts
Showing posts with label probability. Show all posts

Monday, February 2, 2015

Pandemic: The Cure - standard deviation and probability

Initial setup
Recently we have been playing Pandemic: The Cure. The goal of the game is (loosely) to cure all the diseases. Each player has a certain number of dice that they roll on their turn (5 for most players, 7 if you're the Generalist) that give them their possible actions for the turn. One of the actions lets you use one of your die to "bottle up" a disease die and at the end of your turn you roll your bottled up disease dice and if the total amount rolled on the dice for a particular color of disease is greater than 13, then you have cured that disease.

Bottling up the diseases is great because it removes that disease die from play and helps you discover the cure, but until you discover the cure that die of yours you used to "bottle" it up is locked up and you can't use it, meaning you'll have fewer possible actions on your turn, making you less effective until the cure is discovered.

Disease Dice
Each color of disease die has different face values from the other colors'. Each one has a "Cross" face (value 0) and 5 other values. The average value of the faces on each die is 3 but since the values are different the standard deviations of the values on the dice are different. The values on the faces of the dice are as follows.

ValueBlackYellowBlueRed
1st0000
2nd3211
3rd3221
4th3434
5th4566
6th5566
Avg3333
Std Dev1.6722.532.68

So in terms of trying to cure the diseases, the likelihood that the total of the values across all the dice you roll of a color will meet the required sum is different. Below is a table of probabilities of curing the disease with various numbers of a color of dice. The amount needed to cure a disease is normally 13, but sometimes can be 11.

BlackYellowBlueRed
# Dice11+13+11+P13+11+13+11+13+
20.00%0.00%0.00%0.00%11.11%0.00%11.11%0.00%
332.87%7.41%34.72%12.04%34.26%20.37%40.28%23.15%
470.14%46.91%67.67%45.76%60.88%45.06%62.73%45.76%
589.51%77.22%86.52%73.53%79.90%67.30%78.29%67.36%
696.81%91.85%95.03%88.94%90.71%82.81%88.70%82.04%
799.12%97.42%98.33%95.86%96.05%91.82%94.62%90.59%

You'll see that for certain numbers of dice and goal numbers to reach, the probability of curing the disease can be quite different. For example, with 3 dice and a goal of 13 the probabilities range from 7.41% to 23.15%. Most differences are <10%, but that can be a fairly significant difference.

You'll see that no die is universally easier or harder to find cures with. Getting 13+ is only really possible once you have 4 dice. A goal of 11 isn't very likely until you have at least 3 dice, and even then the odds are very bad. It's very hard for a single character other than maybe the generalist to amass 4 or more dice by themselves. After you have 3 dice bottled up you only have two dice left. So getting the 1 in 6 result of being able to bottle up on your dice when you only have two dice is fairly unlikely. The game allows you to trade your bottled up dice to another player if you're on the same square. This probability table tells me that that's a very important part of the game.

Advanced discussion:
In the above two tables, I ordered the dice colors by their standard deviations, lower on the left and higher on the right. One thing you might notice is that for 3 dice, the higher variance dice (aka higher standard deviation) have a higher probability of success. You'll notice that for higher numbers of dice, the colors with a lower standard deviation tend to have a higher chance of success.

When you have 3 dice, the average value of the sum is 9 (because the average for any given die is 3). Nine is insufficient for either goal so results near the average are bad. So you want a result that's far from the average, meaning you want a higher standard deviation. When you're at 5+ dice, the average result, 15, is above the goal so lower standard deviations are better.

When average is bad and you want that extreme result, you'll do better with a higher standard deviation. When the average is good and you don't need an extreme result, you'll do better with a lower standard deviation.

Player Dice, showing all faces
Epidemic Roll Change
Another place where probability plays a big role (roll?) is with epidemics. Each character die has one face which, when rolled, will advance the epidemic track. The generalist, with their seven dice instead of the normal 5, stands a much greater chance of rolling these values on their turn. To balance this, the generalist is allowed to ignore the effect of the first epidemic they roll each turn. This has a huge effect, and it makes the generalist have an overall lower change of advancing the epidemic track than other characters. Below is a table of probabilities for how far each character will advance the epidemic track on their initial roll of dice (with full dice i.e. no dice locked up from bottling up diseases).

AdvancementNormalGeneralist
040.19%66.98%
140.19%23.44%
216.08%7.81%
33.22%1.56%
40.32%0.19%
50.01%0.01%
6NA0.0004%
Avg0.830.45

The other advantage of being the generalist is that when you have no epidemics on your initial roll (28% of the time w/ 7 dice, higher w/ fewer) you can freely reroll dice to try and get a better result w/ no fear of the consequences of rolling an epidemic.

Thursday, July 26, 2012

Risk Battle Statistics and Simulator

Number of Attackers: Offensive Airfield
Number of Defenders: Defensive Airfield

Offense Rolls:
Defense Rolls:
Offense Wins:
Defense Wins:
Cumulative Offense Wins: 0
Cumulative Defense Wins: 0
Offensive Kill-Death Ratio: NA


I was trying to find an image to put above and then I had the bright idea to code the above simulator. After an embarrassingly long amount of time due to my Javascript inexperience, it is done. An explanation of how battle works in Risk is at the bottom following the *

A long time ago I wrote a post that contained some probability calculations associated with the popular board game Risk. This was long before I knew how to format things nicely on the internet and before I was aware of some other things. That said, I think that I can approach the content and its presentation much better now than I could then so I've redone the post.

The original post was focused on showing that you should always choose to attack and defend with as many units as you can, that the odds work out best for you that way. This means that the offense should always attack with 3 if possible and the defense should always defend with 2.

It turns out that the latest version of the Risk rules (which are the rules used in Risk: Factions, a downloadable title for the PS3 and XBox 360) can have situations which modify your battles. Fulfilling certain objectives can allow a player to attack with up to 4 soldiers or defend with up to 3. Furthermore, the player can obtain an airport which bestow a +1 bonus to that player's highest die roll when attacking or defending for any battle that takes place on or adjacent to the territory which has the airport.

I decided that I wanted to see how these variables affect the probabilities of success and the kill-death ratio for the offense. To quickly explain the data in the chart:
  • Most entries fall under "X Kills" which is the probability that under those circumstance the offense will kill X of the defender's pieces. Remember that if the offense doesn't kill a defender's piece then the defender kills a piece belonging to the offense.
  • KDR stands for Kill-to-Death Ratio and is how many pieces the offense should expect to kill for every piece they expect to lose. For example, in the 3 vs 2 matchup with an airport for the offense, the offense should expect to kill almost 2 of the defender's pieces for each piece they lose. A KDR>1 is good for the offense. A KDR<1 is good for the defense.

Probability of offense winning X rolls and KDR
3 vs 2
2 Kills1 Kill0 KillsKDR
Normal37%34%29%1.17
Off +151%31%18%1.97
Def +124%41%35%0.80
3 vs 3
3 Kills2 Kills1 Kill0 KillsKDR
Normal14%21%26%38%0.58
Off +120%25%31%24%0.88
Def +18%21%27%45%0.44
4 vs 2
2 Kills1 Kill0 KillsKDR
Normal46%33%21%1.67
Off +163%25%12%3.11
Def +130%45%25%1.09
4 vs 3
3 Kills2 Kills1 Kill0 KillsKDR
Normal25%26%25%24%1.03
Off +137%25%24%14%1.61
Def +114%31%27%28%0.78

There's nothing surprising here, but it is very interesting to see how much of an advantage the offense has in the normal situation and how much that advantage changes depending on various conditions. There is another advantage that the offense has that isn't discussed here. The offense gets to choose when and where they attack, which allows the to pick battles that they are fairly certain they can win. Play wisely, everyone.

*In classic Risk the objective is to conquer all the territory on the map. You do this by engaging your enemies in battle. To do this you select up to three units on a territory you control to attack an adjacent territory. The owner of that territory can defend with up to two units (these numbers can be increased under certain conditions)

Each player rolls a die for each unit they are attack/defending with and sorts them from highest to lowest. The compare matching dice and if the offense's roll is higher than the defense's the defense loses a piece. If the defense's is higher or there is a tie, then the offense loses a piece. This repeats until the defender loses all their pieces on the territory or the offense gives up.

Example: The offense attacks with 3 pieces and the defense defends with 2. Their rolls are
  • Offense: 4 6 2
  • Defense: 5 4
Sorted, the offense has 6, 4 and 2 and the defense has 5 and 4. The offense's 6 beats the defense's matching 5 but the defense's 4 beats the offense's matching 4 since the defense wins ties. Both sides lose a piece. The 2 is ignored.

Tuesday, March 20, 2012

Mists of Pandaria's New Loot Systems Analyzed.


Because Community is back on the air and we're talking about random things. I present a relatively random song. Seeing this fan video, one of Community's earliest, let Dan Harmon know that the show had "made it" to a certain degree.

I've talked before about how no voting system is perfect. It seems perhaps that no loot system is perfect either. Blizzard has announce that a new loot system will be used in Mists of Pandaria for LFR and the two world bosses where instead of rolling for specific pieces, the game will randomly pick people to get loot. If the game picks your player, it will pick an item appropriate for your class/spec. They haven't decided if every player has an X% chance to get loot or each the game will randomly choose X people to get loot.

Later in the thread, Zarhym went on to note that the X% chance to drop version of the system is flawed because the number of items a boss will drop will then become random, which could lead to abnormally high numbers of drops or even zero drops on a boss.

The game will roll for you, and it won't say what you rolled. You also don't have the option to pass. If you win loot it will be randomly picked from the items appropriate for your class. So you may get something you already have or something that isn't an upgrade. Furthermore, you won't be able to trade loot obtained by this system.

The advantage of this system is that it removes other people from affecting your chance at loot. Nobody can take your loot from you, it's all up to Lady Luck. With the current LFR loot system, some people roll on everything that they are eligible to roll for and then hold the item hostage to trade for something that they need. This is a dick move.

On the other hand, people can't pass on loot via this system, so loot can go to someone who doesn't need any when there are plenty of other people who might need it. People who might even need that specific piece. This does bring concern about loot waste and making it harder to gear. While that is a concern, keep in mind that only gear that is appropriate to people in the raid will drop. So gone will be the days when spell plate drops and you have no Holy paladin.

Another concern is that this will prevent you from obtaining off-spec pieces. I have a personal address to that concern. If you want off-spec gear, then run as your off-spec. My understanding of LFR is that it's quite easy. This loot system won't be used for normal or heroic raids. In a 25-man LFR raid, there will likely be a person for every type of gear that can drop, with the possible exception of spell plate. So if you're taking an off-spec piece, you're likely taking away from someone's main spec. If you're running a premade LFR or an LFR with a large number of friends, then you're likely to be organized enough that you can afford to run on your off-spec.

This new loot system will affect boss loot tables. In order for this system to work, it will require that all bosses in LFR will have to have at least one item that appeals to every specialization. Between armor, jewelry and weapons this shouldn't be hard. However, it is comforting to have that assurance.

Furthermore, there is talk of a system where out-of-raid actions can give you a charm that will allow you an extra roll for loot on any raid boss, regardless of difficulty. This roll also doesn't impact other players, but gives you an extra chance. Furthermore, if it fails to give you boss loot, it will give you something like gold or consumables. When the boss dies, a prompt will ask something along the lines of, "Would you like to use your charm?"

This system too, seems to bear the consequence that all bosses, even in the world of normal and heroic where loot is typically not shared across bosses, must have something that can appeal to everybody. The alternative is that the charm loot would have to come from some sort of shared loot table, which would make it not unique to the boss, which would somewhat defeat the point.

I was all ready to go into this post to tear down and examine the problems with these new loot systems. However, as I started writing it and reread some things to make sure I didn't misstate anything, I realized that not only did I like it (which I already did), but I think it's brilliant. I feel this is a great system and will be a fantastic upgrade to the preexisting LFR loot system.

I'd like to do an investigation into the loot distribution that happens with this new system and how much loot does get wasted in using this new system versus the old system. I'll have to run some simulations to get it done, but I think it will prove to be very interesting.

Tuesday, March 13, 2012

Night School: The Math of Drop Rates

Hopefully that chestpiece is in this pile somewhere...
Drop rates are where most people will encounter and be aware of randomness in World of Warcraft. The other places would be in crits and random procs, of course. There can also be quite a bit of misunderstanding about how they work. Everybody knows the basics, of course: when the boss dies, the game rolls some random numbers and finds those numbers in the loot table to see what the boss should drop. Different items have different drop rates, which come from that item occupying a larger or smaller section of the loot table, making it more or less likely to drop. Other things, like tier tokens and legendary weapon fragments are often rolled for on separate tables from the normal loot.

For the duration of this post, I talk about drop rates with the percents, but all the math with be done with the decimal. So, 10% is 0.10, 5% is 0.05, and 100% is 1. Percents (Latin for "per 100") are a great way to talk about these things, but you cannot do the actual math with them, one must convert them to decimals.

How long until this item will drop?
That's the big question, isn't it. When will my shield drop? Why can't I get a shoulder token? Where is that stupid phoenix mount? Let's just assume that you're the only person contending for a particular item, and that when it drops it will go to you. Will you indulge me by allowing me a table? Who am I kidding? I'm putting a table here whether you like it or not.

Minimum Kills for X% of people?
Drop rate
% of players50%10%1%
50%2769
10%422230
1%744459

An entry from this chart should read as, "With a drop rate of 10%, 50% of players will have to kill the boss 7 or more tries."

So how do you like those numbers? That mount that has a 1% drop rate? There's a ~50% chance it will take you 68 or fewer tries. There's also a 10% chance it will take you 230 or more tries. You might notice that the numbers for 1% of players is roughly double that for the 10% of players. This is because 1% is 10% of 10%. But where does all this come from?

Suppose the probability that an item will drop is p, and the probability that it won't drop would then be 1-p. If you want to know the probability that something will drop after you've killed the boss x times, that's actually difficult to directly calculate, because it could drop multiple times. When calculating probabilities, you'll very often run into situations where the thing you want to know is hard to calculate directly, but the opposite of it (in this case, the probability that the item won't drop in x kills) is very easy to calculate. In that case you calculate the probability that it won't happen and then subtract the result from 1.

In our question, calculating the probability that something won't drop is easy. You simply take the probability that it won't drop from a single kill, 1-p, and raise it to the power of the number of kills, x. You multiply because these are independent events, meaning that the outcome of one event (a kill) does not affect the outcome of the other events. This makes the probability that the item won't drop is*
and the probability that it will drop at least once is
One thing that could be noticed from playing around with that equation is that, for any positive value of x,  unless p=0 or 1, the formula will never equal 0 or 1. In other words, the only times when there is absolute certainty is when the drop isn't random, or you haven't killed the boss yet. Here is a chart that depicts the probability that an item will have dropped based on how many kills have been attempted. Here, the probability of a drop is 10%.

Wolfram Alpha is a great source for doing math.** 
You'll notice that even at the number of kills get's very large, the probability that the item will have dropped never actually hits 1. So no matter how many times you kill, there's no guarantee that the item will drop.

There is an article written by Brian Wood on WoWInsider that contains a wonderful calculator for drop rate percentages such as this. I highly recommend that you check it out here.

Corollary: Average Number of Drops
Of course, the previous section is based on an assumption that you'll only want one of an item, and that it will only drop from one boss/monster. Say you are farming something that has a <100% chance of dropping from whatever you're killing. Let's say it's Relics of Ulduar. It has an 11% percent chance of dropping off of Mildred the Cruel If you want to know the average number that you should expect to get after so many kills, you just multiply the probability of it dropping by the number of kills. If you were to kill Mildred 26 times, then you should expect to have an average of .11*26=2.86 Relics of Ulduar.

The mousover text for those equations contains the LaTeX code used to produce them at the Online LaTeX Equation Editor. Note: "\left(" and "\right)" weren't actually necessary for those, I could have just used "(" and ")" but it's considered a best practice to use the longer ones because they scale in size with their contents. Consider the example below:


**I used Wolfram Alpha to produce the graph up above. It's an amazing thing. Like if Google could do your homework. It can factor polynomials, give population statistics, and even do calculus. I used the free trial of the pro service to get the graph above. The whole thing blows my damn mind.

Friday, September 10, 2010

Some stats on stats.


A recent conversation with a friend has got me obsessing about playing D&D again. However, since I don't have any sourcebooks (because of the fire at my parent's house a couple years back), I am very sadface. Out of this recent obsession, I've decided to do some math. And by math, I mean some programming.

Whenever you create a D&D character, you use die rolls to determine your characters stats. I was curious about how the stats are distributed and the probability of obtaining particular results. To investigate this, I wrote two programs, one iterated through all of the possible rolls for 4 die, dropped the lowest, and found the stat total. This let me figure out the mean, mode, and quartiles for the distribution of the stats.. In short, out of all the possible rolls, the number of outcomes for each number is as follows: