Expressing game mechanics involving several dice as a single random variable

67 Views Asked by At

I want to know how can be expressed mathematically (if at all!) a certain game mechanic that produces a single number by rolling several dice and making decisions based on the results. I'm lost at how to express it, as it is not a simple linear combination or condition. My intent is to understand well the mathematical expression of the algorithm and to know if it's possible to compute more effectively (by hand and with software) values like expected value and variance, or if it's necessary to just find out the Probability Mass Function for the whole system, and calculate from there.

The mechanic is an attack sequence similar to many RPG games, where a first die roll determines success or failure in an attack, and success means rolling more dice to find how much damage was dealt. It is a tiny bit more involved than typical D&D, but here is a simplified example with some fixed values for simplicity:

  1. Roll a $20$ sided die, and if the value is $5$ or lower is a miss, but still produces $3$ damage. No need to roll anything more.
  2. If the previous roll was $6$ or higher it was a hit. Roll a standard $6$ side die, and if a $5$ or $6$ is rolled it was a traumatic hit, otherwise it was a normal hit.
  3. Roll a $10$ sided die for the amount of damage dealt. If a traumatic hit was rolled before, the damage is multiplied by $3$. Otherwise is just the amount just rolled.

It is reasonably easy to make the PMF for this:

  • $25\%$ of chance of failure, which produces a result of $3$.
  • 50% of regular hit, which will produce the results from $1$ to $10$ with 5% chance each.
  • $25\%$ of the trauma hit, which again is split in the results $3, 6, 9\ldots$ up to $30$ (because it's $1, 2, 3,$ etc. multiplied by $3$), each with $2.5\%$ chance.

Just adding the probabilities of the different outcomes would work, if I'm not mistaken, and from the Probability Mass Function we can get variance and mean, etc.

But since each die individually is much simpler and (mean and variance can be easily obtained), I would like to know if an algorithm like this can be expressed as some sort of combination of its parts in a way that could be simpler and more understandable.

EDIT: To summarize and clarify, I'd like to know if we can write that algorithm as a single random variable $X$ which is a function of the other random variables, using conditionals and linear combinations: the "to hit" roll $H$, the trauma roll $T$ and the damage roll $D$. Something like

$$ X = p_{H \le 5} · 3 + p_{H \ge 6} · D ( p_{T \le 4 } · 1 + p_{T \ge 5} · 3) $$

The above doesn't make entire sense, but it's along the lines of what I was trying to (unsuccessfully) express. If that were possible, I could use for example the propagation formulas for variance to calculate the variance based on the variance of the individual dice rolls. Likewise for expected value, etc. I would not be surprised if this isn't possible, but I need to ask. :-)

Thank you.

2

There are 2 best solutions below

1
On BEST ANSWER

At best, your proposed expression for $X$ is highly unusual; I don't think I have ever seen the letter $p$ used this way. Usually $p$ (with or without a subscript) in this context would represent a probability, which is simply a number, not a random variable.

I think some form of Iverson brackets would best provide what you are looking for:

$$ [P] = \begin{cases} 1 & \text{if } P \text{ is true;} \\ 0 & \text{otherwise}. \end{cases} $$

Using this notation,

$$ X = [H \leq 5]\cdot 3 + [H \geq 6]\cdot D( [T \leq 4]\cdot 1 + [T \geq 5]\cdot 3).$$

Equivalently,

$$ X = [H \leq 5]\cdot 3 + [H \geq 6 \land T \leq 4]\cdot D + [H \geq 6 \land T \geq 5]\cdot 3D. $$

Note that you could get the same distribution (but perhaps have less fun rolling for damage) if you let

$$ X = [H \leq 5]\cdot 3 + [6 \leq H \leq 15]\cdot D + [H \geq 16]\cdot 3D. $$

Each of these Iverson brackets is a Bernoulli variable, so the expectation is easily computed. For variance, you could use the formula $\operatorname{Var}(X) = \mathbb E(X^2) - (\mathbb EX)^2,$ where

$$ X^2 = [H \leq 5]\cdot 9 + [H \geq 6 \land T \leq 4]\cdot D^2 + [H \geq 6 \land T \geq 5]\cdot 9D^2. $$

You can also use moments of $X$ (expected values of powers of $X$) to compute kurtosis when you want to.

0
On

One amusing way to organize the calculation makes use of composition of polynomial generating functions.

The normal damage done by a normal hit is a random variable we can denote by N whose associated probability distribution function & damage values can be encoded by the polynomial $\tilde N(d)= \sum_{k=1}^{10} \frac{1}{10} d^k$. Here $d$ is a dummy symbol. Then the tripled damages associated to a traumatic hit are $\tilde N(d^3)$. All the other layers in your flow chart are just binary outcomes, which have even simpler polynomial representations. (I will use words rather than letters to represent those binary outcomes, but you should think of the outcomes as algebraic symbols or input/output variables in a chain of functional relations.)

Step 1. = p Miss + q Hit where Miss= $d^3$.

Step 2. Hit= p Traumatic hit + q Normal hit

Step 3. Normal hit = $\tilde N(d)$ and Traumatic hit = $ \tilde N(d^3)$.

Substituting each polynomial into the layer above you get a composite polynomial that encodes the probability distribution for the amount of damage from this chain of steps. These operations are easily encoded using eg Mathematica or other symbolic software packages.

The final polynomial $ P(d) =\sum_k p_kd^k$ satisfies these relations $ P(1)= \sum_k p_k =1$ (Law of Total probability)

$P'(1)= \sum_k (kp_k)$ = expected damage

$P''(1)= \sum_k (k(k-1) p_k $ = second moment - first moment

from which the variance is easily computed.

The real power of this method is that it can model Watson-Galton branching processes where the outcome of one roll of a die may trigger the opportunity to roll that or another die multiple times. These are chain reactions that can explode exponentially and can model biological reproduction and nuclear explosions, etc)

For example if the first roll of the damage die (say 6) tells you how many times you must roll that die (6 rolls) to determine the catastrophic total damage ( e.g. total points of damage tabulated from adding the outcome of those six rolls), then $ \tilde N ( \tilde N(d))$ describes the distribution of total damage computed at the end of that 2-branch process.