The Forge Archives

General Forge Forums => First Thoughts => Topic started by: Tyler.Tinsley on June 06, 2009, 09:04:46 AM

Title: I need help with a dice math problem
Post by: Tyler.Tinsley on June 06, 2009, 09:04:46 AM
hi, I'm new here and also fairly new to developing RPGs, I hear good things about this community so I will try to contribute as much as I ask from it.

I'm working on my new game and I have dice mechanic I want to use. It gives me the 0-infinity result potential I'm looking for but seems to have satisfyingly stable return.

The problem is I don't know how to calculate the odds for this mechanic, so I'm seeing if some of you can help me out.

The dice mechanic works like this

based on the situation a varying number of D6 are rolled

results of 1 & 2 count for nothing
results of 3-6 count as success
for each 6 rolled a new dice is added to the roll and its result is applied in the same way, with the potential for rolling infinite sixes.

So based on this what is the average success for each dice rolled, or phrased differently what percentage of the dice rolled will result in success?

The best I was able to come up with was a very rough average of 80%  but I'm not sure if that's accurate or if the average changes based on how many dice are rolled to start with.

I'm also interested in the math behind including results of 1-3 as counting for nothing. My attempt puts the success ratio at 60%
Title: Re: I need help with a dice math problem
Post by: chance.thirteen on June 06, 2009, 01:07:58 PM
http://catlikecoding.com/dice/ probably has the answer, but it's a complex one.

The basic die is 1d{0,0,1,1,1,1} however, getting the application to recognize the final 1 as a reroll chance is beyond my ability.

Fortunately the author posts here!

Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 06, 2009, 03:41:49 PM
I saw the calculator but was not quite smart enough to figure it out as well as you have.

The mechanic is basically plagiarized from spending a fate point in mouse guard I wonder if Luke has the numbers laying around?

man I wish I had a math wiz in my play test group.
Title: Re: I need help with a dice math problem
Post by: Jasper Flick on June 06, 2009, 06:43:11 PM
:) Don't worry chance.thirteen, It's beyond the calculator's ability as well. It can only recognize sets of distinct values, not individual positions on the dice.

Here we want to give the six a distinct value, but still also count it as just 1 succes. We can get there, but it's dirty. Here's the steps:

Basically, we start with 1d6, but weigh it like this: 1d6c{1..2 = 0, 3..6 = 1}. That's another way to write 1d{0,0,1,1,1,1}. Can't explode this the right way though.

Let's make the 6 stand out, by increasing its order of magnitude by two: 1d6c{1..2 = 0, 3..5 = 1, 6 = 100} or 1d{0,0,1,1,1,100}. Now we can explode just the six: 1d{0,0,1,1,1,100}e3h. We explode at most 3 times, not infinite. That's a limitation, but rerolling more that three times is extremely rare anyway. You can increase the number to get higher precision.

But now the numbers are all weird, both 101 and 200 represent 2 successes! We can fix that, by treating the result as a die and weighing it again: 1d(1d{0,0,1,1,1,100}e3h)c{0=0,1=1,100=1,101=2,200=2,201=3,300=3,301=4,400=4}. If you explode higher than 3, you have to add weights for 401, 500, and so on.

Now finally we have the proper result for rolling one die, rerolling it at most 3 times. Just increase the first number to roll more of them, for example six: 6d(1d{0,0,1,1,1,100}e3h)c{0=0,1=1,100=1,101=2,200=2,201=3,300=3,301=3,400=4}.

If you want to count 1..3 as 0, just chance the initial weights: 1d{0,0,0,1,1,100}. So rolling that six times is 6d(1d{0,0,0,1,1,100}e3h)c{0=0,1=1,100=1,101=2,200=2,201=3,300=3,301=4,400=4}.

Hope it helps!
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 07, 2009, 12:36:35 AM
wow thanks!

the explanation went far over my head but it managed to drop enough knowledge on me that I can understand what my odds look like. This dice mechanic results in some funny curves and proportions. the average return seems very linked to the amount of dice rolled.

this has helped a whole bunch!
Title: Re: I need help with a dice math problem
Post by: Ron Edwards on June 08, 2009, 10:36:55 AM
Hi Tyler,

In one part of your post you said 1-2 is a failure (or "failed die"), and in another, you said 1-3. Which is it?

Best, Ron
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 08, 2009, 03:52:13 PM
I was thinking about using success or fail raito as a way to model conditions so 1&2 = fail is a healthy person. 1-3 = fail is likely an injured person and so on, for each new condition you have the ratio would get worse. I'm probably going to scrap this idea for something little more cinematic. I would love to have just one method for rolling dice for the whole game.

Right now I'm worried the formula actually produces a little too stable a return with around %50 off the results tied up in just a few values , like when you roll 6 dice roughly 50% of the time you are going to get 4 or 5. granted in this game the difference between 4 or 5 could be very critical. so maybe it will be fine.

I will likely start play testing sections of the game with the current 1&2 =fail

Title: Re: I need help with a dice math problem
Post by: chance.thirteen on June 08, 2009, 04:27:48 PM
The word ratio reminded me of something. You could just say that hurt characters lose 1/5th their successes, wounded lose 2/5ths, badly wounded lose 3/5ths and so on. Decide if you round up or down, and you have a consistance loss that doesn't rely on dice whackiness to tell you it is happening. You also avoid the trouble White Wolf ran into with their increasing targent numbers to the point where a very high pool and a very low pool essentially performed the same because it was very rare to get a success on any die (example: a 10 difficulty. 3 d10s have a worse chance of getting results of 10 compared to a 9 d10 pool, but its still much more happenstance than anything at all reliable.)
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 08, 2009, 06:29:06 PM
My goal is to have conflicts play out like they do in a movie. So I'm likely going to use more temporary shocking moments to model injuries. Like how Inigo Montoya is wounded a few times but still manages to come back and avenge his fathers death. It's a little fantastic but your still able to suspend disbelief.

If I were going for more of a simulation or a less Hollywood kind of story then the sliding ratio would work fine (I would only expand the fail ratio to cover 3&4  3 being lost to physical dysfunction and 4 being lost to mental imbalance). The game already has a strong mechanic for tracking each character's relative advantage in the fight so injury will likely be folded into this.
Title: Re: I need help with a dice math problem
Post by: wincz on June 09, 2009, 05:54:19 AM
I think what your looking for is called the binomial distribution.

It is given as P(K=k) = n!/((n-k)!k!) * p^k * (1-p)^(n-k)

this is the probability of getting exactly k success on n dices. p is the probability of getting a success,
for you with 1-3 as failure gives p = 1/2, and 1-2 as failure gives you p = 2/3.

Now, the thing I don't now about your system is how many dices and how many successes you need.

So just an example in case of,

if I roll n = 5 dices with p = 1/2 and k = 2 (I ask for at least 2 successes),
then you have to sum P(K=2)+P(K=3)+P(K=4)+P(K=5)

Oh, also the ! sign is for factorial, meaning for example 5! = 5*4*3*2*1
With a calculator It quite easy to compute from here.

Now, for the 6 = reroll, this complicate the situation quite a bit, as there is 1/6 chance that the number of dice increases.
Doing it exactly would get very messy, but there is a simple way to approximate, neglecting six giving a second six.
A six increase the number of dice, this means that instead of

P(K=2)+P(K=3)+P(K=4)+P(K=5) you should do  (1+1/6)*( P(K=2)+P(K=3)+P(K=4)+P(K=5) )

Hope it helps..

In my game I use 1-3 fail, 4-6 ok, no reroll

Title: Re: I need help with a dice math problem
Post by: wincz on June 09, 2009, 06:37:22 AM
Hm, sorry, the reroll 6's trick is not correct

... It is more complicated than that.

I'll post the solution to this latter on.
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 09, 2009, 07:47:43 AM
I ran through a little combat today and I think I'm going to stick with 1&2=fail with an exploding 6 mechanic.

In the system it's often the players that actually determine how many dice are rolled so the only thing that is needed math wise is a an easy to understand explanation so players can make an informed choice.

something like this "On average 80% of the dice you roll will be successful"
Title: Re: I need help with a dice math problem
Post by: Jasper Flick on June 09, 2009, 08:06:47 AM
Just for fun, here's another variable to consider: the die size.

For example, you succeed on 1..2 and reroll on a 1.
If you're dominating, roll d4s.
If you're OK, roll d6s.
If you're shocked, roll d8s.
If you're injured, roll d10s.
If you're seriously screwed, roll d12s.
If you're basically dead, roll d20s.

The advantage is that the numbers to look for and the amount of dice to roll stay the same. Also, having to roll bigger dice reall feels different. The downside is that you need to have all those dice.
Title: Re: I need help with a dice math problem
Post by: wincz on June 09, 2009, 08:21:39 AM
How many successes do you require for a throw to be considered successful ?
one or more ? Because this has a strong impact on the odds.

Concerning the 6's reroll, if the roll is successful anyway, there is no point of
knowing if there is 6's or not. They're important only for throw with less success
than required, but having 6's may push them up past the threshold.

So, what has to be done is (for the previous example)

P(K=2)+P(K=3)+P(K=4)+P(K=5) + P(K = 1, with one 6)

this gives (with 1-2 as failures) 0.9544 + 0.0076 = 0.962 or 96.2% of succeeding at least to successes with 5 dices.

this might come handy : http://www.stat.tamu.edu/~west/applets/binomialdemo.html



Title: Re: I need help with a dice math problem
Post by: Jasper Flick on June 09, 2009, 08:33:34 AM
By the way, here's the distribution calculator input for my fun example.

5d(1d(1d6c{1=100,2=1})e3h)c{1=1,100=1,2=2,101=2,3=3,201=3,4=4,301=4,400=4}

The red number is the amount of dice rolled.
The green number is the die size.
The blue number is the max number of rerolls (supports max of 3 with this input string).

Or use wincz's thing, if that's easier.
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 09, 2009, 10:21:45 AM
Quote from: wincz on June 09, 2009, 08:21:39 AM
How many successes do you require for a throw to be considered successful ?
one or more ? Because this has a strong impact on the odds.

it's actually a variable. the more success the better, shooting a gun and missing will only distract the target, where getting a massive success will not only hit but cause serious injury.

I will explain how I got my general 80% return so you can let me know if I am doing something wrong.

each die has a 1/3 chance of failure, a 2/3 chance of success and a 1/6 chance of adding a die with the very same odds.

assuming perfect results if we roll 6 dice we will have 2 failure 4 success and an extra seventh die generated by the six. this extra die is subject to the same odds as the other dice so it's not quite as good as having a dice with 5/6 chance of success.

It's my thinking that the average return could not possibly be better then 5/6 but lies somewhere between 4/6 and 5/6

if we make 1/6th a percentage of 100 we get 16.6, times that by 4.6 (4 represents the 4/6 chance of success and point six represents the 2/3 potential for the exploded die to result in a success) we get 76.6

This is flawed because it's not taking into account the potential for the exploded die to roll another six and produce another die of the same average return.

It's hard to calculate because you need to know what the average return of a dice is in order to calculate the value added by the explosion. it requires a level of math that I cant figure out.

my attempts result in values that i round up to 80% but that's mostly optimism at play.

Title: Re: I need help with a dice math problem
Post by: Jasper Flick on June 09, 2009, 11:34:04 AM
Personally, I would tell players something like "Roughly two out of three dice will be a success, and about one out of ten will generate two successes. But nothing's certain, except that the more dice you roll, the higher your chances of getting those successes!" I think that's fine for an informed decision.
Title: Re: I need help with a dice math problem
Post by: Guy Srinivasan on June 09, 2009, 01:40:16 PM
The average is easy to compute in cases like this if you know the trick. First call the average successes per die A. Then, in your example where 1,2 fail, 3,4,5 succeed, and 6 succeeds and explodes,

A = (2/6 * 0) + (3/6 * 1) + (1/6 * (1+A))

solve for A, you get A = 4/5. So in fact each die is worth expected value exactly 80% of a success, though the results aren't just 0 or 1.

To go further, you can compute the variance of a single die, then multiply by number of dice. If you know how to do this, good - use Wolfram|Alpha to make it easier. :) If you don't, fine... in this case you can tell your players that rolling N dice, on average you'll get 80% successes, and 90% of the time they'll get at least (80 - 115*sqrt(N)/N)% and at most (80 + 115*sqrt(N)/N)%.
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 09, 2009, 02:09:23 PM
Thank goodness some people go to college or at least pay attention in math class.

thanks for confirming my suspicions. I can now price various things accordingly.
Title: Re: I need help with a dice math problem
Post by: evilphd7 on June 12, 2009, 04:59:19 PM
Quote from: Jasper Flick on June 09, 2009, 08:06:47 AM
Just for fun, here's another variable to consider: the die size....

The advantage is that the numbers to look for and the amount of dice to roll stay the same. Also, having to roll bigger dice reall feels different. The downside is that you need to have all those dice.

I'm actually working on a game at the moment which leverages this concept of "scalable" dice for a difficulty.  It hadn't occurred to me that gaming dice might be difficult for some people to find (I've just always them). Does anyone out there happen to know of any published games which use scalable dice?
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 14, 2009, 08:16:42 PM
lots and lots of games use the dice scale 4-12. all to varying degrees of success and complexity. my favorite use of the dice scale was in battle ball. a main stream foot ball board game.
Title: Re: I need help with a dice math problem
Post by: Wordman on June 14, 2009, 08:47:42 PM
The exact math to figure this out is pretty painful. Mostly, it involves looking at a bunch of isolated cases and adding them together.

However, this problem has three important characteristics: 1) the outcome is totally non-obvious, 2) it is extremely easy to simulate a single event (die roll) and 3) it has a limited number of starting cases (i.e. dice pools will only start out so large). This means that this problem is an extremely good candidate for Monte Carlo simulation (http://en.wikipedia.org/wiki/Monte_Carlo_method). (I work with a bunch of math PhD's and nearly all of them told me to use simulation like this, if that helps.)

As far as Monte Carlo simulations go, this one is really easy. You just need some code that will generate the result of a single roll. Then run that code, say, 10 million times (that should take maybe five minutes, tops). Graph the results.

It won't be an exact answer, but it will tell you what you want to know.

If you lack coding ability, let me know. I can whip something up.
Title: Re: I need help with a dice math problem
Post by: Wordman on June 14, 2009, 09:42:08 PM
I decided to just write this code, out of curiosity (code at the end). Here is the results for pools of size one through 10, running a million rolls at each size. Note that the median and the mean are pretty far apart, as you might guess for an "infinite" tail. Bear in mind that this is a simulation, so the distribution will not be perfect. (As an example, in the 1 die table, the 22 success result probably got a few more hits than a pure computation would figure out, just by chance.)


-- Number of rolls generating n successes from a 1 dice pool --
0 successes:          111458 = 11.145789%
1 successes:          345093 = 34.509265%
2 successes:          307151 = 30.715069%
3 successes:           93762 = 9.376191%
4 successes:           66931 = 6.693093%
5 successes:           29757 = 2.975697%
6 successes:           19317 = 1.931698%
7 successes:           10182 = 1.018199%
8 successes:            6516 = 0.651599%
9 successes:            3702 = 0.370200%
10 successes:            2273 = 0.227300%
11 successes:            1442 = 0.144200%
12 successes:             894 = 0.089400%
13 successes:             531 = 0.053100%
14 successes:             364 = 0.036400%
15 successes:             218 = 0.021800%
16 successes:             146 = 0.014600%
17 successes:              94 = 0.009400%
18 successes:              64 = 0.006400%
19 successes:              43 = 0.004300%
20 successes:              24 = 0.002400%
21 successes:               9 = 0.000900%
22 successes:              13 = 0.001300%
23 successes:               4 = 0.000400%
24 successes:               5 = 0.000500%
25 successes:               1 = 0.000100%
26 successes:               2 = 0.000200%
27 successes:               1 = 0.000100%
28 successes:               2 = 0.000200%
29 successes:               1 = 0.000100%
30 successes:               0 = 0.000000%
31 successes:               1 = 0.000100%
Average result: 2.001689

-- Number of rolls generating n successes from a 2 dice pool --
0 successes:           36959 = 3.695896%
1 successes:          173274 = 17.327383%
2 successes:          287574 = 28.757371%
3 successes:          216501 = 21.650078%
4 successes:          107925 = 10.792489%
5 successes:           72522 = 7.252193%
6 successes:           39582 = 3.958196%
7 successes:           25402 = 2.540197%
8 successes:           14852 = 1.485199%
9 successes:            9403 = 0.940299%
10 successes:            5840 = 0.583999%
11 successes:            3655 = 0.365500%
12 successes:            2353 = 0.235300%
13 successes:            1474 = 0.147400%
14 successes:             983 = 0.098300%
15 successes:             564 = 0.056400%
16 successes:             385 = 0.038500%
17 successes:             264 = 0.026400%
18 successes:             164 = 0.016400%
19 successes:             114 = 0.011400%
20 successes:              79 = 0.007900%
21 successes:              42 = 0.004200%
22 successes:              27 = 0.002700%
23 successes:              23 = 0.002300%
24 successes:              21 = 0.002100%
25 successes:               3 = 0.000300%
26 successes:               4 = 0.000400%
27 successes:               2 = 0.000200%
28 successes:               5 = 0.000500%
29 successes:               2 = 0.000200%
30 successes:               0 = 0.000000%
31 successes:               2 = 0.000200%
32 successes:               0 = 0.000000%
33 successes:               0 = 0.000000%
34 successes:               1 = 0.000100%
Average result: 2.999588

-- Number of rolls generating n successes from a 3 dice pool --
0 successes:           12501 = 1.250099%
1 successes:           77238 = 7.723792%
2 successes:          188206 = 18.820581%
3 successes:          233199 = 23.319877%
4 successes:          174189 = 17.418883%
5 successes:          110275 = 11.027489%
6 successes:           74441 = 7.444093%
7 successes:           46089 = 4.608895%
8 successes:           30279 = 3.027897%
9 successes:           19078 = 1.907798%
10 successes:           12220 = 1.221999%
11 successes:            7689 = 0.768899%
12 successes:            5149 = 0.514899%
13 successes:            3354 = 0.335400%
14 successes:            2105 = 0.210500%
15 successes:            1389 = 0.138900%
16 successes:             906 = 0.090600%
17 successes:             609 = 0.060900%
18 successes:             386 = 0.038600%
19 successes:             215 = 0.021500%
20 successes:             176 = 0.017600%
21 successes:             106 = 0.010600%
22 successes:              60 = 0.006000%
23 successes:              48 = 0.004800%
24 successes:              35 = 0.003500%
25 successes:              15 = 0.001500%
26 successes:              16 = 0.001600%
27 successes:               9 = 0.000900%
28 successes:               5 = 0.000500%
29 successes:               7 = 0.000700%
30 successes:               3 = 0.000300%
31 successes:               0 = 0.000000%
32 successes:               1 = 0.000100%
33 successes:               0 = 0.000000%
34 successes:               1 = 0.000100%
35 successes:               1 = 0.000100%
36 successes:               1 = 0.000100%
Average result: 3.993547

-- Number of rolls generating n successes from a 4 dice pool --
0 successes:            4124 = 0.412400%
1 successes:           32211 = 3.221097%
2 successes:          102835 = 10.283490%
3 successes:          180912 = 18.091182%
4 successes:          194005 = 19.400481%
5 successes:          151222 = 15.122185%
6 successes:          107332 = 10.733189%
7 successes:           75950 = 7.594992%
8 successes:           50182 = 5.018195%
9 successes:           34099 = 3.409897%
10 successes:           22523 = 2.252298%
11 successes:           15147 = 1.514698%
12 successes:            9857 = 0.985699%
13 successes:            6600 = 0.659999%
14 successes:            4341 = 0.434100%
15 successes:            2996 = 0.299600%
16 successes:            1950 = 0.195000%
17 successes:            1257 = 0.125700%
18 successes:             809 = 0.080900%
19 successes:             554 = 0.055400%
20 successes:             355 = 0.035500%
21 successes:             265 = 0.026500%
22 successes:             169 = 0.016900%
23 successes:              96 = 0.009600%
24 successes:              66 = 0.006600%
25 successes:              47 = 0.004700%
26 successes:              32 = 0.003200%
27 successes:              22 = 0.002200%
28 successes:               9 = 0.000900%
29 successes:              12 = 0.001200%
30 successes:               9 = 0.000900%
31 successes:               3 = 0.000300%
32 successes:               5 = 0.000500%
33 successes:               2 = 0.000200%
34 successes:               0 = 0.000000%
35 successes:               1 = 0.000100%
36 successes:               1 = 0.000100%
37 successes:               0 = 0.000000%
38 successes:               1 = 0.000100%
Average result: 5.000107

-- Number of rolls generating n successes from a 5 dice pool --
0 successes:            1359 = 0.135900%
1 successes:           12925 = 1.292499%
2 successes:           51276 = 5.127595%
3 successes:          115922 = 11.592188%
4 successes:          166252 = 16.625183%
5 successes:          166993 = 16.699283%
6 successes:          136737 = 13.673686%
7 successes:          103789 = 10.378890%
8 successes:           75276 = 7.527592%
9 successes:           53354 = 5.335395%
10 successes:           37555 = 3.755496%
11 successes:           25521 = 2.552097%
12 successes:           17140 = 1.713998%
13 successes:           11696 = 1.169599%
14 successes:            7829 = 0.782899%
15 successes:            5369 = 0.536899%
16 successes:            3577 = 0.357700%
17 successes:            2400 = 0.240000%
18 successes:            1691 = 0.169100%
19 successes:            1084 = 0.108400%
20 successes:             755 = 0.075500%
21 successes:             493 = 0.049300%
22 successes:             311 = 0.031100%
23 successes:             204 = 0.020400%
24 successes:             158 = 0.015800%
25 successes:             130 = 0.013000%
26 successes:              66 = 0.006600%
27 successes:              44 = 0.004400%
28 successes:              32 = 0.003200%
29 successes:              15 = 0.001500%
30 successes:              17 = 0.001700%
31 successes:              13 = 0.001300%
32 successes:              10 = 0.001000%
33 successes:               3 = 0.000300%
34 successes:               2 = 0.000200%
35 successes:               0 = 0.000000%
36 successes:               1 = 0.000100%
37 successes:               1 = 0.000100%
38 successes:               1 = 0.000100%
Average result: 5.995540

-- Number of rolls generating n successes from a 6 dice pool --
0 successes:             471 = 0.047100%
1 successes:            5024 = 0.502399%
2 successes:           23564 = 2.356398%
3 successes:           66052 = 6.605193%
4 successes:          118920 = 11.891988%
5 successes:          151474 = 15.147385%
6 successes:          148640 = 14.863985%
7 successes:          126129 = 12.612887%
8 successes:           99633 = 9.963290%
9 successes:           75052 = 7.505192%
10 successes:           55323 = 5.532294%
11 successes:           39582 = 3.958196%
12 successes:           27801 = 2.780097%
13 successes:           19430 = 1.942998%
14 successes:           13491 = 1.349099%
15 successes:            9182 = 0.918199%
16 successes:            6414 = 0.641399%
17 successes:            4407 = 0.440700%
18 successes:            2974 = 0.297400%
19 successes:            2080 = 0.208000%
20 successes:            1384 = 0.138400%
21 successes:             938 = 0.093800%
22 successes:             627 = 0.062700%
23 successes:             449 = 0.044900%
24 successes:             301 = 0.030100%
25 successes:             208 = 0.020800%
26 successes:             143 = 0.014300%
27 successes:              82 = 0.008200%
28 successes:              75 = 0.007500%
29 successes:              40 = 0.004000%
30 successes:              36 = 0.003600%
31 successes:              27 = 0.002700%
32 successes:              16 = 0.001600%
33 successes:              11 = 0.001100%
34 successes:               7 = 0.000700%
35 successes:               4 = 0.000400%
36 successes:               5 = 0.000500%
37 successes:               2 = 0.000200%
38 successes:               1 = 0.000100%
39 successes:               0 = 0.000000%
40 successes:               0 = 0.000000%
41 successes:               1 = 0.000100%
42 successes:               1 = 0.000100%
Average result: 6.999319

-- Number of rolls generating n successes from a 7 dice pool --
0 successes:             160 = 0.016000%
1 successes:            1888 = 0.188800%
2 successes:           10624 = 1.062399%
3 successes:           34616 = 3.461597%
4 successes:           75937 = 7.593692%
5 successes:          117204 = 11.720388%
6 successes:          138879 = 13.887886%
7 successes:          135116 = 13.511586%
8 successes:          117412 = 11.741188%
9 successes:           95598 = 9.559790%
10 successes:           74616 = 7.461593%
11 successes:           56149 = 5.614894%
12 successes:           40828 = 4.082796%
13 successes:           29801 = 2.980097%
14 successes:           21329 = 2.132898%
15 successes:           15325 = 1.532498%
16 successes:           10507 = 1.050699%
17 successes:            7425 = 0.742499%
18 successes:            5018 = 0.501799%
19 successes:            3663 = 0.366300%
20 successes:            2454 = 0.245400%
21 successes:            1727 = 0.172700%
22 successes:            1135 = 0.113500%
23 successes:             810 = 0.081000%
24 successes:             576 = 0.057600%
25 successes:             364 = 0.036400%
26 successes:             287 = 0.028700%
27 successes:             165 = 0.016500%
28 successes:             131 = 0.013100%
29 successes:              74 = 0.007400%
30 successes:              53 = 0.005300%
31 successes:              40 = 0.004000%
32 successes:              29 = 0.002900%
33 successes:              22 = 0.002200%
34 successes:              14 = 0.001400%
35 successes:              12 = 0.001200%
36 successes:               3 = 0.000300%
37 successes:               4 = 0.000400%
38 successes:               1 = 0.000100%
39 successes:               2 = 0.000200%
40 successes:               0 = 0.000000%
41 successes:               1 = 0.000100%
42 successes:               0 = 0.000000%
43 successes:               2 = 0.000200%
Average result: 7.994876

-- Number of rolls generating n successes from a 8 dice pool --
0 successes:              56 = 0.005600%
1 successes:             687 = 0.068700%
2 successes:            4564 = 0.456400%
3 successes:           17034 = 1.703398%
4 successes:           44121 = 4.412096%
5 successes:           80772 = 8.077192%
6 successes:          113469 = 11.346889%
7 successes:          128215 = 12.821487%
8 successes:          124703 = 12.470288%
9 successes:          111117 = 11.111689%
10 successes:           91923 = 9.192291%
11 successes:           73464 = 7.346393%
12 successes:           56527 = 5.652694%
13 successes:           42304 = 4.230396%
14 successes:           31228 = 3.122797%
15 successes:           23000 = 2.299998%
16 successes:           16677 = 1.667698%
17 successes:           11905 = 1.190499%
18 successes:            8423 = 0.842299%
19 successes:            6056 = 0.605599%
20 successes:            4169 = 0.416900%
21 successes:            2840 = 0.284000%
22 successes:            2100 = 0.210000%
23 successes:            1412 = 0.141200%
24 successes:            1028 = 0.102800%
25 successes:             657 = 0.065700%
26 successes:             494 = 0.049400%
27 successes:             319 = 0.031900%
28 successes:             238 = 0.023800%
29 successes:             150 = 0.015000%
30 successes:             109 = 0.010900%
31 successes:              89 = 0.008900%
32 successes:              47 = 0.004700%
33 successes:              31 = 0.003100%
34 successes:              26 = 0.002600%
35 successes:              22 = 0.002200%
36 successes:               8 = 0.000800%
37 successes:              10 = 0.001000%
38 successes:               3 = 0.000300%
39 successes:               2 = 0.000200%
40 successes:               1 = 0.000100%
41 successes:               0 = 0.000000%
42 successes:               0 = 0.000000%
43 successes:               0 = 0.000000%
44 successes:               0 = 0.000000%
45 successes:               0 = 0.000000%
46 successes:               1 = 0.000100%
Average result: 8.997355

-- Number of rolls generating n successes from a 9 dice pool --
0 successes:              12 = 0.001200%
1 successes:             257 = 0.025700%
2 successes:            1904 = 0.190400%
3 successes:            8114 = 0.811399%
4 successes:           23852 = 2.385198%
5 successes:           51270 = 5.126995%
6 successes:           82885 = 8.288492%
7 successes:          108380 = 10.837989%
8 successes:          119531 = 11.953088%
9 successes:          117302 = 11.730188%
10 successes:          104956 = 10.495590%
11 successes:           88585 = 8.858491%
12 successes:           72347 = 7.234693%
13 successes:           56695 = 5.669494%
14 successes:           43571 = 4.357096%
15 successes:           33096 = 3.309597%
16 successes:           24101 = 2.410098%
17 successes:           18077 = 1.807698%
18 successes:           12861 = 1.286099%
19 successes:            9374 = 0.937399%
20 successes:            6624 = 0.662399%
21 successes:            4815 = 0.481500%
22 successes:            3415 = 0.341500%
23 successes:            2326 = 0.232600%
24 successes:            1703 = 0.170300%
25 successes:            1187 = 0.118700%
26 successes:             850 = 0.085000%
27 successes:             601 = 0.060100%
28 successes:             404 = 0.040400%
29 successes:             280 = 0.028000%
30 successes:             176 = 0.017600%
31 successes:             122 = 0.012200%
32 successes:             121 = 0.012100%
33 successes:              54 = 0.005400%
34 successes:              43 = 0.004300%
35 successes:              25 = 0.002500%
36 successes:              29 = 0.002900%
37 successes:              14 = 0.001400%
38 successes:              15 = 0.001500%
39 successes:               6 = 0.000600%
40 successes:               5 = 0.000500%
41 successes:               3 = 0.000300%
42 successes:               7 = 0.000700%
43 successes:               1 = 0.000100%
44 successes:               2 = 0.000200%
45 successes:               1 = 0.000100%
46 successes:               1 = 0.000100%
47 successes:               1 = 0.000100%
Average result: 9.997082

-- Number of rolls generating n successes from a 10 dice pool --
0 successes:               5 = 0.000500%
1 successes:              92 = 0.009200%
2 successes:             745 = 0.074500%
3 successes:            3627 = 0.362700%
4 successes:           12172 = 1.217199%
5 successes:           29780 = 2.977997%
6 successes:           55981 = 5.598094%
7 successes:           83511 = 8.351092%
8 successes:          104598 = 10.459790%
9 successes:          111856 = 11.185589%
10 successes:          109573 = 10.957289%
11 successes:          100221 = 10.022090%
12 successes:           85998 = 8.599791%
13 successes:           71306 = 7.130593%
14 successes:           56425 = 5.642494%
15 successes:           44239 = 4.423896%
16 successes:           34210 = 3.420997%
17 successes:           25706 = 2.570597%
18 successes:           19196 = 1.919598%
19 successes:           14202 = 1.420199%
20 successes:           10271 = 1.027099%
21 successes:            7531 = 0.753099%
22 successes:            5357 = 0.535699%
23 successes:            3995 = 0.399500%
24 successes:            2769 = 0.276900%
25 successes:            1968 = 0.196800%
26 successes:            1405 = 0.140500%
27 successes:            1000 = 0.100000%
28 successes:             690 = 0.069000%
29 successes:             452 = 0.045200%
30 successes:             347 = 0.034700%
31 successes:             249 = 0.024900%
32 successes:             148 = 0.014800%
33 successes:             114 = 0.011400%
34 successes:              84 = 0.008400%
35 successes:              63 = 0.006300%
36 successes:              40 = 0.004000%
37 successes:              23 = 0.002300%
38 successes:              16 = 0.001600%
39 successes:               9 = 0.000900%
40 successes:               8 = 0.000800%
41 successes:               5 = 0.000500%
42 successes:               4 = 0.000400%
43 successes:               3 = 0.000300%
44 successes:               2 = 0.000200%
45 successes:               0 = 0.000000%
46 successes:               2 = 0.000200%
47 successes:               3 = 0.000300%
Average result: 11.005374
Title: Re: I need help with a dice math problem
Post by: Wordman on June 14, 2009, 09:42:26 PM
Here is the code, written in Python. Settings are at the bottom. Change "Repetitions" at the bottom to increase or decrease the number of repetitions made at each size. Change the MinPool and MaxPool to alter the possible range of pool sizes. Note that, being a simulation, you will get different results each time you run this code. If you want to repeat a result, you'll need to change random.seed() into something that provides a constant seed value.

This code is not particularly efficient, and probably contains bugs.

import random

def init_poolsize(poolsize,counts):
   results = {}
   results['totalrolls'] = 0
   results['totalsux'] = 0
   results['sux'] = {}
   counts[poolsize] = results
   
def rollpool(poolsize):
   successes = 0
   for die in range(0,poolsize + 1):
      roll = random.randint(1, 6)
      if roll >= 3:
         successes += 1
         if roll == 6:
            successes += rollpool(1)
   return successes

def run_poolsize(poolsize,counts,reps):
   results = counts[poolsize]
   for rep in range(0,reps + 1):
      sux = rollpool(poolsize)
      results['totalrolls'] += 1
      results['totalsux'] += sux
      try:
         results['sux'][sux] += 1
      except:
         results['sux'][sux] = 1

def print_poolsize(poolsize,counts):
   print
   print '-- Number of rolls generating n successes from a %i dice pool --' % (poolsize)
   results = counts[poolsize]
   sux = results['sux']
   
   # Find the highest number of successes on a single roll
   suxcounts = sux.keys()
   suxcounts.sort()
   maxresult = suxcounts[-1]
   
   # Iterator over all possible results
   totalrolls = results['totalrolls']
   for successes in range(0,maxresult + 1):
      count = 0
      try:
         count = results['sux'][successes]
      except:
         count = 0 # No roll generated this many successes
      percentage = (count * 100.0) / totalrolls
      print '%2i successes: %15i = %0.6f%%'  % (successes, count, percentage)
   
   averageresult = (1.0 * results['totalsux']) / totalrolls
   print 'Average result: %f' % (averageresult)
   
Counts = {}
Repititions = 1000000
MinPool = 1
MaxPool = 10
random.seed()
for poolsize in range(MinPool, MaxPool+1):
   init_poolsize(poolsize,Counts)
   run_poolsize(poolsize,Counts,Repititions)
   print_poolsize(poolsize,Counts)
Title: Re: I need help with a dice math problem
Post by: Guy Srinivasan on June 15, 2009, 01:15:43 PM
I think this is a bug:
for die in range(0,poolsize + 1):
'cause it looks like it's rolling 1 too many dice here, and that jives with the averages you're getting. If a 6 means roll 2 extra dice, then each die would be worth A = 3/6 * 1 + 1/6 * (1+2*A) = 1 success, and rolling "N dice" would instead roll N+1 dice, yielding on average N+1 successes, like your simulation shows.
Title: Re: I need help with a dice math problem
Post by: Wordman on June 15, 2009, 01:35:03 PM
Quote from: Guy Srinivasan on June 15, 2009, 01:15:43 PM
I think this is a bug:
for die in range(0,poolsize + 1):
'cause it looks like it's rolling 1 too many dice here
Absolutely right. Serious bug, too. Should have been either range(0,poolsize) or range(1,poolsize + 1). Since you don't actually use the 'die' variable there, the first one would be better.

Since we still can't edit posts (for no satisfactorily explained reason), mentally add one pool sizes of the output data.

That will serve as a lesson to me to not post code I only spent 45 minutes on. D'oh!
Title: Re: I need help with a dice math problem
Post by: Guy Srinivasan on June 15, 2009, 02:09:06 PM
Unfortunately it's not just a matter of using a different table...
if roll == 6:
            successes += rollpool(1)

makes a 6 explode into 2 dice rather than 1.
Title: Re: I need help with a dice math problem
Post by: Tyler.Tinsley on June 15, 2009, 02:34:36 PM
I thought the numbers looked a little optimistic :) , still I'm quite impressed that you set up simulations to test the math. I would love to see some less optimistic 6 explodes as one die tests.
Title: Re: I need help with a dice math problem
Post by: Wordman on June 15, 2009, 07:57:26 PM
Quote from: Guy Srinivasan on June 15, 2009, 02:09:06 PM
Unfortunately it's not just a matter of using a different table...
if roll == 6:
            successes += rollpool(1)

makes a 6 explode into 2 dice rather than 1.
D'oh! Missed it by that much. What a difference two bloody characters makes.

Anyway, a rerun with the fix:


-- Number of rolls generating n successes from a 1 dice pool --
0 successes:          333360 = 33.335967%
1 successes:          555095 = 55.509444%
2 successes:           92972 =  9.297191%
3 successes:           15511 =  1.551098%
4 successes:            2567 =  0.256700%
5 successes:             417 =  0.041700%
6 successes:              72 =  0.007200%
7 successes:               6 =  0.000600%
8 successes:               1 =  0.000100%
Average result: 0.800406

-- Number of rolls generating n successes from a 2 dice pool --
0 successes:          111192 = 11.119189%
1 successes:          370383 = 37.038263%
2 successes:          370405 = 37.040463%
3 successes:          113023 = 11.302289%
4 successes:           27365 =  2.736497%
5 successes:            6099 =  0.609899%
6 successes:            1223 =  0.122300%
7 successes:             260 =  0.026000%
8 successes:              39 =  0.003900%
9 successes:              10 =  0.001000%
10 successes:               2 =  0.000200%
Average result: 1.599795

-- Number of rolls generating n successes from a 3 dice pool --
0 successes:           37337 =  3.733696%
1 successes:          185670 = 18.566981%
2 successes:          339561 = 33.956066%
3 successes:          278055 = 27.805472%
4 successes:          112507 = 11.250689%
5 successes:           34746 =  3.474597%
6 successes:            9275 =  0.927499%
7 successes:            2186 =  0.218600%
8 successes:             521 =  0.052100%
9 successes:             114 =  0.011400%
10 successes:              23 =  0.002300%
11 successes:               6 =  0.000600%
Average result: 2.399155

-- Number of rolls generating n successes from a 4 dice pool --
0 successes:           12358 =  1.235799%
1 successes:           81706 =  8.170592%
2 successes:          219625 = 21.962478%
3 successes:          299322 = 29.932170%
4 successes:          228133 = 22.813277%
5 successes:          104993 = 10.499290%
6 successes:           37954 =  3.795396%
7 successes:           11659 =  1.165899%
8 successes:            3162 =  0.316200%
9 successes:             811 =  0.081100%
10 successes:             214 =  0.021400%
11 successes:              45 =  0.004500%
12 successes:              14 =  0.001400%
13 successes:               5 =  0.000500%
Average result: 3.201216

-- Number of rolls generating n successes from a 5 dice pool --
0 successes:            4090 =  0.409000%
1 successes:           34337 =  3.433697%
2 successes:          119925 = 11.992488%
3 successes:          229183 = 22.918277%
4 successes:          263922 = 26.392174%
5 successes:          192198 = 19.219781%
6 successes:           98005 =  9.800490%
7 successes:           39006 =  3.900596%
8 successes:           13553 =  1.355299%
9 successes:            4117 =  0.411700%
10 successes:            1198 =  0.119800%
11 successes:             346 =  0.034600%
12 successes:              91 =  0.009100%
13 successes:              24 =  0.002400%
14 successes:               3 =  0.000300%
15 successes:               1 =  0.000100%
16 successes:               2 =  0.000200%
Average result: 4.002238

-- Number of rolls generating n successes from a 6 dice pool --
0 successes:            1379 =  0.137900%
1 successes:           13919 =  1.391899%
2 successes:           59608 =  5.960794%
3 successes:          146485 = 14.648485%
4 successes:          227298 = 22.729777%
5 successes:          233380 = 23.337977%
6 successes:          167841 = 16.784083%
7 successes:           89685 =  8.968491%
8 successes:           38973 =  3.897296%
9 successes:           14627 =  1.462699%
10 successes:            4795 =  0.479500%
11 successes:            1438 =  0.143800%
12 successes:             424 =  0.042400%
13 successes:             106 =  0.010600%
14 successes:              29 =  0.002900%
15 successes:              12 =  0.001200%
16 successes:               2 =  0.000200%
Average result: 4.797797

-- Number of rolls generating n successes from a 7 dice pool --
0 successes:             484 =  0.048400%
1 successes:            5236 =  0.523599%
2 successes:           27428 =  2.742797%
3 successes:           83077 =  8.307692%
4 successes:          163374 = 16.337384%
5 successes:          218731 = 21.873078%
6 successes:          209337 = 20.933679%
7 successes:          148116 = 14.811585%
8 successes:           82506 =  8.250592%
9 successes:           38397 =  3.839696%
10 successes:           15441 =  1.544098%
11 successes:            5369 =  0.536899%
12 successes:            1740 =  0.174000%
13 successes:             545 =  0.054500%
14 successes:             171 =  0.017100%
15 successes:              32 =  0.003200%
16 successes:              13 =  0.001300%
17 successes:               3 =  0.000300%
18 successes:               1 =  0.000100%
Average result: 5.599508

-- Number of rolls generating n successes from a 8 dice pool --
0 successes:             143 =  0.014300%
1 successes:            1969 =  0.196900%
2 successes:           12151 =  1.215099%
3 successes:           43503 =  4.350296%
4 successes:          103426 = 10.342590%
5 successes:          171391 = 17.139083%
6 successes:          207995 = 20.799479%
7 successes:          188533 = 18.853281%
8 successes:          133131 = 13.313087%
9 successes:           76267 =  7.626692%
10 successes:           37045 =  3.704496%
11 successes:           15530 =  1.552998%
12 successes:            5914 =  0.591399%
13 successes:            2047 =  0.204700%
14 successes:             669 =  0.066900%
15 successes:             199 =  0.019900%
16 successes:              65 =  0.006500%
17 successes:              16 =  0.001600%
18 successes:               5 =  0.000500%
19 successes:               0 =  0.000000%
20 successes:               1 =  0.000100%
21 successes:               1 =  0.000100%
Average result: 6.399238

-- Number of rolls generating n successes from a 9 dice pool --
0 successes:              53 =  0.005300%
1 successes:             784 =  0.078400%
2 successes:            5299 =  0.529899%
3 successes:           21505 =  2.150498%
4 successes:           59738 =  5.973794%
5 successes:          118520 = 11.851988%
6 successes:          174653 = 17.465283%
7 successes:          195644 = 19.564380%
8 successes:          172489 = 17.248883%
9 successes:          120243 = 12.024288%
10 successes:           70248 =  7.024793%
11 successes:           35407 =  3.540696%
12 successes:           15638 =  1.563798%
13 successes:            6276 =  0.627599%
14 successes:            2343 =  0.234300%
15 successes:             785 =  0.078500%
16 successes:             276 =  0.027600%
17 successes:              70 =  0.007000%
18 successes:              24 =  0.002400%
19 successes:               5 =  0.000500%
20 successes:               1 =  0.000100%
Average result: 7.198898

-- Number of rolls generating n successes from a 10 dice pool --
0 successes:              15 =  0.001500%
1 successes:             263 =  0.026300%
2 successes:            2193 =  0.219300%
3 successes:           10228 =  1.022799%
4 successes:           32470 =  3.246997%
5 successes:           74648 =  7.464793%
6 successes:          130646 = 13.064587%
7 successes:          174249 = 17.424883%
8 successes:          183572 = 18.357182%
9 successes:          156223 = 15.622284%
10 successes:          110777 = 11.077689%
11 successes:           65321 =  6.532093%
12 successes:           33589 =  3.358897%
13 successes:           15443 =  1.544298%
14 successes:            6373 =  0.637299%
15 successes:            2619 =  0.261900%
16 successes:             944 =  0.094400%
17 successes:             294 =  0.029400%
18 successes:              89 =  0.008900%
19 successes:              34 =  0.003400%
20 successes:               7 =  0.000700%
21 successes:               4 =  0.000400%
Average result: 7.997856
Title: Re: I need help with a dice math problem
Post by: chaviro on June 16, 2009, 11:06:37 AM
Hi,

I cannot resist a math problem  ;)

Assuming that your single dice works as follows
1-2 nothing
3-6 1 success + reroll if 6

The simplest way to compute the odds of success is, to me, to compute the
probability distribution for a single die. For n dice, you'll just use the
binomial law (don't worry, I'll do the maths below).
So, let's proceed.

With a single die, the distribution is as follows

2/6 : 0 success
1/6*(3 + 2/6) : 1 success
1/6*1/6*(3 + 2/6): 2 success
...
1/(6 to the n)*(3 + 2/6) : n success

The fact is that, contrary to what one usually thinks (feels), the exploding
die has few consequences on the odds ; a little biais up, no more.

Let's call E(1, n) the above probability of getting n success with a die, and
E(0,n) = 0 (and you know that E(k,0) = (2/6 to the k)).  From this, you may
compute the odds of getting E(k,n), the exact probability of getting n success
with k dice recursively :

E(k,n) = k times the sum for i = 1 to n of E(1,n-i)*E(k-1,i)

Well, I suppose this does not help you as much as a bunch of numbers and a nice
curve, so I give you my results, which I hope are correct (I'm rather sure of myself on this one, though) :

1 die
0       0.3333%
1       0.5556%
2       0.0926%
3       0.0154%
4       0.0026%
5       0.0004%

2 dice
0       0.1111%
1       0.3704%
2       0.3704%
3       0.1132%
4       0.0274%
5       0.0060%
6       0.0012%
7       0.0002%

3 dice
0       0.0370%
1       0.1852%
2       0.3395%
3       0.2795%
4       0.1123%
5       0.0344%
6       0.0092%
7       0.0022%
8       0.0005%
9       0.0001%

4 dice
0       0.0123%
1       0.0823%
2       0.2195%
3       0.2995%
4       0.2271%
5       0.1055%
6       0.0378%
7       0.0116%
8       0.0032%
9       0.0008%
10      0.0002%

5 dice
0       0.0041%
1       0.0343%
2       0.1200%
3       0.2296%
4       0.2637%
5       0.1927%
6       0.0975%
7       0.0390%
8       0.0134%
9       0.0041%
10      0.0012%
11      0.0003%

6 dice
0       0.0014%
1       0.0137%
2       0.0594%
3       0.1464%
4       0.2271%
5       0.2339%
6       0.1678%
7       0.0897%
8       0.0389%
9       0.0146%
10      0.0049%
11      0.0015%
12      0.0004%
13      0.0001%

7 dice
0       0.0005%
1       0.0053%
2       0.0276%
3       0.0831%
4       0.1628%
5       0.2187%
6       0.2093%
7       0.1487%
8       0.0826%
9       0.0381%
10      0.0153%
11      0.0055%
12      0.0018%
13      0.0006%
14      0.0002%

8 dice
0       0.0002%
1       0.0020%
2       0.0122%
3       0.0435%
4       0.1031%
5       0.1715%
6       0.2077%
7       0.1889%
8       0.1334%
9       0.0762%
10      0.0368%
11      0.0156%
12      0.0059%
13      0.0021%
14      0.0007%
15      0.0002%

9 dice
1       0.0008%
2       0.0052%
3       0.0215%
4       0.0597%
5       0.1186%
6       0.1747%
7       0.1959%
8       0.1715%
9       0.1207%
10      0.0705%
11      0.0354%
12      0.0157%
13      0.0063%
14      0.0023%
15      0.0008%
16      0.0003%

10 dice
1       0.0003%
2       0.0022%
3       0.0101%
4       0.0323%
5       0.0748%
6       0.1300%
7       0.1743%
8       0.1842%
9       0.1567%
10      0.1100%
11      0.0654%
12      0.0338%
13      0.0156%
14      0.0065%
15      0.0025%
16      0.0009%
17      0.0003%

At least, they seem to match the numbers from the Monte Carlo method (and
should be more accurate, especially on the lower and higher ranges of the
curve). Note that I truncated probabilities which are less than 0.0001%.

Chaviro
Title: Re: I need help with a dice math problem
Post by: Wordman on June 16, 2009, 02:45:52 PM
Quote from: chaviro on June 16, 2009, 11:06:37 AMAt least, they seem to match the numbers from the Monte Carlo method (and
should be more accurate, especially on the lower and higher ranges of the
curve).
Sweet! Thanks for that. Good to see that they add up!

One nitpick with chaviro's tables, using the 1 die, 0 success entry as an example. To be pedantically correct, should be either "33.33%" or just "0.3333" without the % sign.

Chaviro's is right that his math will give you more accurate numbers. And more quickly as well! And with fewer bugs!
Title: Re: I need help with a dice math problem
Post by: chaviro on June 17, 2009, 05:08:25 AM
Quote from: Wordman on June 16, 2009, 02:45:52 PM
To be pedantically correct, should be either "33.33%" or just "0.3333" without the % sign.
You're right :) Thank you.