Friday, July 9, 2010

Recursion is fun

In preparation for the onset of WHFB 8th Ed.'s magically exploding heads and at the request of YodasLuck, I evaluated the probability of double or more 1s or 6s relative to the number of dice being thrown. Math below the cut, and I leave the implications of the probabilities as an exercise to the reader.

2 dice: 2/36 (6%)
3 dice: 32/216 (15%)
4 dice: 342/1296 (26%)

And on a related topic, I've simulated what the difference between 2d6 would be to get an idea of the distribution of power dice versus dispel dice, assuming no army bonuses to either:
0: ~16.5%
1: ~28%
2: ~22%
3: ~17%
4: ~11%
5: ~5.5%

13 Jul Edit: Updated the mathematics to be far less complicated (less fun, but much more readable), and added other sim results
22 Jul Edit: Added power dice sim results to bottom of post

The simple case of two dice: 1/36 chance for snake eyes + 1/36 chance of boxcars = 2/36.

For the slightly more complicated case of three dice, consider that the probability of rolling double ones or sixes (henceforth DOOS) is simply the twice the probability of rolling a generic double. Label each die discretely: A, B and C. Then evaluate the probabilities on a case-by-case basis for die A, say for rolling double 1s:
1) 5/6 chance of A not being 1, therefore rolling double 1s requires B and C are 1s, or 1/36 -> 5/216.
2) 1/6 chance of A being 1, therefore DOOS requires B or C being 1 (the same as 1 - the probability of not rolling a 1: 1 - (5/6)² = 11/36) -> 11/216.

The probability of double 1s is thus 16/216, and rolling DOOS is 32/216. This concurs with the results from the dice-rolling Python script I whipped up below.

Calculating the probability for four dice is a similar process:
1) 5/6 chance of A not being a 1, and thus the remaining three dice must be double 1s (result from above: 16/216) -> 80/216.
2) 1/6 chance of A being a 1, therefore snake eyes requires any of the remaining dice be 1 (1 - (5/6)³ = 91/216).

Double 1s total: 171/216, or 342/1296 (26%) for DOOS. Also in agreement with the simulation.

More generally:
P_x(n) - probability that x will be rolled on any of n dice. Is equivalent to 1 - (5/6)^n.
P_xx(n) - probability that double xs will be rolled on any of n dice. Is generally equivalent to 5/6*P_xx(n-1) + 1/6*P_x(n-1).

For n+1 dice, P_DOOS(n+1) can be considered:
1) 2(5/6 * P_11(n))
2) 2(1/6 * P_1(n)).

Python script: dicer.py (written under Python 2.4). Note that the numCheck function only evaluates the probability of a single doubles (or more) value at a time, so any results should be doubled to evaluate DOOS.

Power dice vs dispel dice sim results:
Power Dice:
2: 2.7%
3: 5.6%
4: 8.5%
5: 11.1%
6: 14.0%
7: 16.5%
8: 13.7%
9: 11.1%
10: 8.4%
11: 5.5%
12: 2.8%

Dispel Dice:
1: 2.7%
2: 8.3%
3: 14.1%
4: 19.3%
5: 24.9%
6: 30.6%

No comments:

Post a Comment