## Sunday, April 5, 2009

### Ten Percent

Random is everywhere in WoW. Most spells have a range of damage. All weapons have a range of damage. Did you hit or miss? If you hit, was it a crit? Did your talents proc? How about your trinkets or weapon enchants? Maybe your embroidery?

In each action, a multitude of things can happen or not happen entirely randomly. When we talk about increasing DPS, increasing healing, or increasing survivability, we invariably talk about the midpoint, the average DPS something will grant. Moving from 20% crit to 26% crit is generally an increase of about 5% total damage (126/120). But if at the end of a fight you cast precisely 100 spells and 40 crit, how powerful was that increase to your crit chance? And what if only 15% crit?

So, this led me to a question. If we look at the *average* damage a player will do, what are the odds that he'll spontaneously do 10% more than normal? I'm going to be dealing only with crits here. Proc chances and things are beyond the scope of this project.

Lets normalize. We're casting 100 spells, each spell does 10 damage. A crit is 20 damage. At 30% crit, we're expecting 1300 total damage. This equates to 70 hits and 30 crits. A ten percent increase would be 1430 total damage, or 57 hits and 43 crits, or 43% crit chance.

The odds that we get 30 crits within 100 attacks is given by (CritChance^(NumCrits)) * ((1-CritChance)^(TotalAttacks-NumCrits)) * (Number of possible combinations of NumCrits and (TotalAttacks-NumCrits)) For example, given 2 coin flips of a fair coin, the odds of getting one head and one tails is .5^1 * .5^1 * 2 ([HT] or [TH] are both viable) which is .5 * .5 * 2 or .25 * 2 or .5, which makes sense, as there are four total options and two lead to the desired result. So, that math definitely works, and I feel better.

Crit Chance, Num Crits, and Total Attacks are all determined by our calculation. However, the number of possible combinations of crit/hit is harder to get at since we're dealing with reasonably large sample sizes (100). This is actually given to us by the formula [(Total Attacks)! / ([Num Crits]! * [Total Attacks - Num Crits]!)] or in our case 100! / (30! * 70!)

Thus, our whole formula is

(CritChance^(NumCrits)) * ((1-CritChance)^(TotalAttacks-NumCrits)) * ([TotalAttacks]! / [(NumCrits)! * (TotalAttacks - NumCrits)!])

In the case of 30/100 crits with a 30% crit chance, this is:

.3^30 * .7^70 * 100! / (30! * 70!) = 8.68%

And this tells us... What? Pretty much nothing. The odds of getting EXACTLY the right number of crits is relatively low. Hopefully you already knew this. But see, we're looking for something more. We want the chance of a range of values. For example, the chance of getting AT LEAST 10% more damage means the chance of getting 43 to 100 crits. Ultimately, we have to use summation. As in, we have to pick a total and a crit chance, then calculate it for each integer value. I don't like doing that by hand, so I wrote a small program to do it for me. I won't be reproducing intermediate steps, just end results.

43-100% crit, or 10% or higher improvement: .4% chance
0-17% crit, or 10% or higher drop: .2%

37-100% crit, or 5%+ up: 8% chance
0-23% crit, or 5%+ down: 7.5% chance

Hmm, with 100 casts, the odds of a 10% increase are almost nil and the odds of a 5% increase are pretty unreasonable. But nothing right now takes that long. For example, with a 2 second cast spell, killing Patchwerk in 2:30, we're looking at 75 casts. And the burst phases of most fights are much shorter, for example the Tenebron phase of +3 should be lasting less than 45 seconds or MAYBE 30 casts. So lets say 40% crit, 30 casts. Midpoint should be 12, 16 is roughly a 10% increase.

30 casts, 40% crit
16-30 crits: 9.7% chance
0-8 crits: 9.4% chance

5% variance:
14-30 crits: 28% chance
0-10 crits: 29% chance.

Interesting. Even on a short fight with a high crit chance, the odds that you'll crit significantly more than you should is pretty low; a 10% increase is definitely possible for an individual, but you'll almost never see the whole raid get even a 5% DPS increase.

I'm quite surprised, I was expecting to see crit give a much higher variance. This is actually pretty cool, since it means that a bad group will almost never get lucky and do a ton of DPS, and a good group will almost never have terrible luck and lose a ton of DPS. Which means if you're seeing variance in your raid's DPS, you should probably look at external factors, like void zones spawning three deep around your mobs.

Edit: Source for the program is here-
http://www.saichotictech.net/WoW/Binomials.lua

1. A bit more rigorously, the probability of getting p crits is given by a standard binomial distribution, with mean n*p, and variance n*p*(1-p). For our 100 attacks with 30% crit, the mean is 30 crits, and the variance is 21. This means the standard deviation is sqrt(21)~~4.6.

Another, less accurate, but requiring less computation is to estimate the binomial distribution with a normal distribution. Specifically, P(43 crits or more) ~~ P(Y >= 43.5), where Y is a normal variable with mean = n*p = 30 and variance = n*p*(1-p) = 21. The normalized variable is z = (43.5 - 30) / sqrt(21) = 2.95. From a basic table, P(z>2.95) = .016, or .16%. Inaccurate, but pretty close. It works better for larger n, when the summation breaks down.

In general, this is a useful approximation for any binomial distribution. Two things to remember:
1) always correct the random variable by +.5, otherwise the results are very inaccurate.
2) ensure that n is sufficiently large, a useful rule of thumb is to ensure that both n*p and n*(1-p) are greater than 5.

This just backs up the math up there, but more math==more awesome!

2. Ahhhh that looks familiar. I KNEW we'd done something exactly like this in AP Stats senior year, but I couldn't remember quite how and googling wasn't helping :P

Writing the summation program was fun though, since factorial overflows integers ridiculously fast. Thank god for Lua.

3. Wikipedia is a tool of the gods themselves! Seriously, if you know the terms, you can find everything about anything.

4. How does this have anything to do with Balance in WoW? Why did I waste my time coming to this craptastic blog?

You do realize that no one gives a shit about all the math that goes behind programing the games mechanics. No one thinks your smart because you added it up and posted it on a website.

If anyone really cared about it, they would be impressed by the software and code designers.

PS: Your website sucks. Now I see why it's empty lol