1
$\begingroup$

For context, I'm the author of ktcalc, a specialized calculator for Kill Team (a Warhammer 40K franchise game that uses d6 dice) that calculates exact probabilities of outcomes for ranged and melee attacks. I'm struggling on how to calculate the exact probability for d6 dice roll outcomes where the roller gets to choose which value/pip-count to reroll. (Wyrmblade's Cult Ambush ability has this reroll rule.)

Here's an example of the reroll rule in action: imagine 6 is critical success, 4 and 5 are normal success and 1-3 are fails. The attacker rolls {1,3,3,4,6}. 3 is the most common fail value, so he chooses to re-roll the two 3s. They come up {3,6}, so the final outcome is {1,3,4,6,6}, which more importantly is 2 fails, 1 normal success, and 2 critical successes.

With that re-roll ability, I want to calculate the probability of ending up with $n_c$ critical successes, $n_n$ normal successes, and $n_f$ failures. Other inputs are the probabilities of each roll being a critical success ($p_c$), normal success ($p_n$), or failure ($p_f$).

If there were no reroll abilities, the answer is:

$p_c^{n_c} \cdot p_n^{n_n} \cdot p_f^{n_f} \cdot \frac{(n_c + n_n + n_f)!}{n_c! \cdot n_n! \cdot n_f!}$

And you can see it in TypeScript here.

So, given $\{p_c,n_c,p_n,n_n,p_f,n_f\}$ and that the attacker will reroll the most common fail value, what is the probability of ending up with $n_c$ critical successes, $n_n$ normal successes, and $n_f$ failures?

For some other reroll abilities, you can handle them quite simply. For instance, rerolling $1$s (Ceaseless) can be handled by multiplying pre-reroll $p_c$ and $p_n$ by $7/6$ to get the post-reroll probabilities. Rerolling all failures (Relentless) can be handled by multiplying pre-reroll $p_c$ and $p_n$ by $1 + p_f$. Code here, and less elegant code to handle rerolling a single die (balanced) here.

UPDATE: I implemented a solution here. I basically iterate over all possibilities of how many of each fail type was rolled, with smart "collapsing" of similar outcomes (ex: {1,1,2} is similar to {2,2,1}). It's not as elegant as I originally hoped was possible, but it has some significant improvements over naive brute force.

$\endgroup$

1 Answer 1

0
$\begingroup$

I suggest using:

  • The chain rule, which allows you to express the final probability as the accumulation of products of conditional probabilities.
  • Memoization.

Specifically, you could split the probability into three factors:

  • Given an initial pool, how many dice fail?
  • Given a total number of failing dice, how many can be rerolled?
  • Given a number of rerolled dice, how many generate norms / crits?

Then combine either the first two to get:

  • Given an initial pool, how many rerolls / initial norms / initial crits are generated?

Or the last two to get:

  • Given a total number of failing dice, how many norms / crits are generated on the reroll?

Then you can combine this with the remaining factor to get the overall solution.

$\endgroup$
1
  • $\begingroup$ Yes, I'm increasingly thinking that I'll have to do this two-phase approach (with some precalculated tables), thanks. $\endgroup$
    – JacobEgner
    Commented Sep 13, 2022 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .