## Sunday, December 11, 2016

### The Arch-Mage Casts a Fireball

Fireball damage: its calculation and its distribution.

This is what the game is about. I cast the spell:

Look at all the damage! But how much damage, exactly? My enthusiasm is tempered by the prospect of adding up the pips.

Fortunately, as a wizard I am familiar with the arcane rule of tens. Prestidigitation ensues and the hidden number is revealed:

Apropos of nothing, I timed myself on a few more rolls:
• 65 hit points: 22.2s
• 63 hit points: 19.6s
• 56 hit points: 28.3s
• 63 hit points: 28.3s
• 62 hit points: 24.9s
An average of 24.7s spent to get a number that was usually within a couple hit points of 63.

## A Shortcut?

When younger I was tempted to roll a single d6, multiply it by 18, and be done with it. That is, use a d6 × 18 roll in place of the 18d6. However, even then I couldn't escape the feeling that this was not an equivalent roll. I could see that the latter method always produces a multiple of 18, but I wondered if it wasn't close enough all the same.

Both methods cause 63 hit points of damage on average, so in that respect they are the same. But if the mean is all we care about, why roll dice at all?

Plotting the probability mass distributions is a good way to show how different rolls are. Here the 18d6 distribution is in red and the d6 × 18 distribution is in blue:
The standard deviations are 7.2 and 30.7, a large difference.

## Chebyshev's Inequality

At this point, I'm going digress in an attempt to make the standard deviation seem useful.

According to Chebyshev's inequality, the chance of being more than k standard deviations from the mean can never be greater than 1/k2. Thus, in the case of the 18d6 distribution, the chance the value is less than 49 or more than 77 is no more than 25%. The same probability for the d6 × 18 distribution is 66⅔%.

Chebyshev's inequality is a rough upper bound that works for any distribution for which we know the mean and standard deviation. If we know the distribution, we can do a summation or integration to get the exact probability; for the 18d6 distribution the exact probability is less than 5%.

## A Better Shortcut?

Back to rolling fireball damage.

What if we allow two rolls of a d6? I wrote some code which searches for an expression with the same mean and the nearest standard deviation. To keep things simple the first d6 always gets multiplied by a non-negative integer and the second d6 is taken as is. With those constraints here are the best approximations:
``````
``````
``````   1d6: d6 × 0 + d6 +  0
2d6: d6 × 1 + d6 +  0
3d6: d6 × 0 + d6 +  7
4d6: d6 × 1 + d6 +  7
5d6: d6 × 2 + d6 +  7
6d6: d6 × 1 + d6 + 14
7d6: d6 × 2 + d6 + 14
8d6: d6 × 3 + d6 + 14
9d6: d6 × 2 + d6 + 21
10d6: d6 × 3 + d6 + 21
11d6: d6 × 2 + d6 + 28
12d6: d6 × 3 + d6 + 28
13d6: d6 × 4 + d6 + 28
14d6: d6 × 3 + d6 + 35
15d6: d6 × 4 + d6 + 35
16d6: d6 × 3 + d6 + 42
17d6: d6 × 4 + d6 + 42
18d6: d6 × 3 + d6 + 49
19d6: d6 × 4 + d6 + 49
20d6: d6 × 5 + d6 + 49
21d6: d6 × 4 + d6 + 56
22d6: d6 × 5 + d6 + 56
23d6: d6 × 4 + d6 + 63
24d6: d6 × 5 + d6 + 63``````

Here is how well the approximation works for the arch-mage; the 18d6 distribution is in red and the d6×3 + d6 + 49 in blue: