# Help with probability for a complicated dice pool mechanic

I'm putting together a system with experimental dice mechanics. I want to know the probabilities involved, preferably in a way such as anyDice where I can easily change all variables and get the probability results without having to have a degree in maths to figure it out.

### This is the simple part.

The core mechanic would be that a player puts together a pool of dice and rolls them against a target number from 2-6. Every die that equals or exceeds the target number is a hit.

### Where it gets complex

In that pool are positive dice equal to the skill of the player and negative dice equal to skill of an NPC opponent. Hits on negative dice cancel out positive hits of equal or lower value. Any remaining hits are counted and used to determine results.

• Example: a player has a skill of 5 and is performing an action with a TN of 4 against an opponent with a skill of 3. This creates a pool of 5 positive dice which come up 1,2,4,4,6 and 3 negative dice that come up 2,4,5. The 1 and 2 on the positive dice are set aside as well as the 2 on the negative dice leaving 3 positive hits (4,4,6) and 2 negative hits (4,5). The negative 4 cancels out one of the positive 4s and the negative 5 cancels out the other negative 4 leaving the positive 6 for a net total of 1 positive hit.

I'm looking for the probability of getting X number of net positive hits given various numbers of positive dice, negative dice, and target numbers.

As a separate mechanic that could be layered onto the core mechanic I am considering the ability to "boost" or "drain" a pool by adding a number of dice to the positive dice (or I suppose the negative too) before the roll and then subtracting the same number of either the lowest/highest results before determining hits.

For example: if the positive dice pool of 5 was boosted by 2 you would roll 7 positive dice and drop the two lowest results before determining hits. I'm curious how much of a statistical difference this would make given different sized pools compared to changing the target number or simply adding/subtracting dice from the pool straight up.

### Why do I need this?

The mechanic is actually the starting point on this one. I'm trying to see if it can be made into something functional but without solid probability data I'm mostly just playing things by ear.

Here you have it on AnyDice to test it.

Here the code. You can subsitute the "difficulty", "myroll" and "hisroll" to test different situations. Also, if you know a bit about AnyDice, can create different outputs to test how change a variation in skills or difficulty.

function: difficulty X:n myroll A:s hisroll B:s {
RESULT: 0
loop V over {X..6} {
RESULT: RESULT + (V = A) - (V = B)
}
result: RESULT
}

output [difficulty 3 myroll 3d6 hisroll 3d6]


I'll be happy to implement the Boost or Drain if you could be more specific about how it works.

Mathematically, this is two opposed binomial distributions, which is pretty easy to construct, and should be even easier to code. Let's define n as the number of dice in the positive roll and m as the number of dice in the negative roll. I'll assume for this that t, the target number, and d, the number of sides, are the same for the two rolls.

As a standard rule, I define a target number as "equal to or greater than", so our states S (Success) and F (Failure) look like this for both positive and negative rolls:

$$S=\frac{d-t+1}{d},F=\frac{t-1}{d}$$

If we just want to pull out the entire probability, we can just use the generating function/convolution approach. The entire probability distribution can be generated by calculating:

$$F(z)=\left(\frac{(d-t+1)z+(t-1)}{d}\right)^n\left(\frac{(d-t+1)z^{-1}+(t-1)}{d}\right)^m$$

And you'll get the probability for each possible number of successes by looking at the coefficients of each power of z. This is very easily done via Wolfram Alpha - just replace the variables with your chosen numbers and WA will do all the heavy lifting. In fact, taking your example above, Wolfram gives the full distribution as:

$$\frac{8}{6561}z^5 + \frac{92}{6561}z^4 + \frac{446}{6561}z^3 + \frac{1181}{6561}z^2 + \frac{1850}{6561}z^1 + \frac{1736}{6561}z^0 + \frac{944}{6561}z^{-1} + \frac{272}{6561}z^{-2} + \frac{32}{6561}z^{-3}$$

Of course, since we have the generating function, we can also use this to quickly determine the expected value of a given roll (for the math-heads, you can get the expected value of a roll from the generating function by finding the function's derivative, then setting z=1):

$$E(H)=\frac{(n-m)(d-t+1)}{d}$$

This makes an intuitive amount of sense - each positive and negative die has the same probability of a hit, and since negative and positive dice cancel, you'd expect the number of successes to be proportional to the difference in dice pools.

If you want to generate just the probability of a specific number of net successes, that formula is pretty easy to build - at it's base, we have two binomial distributions, and we just need add together all combinations that land us at h, which would be:

$$P(H=h)=\sum_{k=\max(0,-h)}^{\min(n,m)}\binom{n}{h+k}\left(\frac{d-t+1}{d}\right)^{h+k}\left(\frac{t-1}{d}\right)^{n-h-k}\binom{m}{k}\left(\frac{d-t+1}{d}\right)^{k}\left(\frac{t-1}{d}\right)^{m-k}$$

Which we can simplify down to:

$$P(H=h)=\sum_{k=\max(0,-h)}^{\min(n,m)}\binom{n}{h+k}\binom{m}{k}\left(\frac{d-t+1}{d}\right)^{h+2k}\left(\frac{t-1}{d}\right)^{n+m-h-2k}$$

Finally, if you wanted to find the probability of any positive result, you'd just sum for h=1 up to h=n:

$$P(H>0)=\sum_{h=1}^{n}\sum_{k=0}^{\min(n,m)}\binom{n}{h+k}\binom{m}{k}\left(\frac{d-t+1}{d}\right)^{h+2k}\left(\frac{t-1}{d}\right)^{n+m-h-2k}$$

(note: the inner sum changes the start point because if you're only summing positive h then max(0,-h) will always equal 0)