View Full Version : Roll & Keep probabilities for six-sided dice

The Troubadour

2016-12-19, 11:25 PM

Hey there, everyone! I need the help of the more mathematically inclined folks, please. Basically, I need help calculating the average of 2d6 to 8d6 rolls, only following these rules:

1) I can only keep the two highest dice per roll (for instance, if I rolled 4d6 and got 1, 3, 2 and 5, I would only keep the 3 and the 5);

2) any die that reads 6 "explodes" - that is, I can roll it again and add the new result to the previous one (for instance, if I rolled 3d6 and got 6, 5 and 5, then re-rolled the 6 and got a 3, my final result would be 9, 5 and 5, and I'd keep both the 9 and one of the 5).

Basically, it's the same as the Roll-and-Keep system used by classic "Legend of the Five Rings" and 1st Edition "Seventh Sea", only using d6es instead of d10s.

Many thanks in advance!

Knaight

2016-12-20, 12:45 AM

Mathematics schmathematics. This is what anydice is for. Specifically, here's some code:

output [highest 2 of 2d([explode 1d6])]

output [highest 2 of 3d([explode 1d6])]

output [highest 2 of 4d([explode 1d6])]

output [highest 2 of 5d([explode 1d6])]

output [highest 2 of 6d([explode 1d6])]

output [highest 2 of 7d([explode 1d6])]

output [highest 2 of 8d([explode 1d6])]

This appears to only model dice that explode 0, 1, or 2 times, but past that the odds are pretty negligible (3+ explosions on a die is a 1/216 event). There is a way to move that variable up, I just don't know it off the top of my head.

Mastikator

2016-12-20, 03:11 AM

Do all the dice "explode" if ONE of the rolls a 6 or just the one that rolled a 6? If just one then the odds of a d6 exploding is 1/6, each time it does it adds 3.5 to the value, so on average it increases the dice value by 3.5/6. Or 0.58333...

It just increases the average number from 3.5 to 4 on a d6.

Knaight

2016-12-20, 03:20 AM

Do all the dice "explode" if ONE of the rolls a 6 or just the one that rolled a 6? If just one then the odds of a d6 exploding is 1/6, each time it does it adds 3.5 to the value, so on average it increases the dice value by 3.5/6. Or 0.58333...

It just increases the average number from 3.5 to 4 on a d6.

Not quite. There are multiple explosions, and while you can truncate the series and lose relatively little accuracy (this is how to do it numerically, and it's how anydice does it) a proper technique would be an infinite sum. The number of times one gets to roll is 1 (the first roll) + (1/6)/(5/6), so 1.2 dice on average. The average thus moves from 3.5 to 4.2 per die.

However, with a roll and keep system averages on a per die basis don't really get you that far, hence the code upthread.

jayem

2016-12-20, 03:55 AM

Before rerolling the probability distribution for one dice is simple in a frustrating way.

P(1)=1/6

P(2)=1/6

P(3)=1/6

P(4)=1/6

P(5)=1/6

P(6)=0 !

P(7)=1/36

P(11)=P(10)=P(9)=P(8)=P(7)

P(12)=0

And this step pattern continues,

Which is going to be 'interesting' to join.

We had a thread without the exploding but with rerolls which had a nice triangular rule as to the odds. But would have to think how that works here,

The Troubadour

2016-12-20, 10:03 AM

Mathematics schmathematics. This is what anydice is for. Specifically, here's some code:[...]

Thanks! Do you have any idea what's the code if I wanted to add another rule, that the first "1" on any d6 is automatically re-rolled?

jayem

2016-12-20, 06:02 PM

For the highest dice, things combine fairly nicely (with the exploding dice being more burny than exploding).

You can find the cumulative prob distribution for a single die

Pc(n)=n/6 for n<6

=5/6 for n=6

=5/6+n/36 for n=7-11

=1-1/36 for n=12

=1-1/(6^n/6)+(n%6)/(6^((n+6)/6)) (I think, with / being integer division, ^ power, % remainder when divided by)

Which is a pain to do anything analytic with, but at least means you can work out any number.

While to find the probability that the highest die of d dice is n (for any probability distribution).

P(n,d)=Pc(n)^d - Pc(n-1)^d I.E probability that all the dice are below n, minus the probability that all dice are below n-1, gives the probability that AT LEAST 1 dice has exactly n.

N.B this gives the nice result from the previous thread for boring dice throws.

So for any particular number, you could find out the probability, by doing a limited number of calculations. E.G I make that the chance of the highest of 10 exploding die being 40 is about 1/27000.

I did try working it out for the highest 2 numbers. But I think something goes funny because of the cases where the two highest dice are the same. Though you could probably do low numbers knowing it's a flat distribution (until a dice explodes) so things can be canceled out, and then for high numbers rely on collisions being rare when die do explode.

But monte carlo has it's virtues, (or computer based exhaustive case by case).

meschlum

2016-12-21, 12:48 AM

Numbers to crunch! Hurrah!

An exploding N sided die has a simple trick you can use to get the average: either you roll less than the explosion number, or you get an exploding die PLUS the explosion number.

So if the exploding die has an average of X, and explosions happen with rolls of N on the die, this means you get:

X = (1 + 2 + ... + (N - 1)) / N + (N + X) / N

Since you either have a number between 1 and N - 1 (happens (N - 1) / N) of the time), or 1/N of the time, you have N plus an exploding die.

The above simplifies to (N - 1) X = N (N + 1) / 2, or:

X = N / 2 + N / (N - 1)

So an exploding six sided die has an average of 3 + 1.2 = 4.2, as stated previously (a 20% increase). A non-exploding six sided die has an average of 3.5, so it's not much of a boost.

When you reroll the initial 1, the above logic becomes helpful:

1/6 of the time, you roll a 1 and get an exploding die instead, average of 4.2

4/6 of the time, you roll 2-5 and get that much

1/6 of the time, you roll a 6 and get an exploding die added, average of 6 + 4.2

So in all, you have:

4.2 / 6 + (2 + 3 + 4 + 5) / 6 + (6 + 4.2) / 6 = 0.7 + 2.33 + (1 + 0.7) = 4.733

Which means that an exploding d6 where you reroll if you got a 1 the first time you rolled (but not if you roll an explosion and then a 1) gives you an average of 4.733, a small increase over an exploding die (a bit over 10%)

When you reroll the first time you get a 1, even during an explosion, things become more complicated because you need to keep track of your status.

1/6 of the time, you reroll and get a normal exploding die (average 4.2)

4/6 of the time, you get your die roll (2 to 5)

1/6 of the time, you explode and keep your access to the reroll power

Let Y be the average of an exploding six sided die which still has a single 'reroll on a 1' charge left.

You have Y = 4.2 / 6 + (2 + 3 + 4 + 5) / 6 + (6 + Y) / 6

Which simplifies to 5 Y / 6 = 4.033, so Y = 4.84. Better than if you only reroll 1s on your first roll, but not that much.

And that is the type of reasoning you use when you're taking the 2 best dice from a number rolls.

Since a die that has exploded once is always more than a die that has not exploded, and always less than a die that has exploded twice or more, you want to keep track of the number of explosions.

When you roll two dice, you keep both, and you average is just the sum of the two, so 8.4 (exploding dice) to 9.68 (exploding dice with rerolls of the first '1' for each).

When you roll three dice, there are four possible cases:

No explosions: you're taking the two highest dice, all of which are between 1 and 5. Happens with probability (5/6)^3 = 125 / 216, around 58%.

One explosion: you're taking the exploded die (6 + 4.2 on average) and the highest of two dice, both of which are between 1 and 5. Happens with probability 75 / 216, around 33%

Two explosions: you're taking both exploded dice (6 + 4.2 on average each), for a total of 20.4 on average. Happens with probability 15 / 216, around 7%

Three explosions: all dice exploded, so you repeat the above. You total is 12 + the average from the process, since you got some 6s before repeating. Happens with probability 1 / 216, less than 0.5%

So what is the average when you take the maximum of two dice, all ranging from 1 to 5?

You get a 1 only if all dice roll 1 - happens 1/25 of the time (1/5 chance per die, so 1/5 * 1/5) (1/125 with three dice)

You get a 2 only if all dice are 1s or 2s and not all are 1s - happens (4/25 - 1/25) = 3/25 of the time (2/5 chance per die of being 1 or 2, so 4/25 for both, minus the case with only 1s). With three dice, it's 8/125 - 1/125 = 7/125 of the time.

You get a 3 only if all dice are 1s, 2s, or 3s and not all are 1s or 2s - happens (9/25 - 4/25) = 5/25 of the time. With three dice, it's 27/125 - 8/125 = 19/125.

You get a 4 7/25 of the time (37/125 with three dice)

You get a 5 9/25 of the time (61/125 with three dice)

That gives you an average of (1*1 + 2*3 + 3*5 + 4*7 + 5*9)/25 = 3.8 (with two dice), and (1*1 + 2*7 + 3*19 + 4*37 + 5*61)/125 = 4.2 (with three dice).

And what is the sum of the two highest rolls when rolling three dice, all ranging from 1 to 5?

Time to cheat: the minimum is 1.8 (the maximum when rolling three dice is 4.2, which is 1.2 over the mean. The minimum is therefore 1.2 below the mean). The sum of all three dice is 9 on average, so the two highest have an average sum of 7.2 (7.2 + 1.8 = 9). As an alternative, the maximum die is 4.2 on average, the middle die has an average of 3 (there is one above and one below, so trends in either direction are balanced out), so the sum of the two is 7.2 on average.

Coming back to our original list, we have:

125/216 of having 7.2

75/216 of having 10.2 + 3.8 = 14

15/216 of having 20.4

1/216 of having 12 plus the overall average.

Which can be expressed as Z = (900 + 1050 + 306 + 12 + Z) / 216, so Z = 2268 / 215 ~10.5. A nice improvement over the 8.4 you get from rolling two exploding dice and taking the sum.

If you want to do the same with four or more dice, the reasoning remains the same. Again, the bits you've assembled above can be reused later on. For instance, with four dice, if you get three explosions, the last die does not matter any longer, and you're looking for 12 plus the sum of the top two dice out of three exploding dice - which you've just computed. So for four dice, you'd have:

No explosions: needs to be computed. More than 7.2 (top two dice with three dice), less than 10 (rolling only 5s all the time).

One explosion: 6 + 4.2 from the explosion, maximum of three dice (which we've computed - 4.2), so 14.4

Two explosions: 20.4, as before

Three explosions: discard the unexploded die, all your three dice are now 6 + the previous score. The average is ~10.5, plus 12 for a total of 22.5 or so.

Four explosions: the rare outlier case, compute as before (it happens 1/1296, so it's not going to shift the odds much).

Etc.

Knaight

2016-12-21, 03:01 AM

Thanks! Do you have any idea what's the code if I wanted to add another rule, that the first "1" on any d6 is automatically re-rolled?

Not really. It is documented though, and I can talk about general programming for it. The easiest way to do it would be to define the individual die such that it has a range of numbers (1-6), a state tracker (RolledOne=0), and two if statements (one for if a 6 is rolled, one for if a 1 is rolled, which first checks if RolledOne=0, then if it does adds another 1d6-1 and sets RolledOne=1.

The Troubadour

2016-12-26, 05:41 AM

Numbers to crunch! Hurrah!

Wow, thanks a lot for this! And I'm glad you had fun with it. :-)

Powered by vBulletin® Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.