# Help calculating opposing dice pool in AnyDice

I need to calculate the probability of A winning against B. Both A and B throw 1-15 d6s, the one with more successful dice (SD) wins.

There are actually 5 possibles outcomes:

• CF: A's SD < B's SD -3
• F: A's SD < B's SD
• DR: A's SD = B's SD
• S: A's SD > B's SD
• CF: A's SD > B's SD +3

A die can give 4 different outcomes:

• Roll 1: -1 SD
• Roll 2-3: 0 SD
• Roll 4-5: +1 SD
• Roll 6: +2 SD

I want to see the probability of A outcomes in different situations, with the number of dice for A and B going from 1 to 15.

I've done something in AnyDice, but looking further into the documentation I think I completely messed up:

function: singledice DICE:n{
if DICE = 1 {result : -1 }
if DICE = 2 {result : 0 }
if DICE = 3 {result : 0 }
if DICE = 4 {result : 1 }
if DICE = 5 {result : 1 }
if DICE = 6 {result : 2 }
}

function: throw A dices{
X: 0
loop N over{1..A}{
X : X + [singledice d6]
}
result: X
}

function: players K and L{
CF:0
F:0
DR:0
S:0
CS:0
loop G over{1..K}{
loop H over{1..L}{
C:[throw G dices]-[throw H dices]
if C < -3 {CF:CF+1}else
if C < -1 {F:F+1} else
if C = 0 {DR:DR+1}else
if C = 1 {S:S+1}else
if C = 2 {S:S+1}else
if C > 2 {CS:CS+1}
}
}
result: {CF, F, DR, S, CS}
}

loop M over{1..15}{
loop U over{1..15}{
output [players M and U] named "[M] vs [U]"
}
}


Answered by Jasper Flick, the creator of AnyDice: http://anydice.com/program/6268

Here is the code

function: check A:n vs B:n {
if A < B - 3 { result: -2 } \ CF \
if A < B { result: -1 } \ F \
if A > B + 3 { result: 2 } \ CS \
if A > B { result: 1 } \ S \
result: 0 \ DR \
}

SD: d{-1, 0:2, 1:2, 2}

loop A over {1..15} {