Interactive Dice Test Probability Webpage

Thanks, it was pretty fun to build and I got to justify spending work time on it since I was learning dash.

I’m not sure how much detail you’d like me to go into, but I’m using generating functions to do this. They basically take advantage of the fact that multiplying polynomials works the same way as calculating probabilities, but are a lot easier to write and work with once you wrap your head around them. The heart of this is in these lines of the code.

The function I used for a single die of open-ended black shade skills is open-ended-roll . The coefficients of x^n correspond to the probability of n successes. For example x^0 is 1/2, so there’s a 50% of getting 0 successes (rolls of 1, 2, or 3). The coefficient of x^1 is 5/12, which corresponds to a roll of 4 or 5, or a 6 when the exploded die rolls a 1, 2, or 3 the probability of this is 1/2 (2/3 + 1/3 * 1/2). I actually calculate the second and third terms in the code.

p_1 = success_chance*(dud_chance + explode_chance*failure_chance)
p_2 = success_chance*explode_chance*success_chance*(dud_chance + explode_chance*failure_chance)

success_chance and failure_chance are 1/2 for black shade skills, explode_chance is 1/3 because it’s the probability of a success exploding, and dud_chance is 2/3. The series is infinite and has non-zero values for arbitrarily high successes. This is because you could theoretically roll any number of sixes, however unlikely, before rolling something besides a 6 and there is a small chance of rolling an arbitrary number of successes.

Now that we have a polynomial whose coefficients correspond to probabilities of one die, getting the odds of multiple dice is just multiplying the polynomial by itself. This does the hard work of tracing out every path to get to, for example, 6 successes whether it’s by rolling six 4s or a 6, five 4s, followed by four 6s and a 4 from exploding dice. I used the sympy library to do the multiplication. Then I just checked the coefficients up to x^10 (Ob 10).

I use this same method for non-open-ended (…closed-ended?) tests as well. There the equation is just failure_chance + success_chance*x. There are easier ways to do it, but I was already doing it for the exploding dice. I haven’t yet done anything with re-rolling failures like Luck on an open-ended skill, Saving Grace, or Call-On Traits. That’s next.

4 Likes