# Opposing d6 Pools, # of higher dice

I've read dozens of posts here, and wrestled with with anyDice suggested code, but nothing matches quite what I am looking for. I think it is simple in concept: for opposing dice pools of 1..6d6, I want to figure the probability of of higher dice.

In my case, the count of higher dice includes a dice with a higher face than the opponents highest, and/or a higher count of the opponent's highest face. A = 1234, B = 456: B nets 2 (5 and 6 > 4) A = 1233, B = 1223, A nets 1 (2 3s to 1 3) I want to analyze the probability of each 3 of higher dice for 2d6 versus 2..6d6. Any help would be appreciated.

The closest I've come is https://anydice.com/program/1f78d, but that just tells me the relative probability of X # of dice of the same face.

Thanks,

• John
• There might be a duplicate of this If I recall correctly, but maybe it was something similar instead - a quick search didn't show that q though. Commented Dec 23, 2020 at 0:27
• Welcome to asking questions on rpg.se btw, I hope you find an answer soon. Please take the tour if you haven't already or check out the help center for a faq query. Commented Dec 23, 2020 at 0:28
• Just to clarify, would 1234 vs. 446 be counted as net 2?
– G_B
Commented Dec 24, 2020 at 4:32

function: A:s vs B:s {
if 1@A = 1@B { result: (A = 1@A) - (B = 1@B) }
else { result: (A > 1@B) - (B > 1@A) }
}

loop N over {2..7} {
output [Nd6 vs 2d6] named "[N]d6 vs 2d6"
}


It makes use of the following AnyDice features:

1. Passing a dice roll to a function expecting a sequence (i.e. as a parameter tagged with :s) "freezes" the roll: AnyDice will automatically call the function for every possible outcome of the roll and tally up the results.
2. When enumerating the possible outcomes of a dice roll, AnyDice always sorts the rolled numbers from highest to lowest. Thus, 1@ will return the highest die roll in each pool.
3. When a sequence is compared with a number, AnyDice will compare each element of the sequence with the number and count the number of true comparisons.

Thus, we have two cases:

• If the highest rolls in each pool are the same (i.e. if 1@A = 1@B), we count the number of times that highest roll occurs in pool A (with A = 1@A), subtract from it the number of times it occurs in pool B (i.e. B = 1@B) and return the difference.
• Otherwise we count the number of rolls in pool A that exceed the highest roll in pool B (with A > 1@B) and subtract from it the number of rolls in pool B that exceed the highest roll in pool A (i.e. B > 1@A). (Of course, only one of these two counts can be non-zero.)

## If you want to do introspection on a dice pool, you need functions

One thing we can do in Anydice is to cast dice into a sequence. The sequence can be treated as a rolled dice pool and the function will be analysed over all possible rolls giving us our probabilities.

Armed with that our method then becomes fairly straight forward. For our opponent pool (B) we only care about the highest and since a dice pool cast as a sequence will be sorted in descending order, we can simply take the first; 1@B. We then count all the dice values higher than 1@B in A. If that count is 0 (ie. none of our dice are higher than the opponents highest) we count the number that is equal to 1@B and return that instead.

You can see this implemented in the following Anydice program

D: 6

function: number higher in A:s over B:s
{
C: [count {1@B+1..D} in A]
if C = 0 { C: [count 1@B in A] }
result: C
}

loop N over {2..6} {
output [number higher in 2dD over NdD] named "[N]d[D] higher dice v 2d[D]"
}

• Thanks so much! Off the cuff looks like the only thing missing is the chances of the 2d6 having the higher dice (which I'd think would show as -1 and -2). I'll play around with this, thanks again. Commented Dec 23, 2020 at 17:41
• @JohnTroxel Oh, I think I've misunderstood the rolling method. If the opponent has strictly a higher dice should the count not be 0? Commented Dec 23, 2020 at 18:04

I ended up with the following, taking into account the # of dice when the highest face is a tie. I think it works, nice even distribution at even numbers, skewing toward the advantage of having a larger pool without making it instantly OP.

\ Dice pool higher dice, ties on highest face use higher count \
\ D is the size of the dice \
\ Successes are scored on all dice higher than opposing highest, or on the higher # of dice for ties on the highest face \

D: 6

function: number higher in A:s over B:s
{
if 1@A != 1@B { result: [count {1@B+1..D} in A] - [count {1@A+1..D} in B] } \ Diff of higher As = higher Bs \
result: [count {1@B} in A] - [count {1@A} in B] \ Diff the _count_ of highest \
}

loop N over {2..7} {
output [number higher in NdD over 2dD] named "[N]d[D] higher dice v
2d[D], ties count"
}