# Subtracting opposed dice in Anydice

In some games, opposed dice rolls are subtracted. An example (although this is a boardgame, not an rpg) is Twilight Struggle. Not only is it important to determine who won, but by how much. A similar situation would be when the DM creates a mechanic where opposed skill checks on say d20s are compared (who won by the most). I'm wondering how to do this in anyDice.

What is an easy way of doing this in anyDice?

• Hi aphid, welcome to rpg.se! Take the tour and visit the help center or ask here in the comments (use @ to ping someone) for more information. Thanks for contributing and happy gaming! Commented May 27, 2020 at 6:48

# Simply Subtract the Dice Pools

From AnyDice's documentation on Dice:

You can perform operations on dice as if they were numbers, in which case the operation gets applied to all individual numbers on the dice.

Since AnyDice supports subtraction and the creation of custom dice pools you can simply subtract the dice pools to get the results distribution. To compare two d20s :

output 1d20 - 1d20

This syntax can also support more complex pools:

output (2d10+1d4) - (1d20+1d6)

You can see the results from these programs here.

It turns out that for any die $$\D = \text{d}N\$$, the formula $$\D' = \text{d}N - (N + 1)\$$ creates a die $$\D'\$$ that is the result of subtracting such a die. Sure, for for example a d6, rolls of 6 are treated as 1, 5 as 2, 4 as 3, this does not actually change the probabilities at all, and such a black box communicating the result would be indistinguishable (the numbers are inverted).

So to subtract 2 identical dice (using d6es as an example) the result would just be to roll $$\2\text{d}6 - 7\$$. For a d20 example, the result would be $$\2\text{d}20 - 21\$$

• It would be simple to just negate the die: while d6 - 7 indeed has the same distribution as -d6, the latter is a lot simpler and more readable. (Also, the equivalence doesn't hold for custom dice with non-symmetric distributions.) Commented May 28, 2020 at 7:42