# Probability for the occurrence of each outcome in dice game

For a fictitious dice game, there is the following rules:

Rules

if ('player A dice roll' = 3 OR 'player A dice roll' < 10 + 'player B bonus' - 'player A bonus') {
Outcome 1: player_A fails and player_B automatically wins.
} else {
if ('player B dice roll' = 18 OR ('player B dice roll' > 3 AND 'player B dice roll' >= 10 + 'player A bonus' - 'player B bonus' AND 'player B dice roll' => 'player A dice roll')) {
Outcome 2: player_B beats player_A: player_B wins, player_A loses.
} else {
Outcome 3: player_B does not beats player_A: player_A wins, player_B loses.
}
}


Where:
- 'player N dice roll' is the sum of 3 (six sided) dice.
- A roll of 3 is always a failure, a roll of 18 is always a success.
- 'player N bonus' is (whole) number between -10 and 10.

I want to find out the probability for the occurrence of each outcome, but I failed. I can write a script that simply throws the dice and keeps track of the results. Let the script loop for say 10,000,000 times and the outcome is pretty close to the actual probabilities, but (funnily enough) 10,000,000 tries still leaves a fair margin of error in the outcome.

I don't like margin of errors, so I would like to calculate the probabilities instead. BUT I don't know how to calculate it. I tried, but the solution just eludes me :-(

How can I calculate probability for the occurrence of each outcome as described above?

(Bonus points for an explanation which is understandable for someone with rusty math skills)

Update
Since I don't know how to describe the above rules in a mathematical notation, I decided to describe the rules in a less abstract way.

Player A: the $Human$.
Player B: the $Orc$.

The $Human$ attacks the $Orc$. The outcome of the attack is determined by rolling 3 (six sided) dice. A combined roll of 3 is always a failure, a combined roll of 18 is always a success.

The $Human$ needs a combined dice roll to be greater than $10 + Bonus_{(Orc)} - Bonus_{(Human)}$ to hit the $Orc$; a combined roll of 3 is always a failure.

If the $Human$ makes a successful attack against the $Orc$, the $Orc$ gets to defend itself.
The $Orc$'s combined dice roll needs to be greater than or equal to $10 + Bonus_{(Human)} - Bonus_{(Orc)}$ AND needs to be equal to or better than the $Human$'s dice roll ( $DiceRoll_{(Orc)} >= DiceRoll_{(Human)}$ ). Of course, a combined roll of 3 is an automatic failure for the $Orc$ to defend itself and on a combined dice roll of 18 the $Orc$ automatically defends itself successfully.

I'm not sure this is any more clear than the rules as described above, but I don't know how to make it more clear otherwise.

• What do you mean by BONUS POINTS? I didn't know MathsSE had Bonus points to award. – SchrodingersCat Oct 29 '15 at 17:26
• Your question is extremely unclear. Please use proper mathematical notation instead of relying on us to reverse-engineer your code. – barak manos Oct 29 '15 at 17:30
• I don't know how to write this in mathematical expressions? How can I improve it? – Monika Oct 29 '15 at 19:25
• Is the BONUS constant for each player over the rounds? – rightskewed Nov 7 '15 at 0:04
• @rightskewed, yes. the bonus is intended to stays constant for the duration of a round. Once the round ha been concluded (somebody won and somebody lost) the players could roll again with a different bonus. – Monika Nov 7 '15 at 18:06

The problem of determining the probability of occurrence of a score $n$ rolling three dice (with $n$ integer ranging between $3$ and $18$) reduces to the problem of determining the number of "restricted" partitions of $n$ (i.e., way of writing $n$ as a sum of positive integers, with the restriction that the sum has to contain exactly three integers). Each valid partition must then be multiplied by the number of possible permutations. For example, $n=4$ has only one valid restricted partition ($2,1,1$), which must be multiplied by three to account for the possible three combinations $2,1,1-1,2,1-1,1,2$. More generally, if three different numbers form the partition (e.g., $8$ as $8 = 1 + 3 + 4$), there are $3!$ different ways of permuting these numbers, so that the partition corresponds to six outcomes in the sample space. On the other hand, if two different numbers form the partition (e.g., $4$ as $2+1+1$), then there are three different ways of permuting these numbers, so that the partition corresponds to three outcomes in the sample space. When the partition has all equal numbers (e.g., $6$ as $6=2+2+2$), clearly the partition corresponds to a single outcome.

Taking into account these considerations, and knowing that rolling three dice there are $6^3=216$ total outcomes, we can calculate the probability for each $n$:

$$n=3: 1/216 = 0.5\%$$ $$n=4: 3/216 = 1.4\%$$ $$n=5: 6/216 = 2.8\%$$ $$n=6: 10/216 = 4.6\%$$ $$n=7: 15/216 = 7.0\%$$ $$n=8: 21/216 = 9.7\%$$ $$n=9: 25/216 = 11.6\%$$ $$n=10: 27/216 = 12.5\%$$

It is not necessary to calculate the probabilities for $n=11,12,13...18$, since they are symmetric with those shown above.

Applying this to the OP, if we define $k$ the difference between player B bonus and player A bonus, we have that player A needs a total combined dice roll greater than $10+k$ to hit player B (and in order not to lose). The probability of this event can be obtained by summing the corresponding probabilities above. For instance, if $k=3$, then player A needs a total combined dice roll greater than $10+3=13$. We then have to sum the probabilities of occurrence of $n=14,15...18$. Since these symmetrically correspond to the probabilities of occurrence of $n=3,4...7$, we get $$\frac{1+3+6+10+15}{216}=\frac{35}{216}=16.2\%$$

The same calculations can be used to determine the probability that player B defends successfully. In the example above, he must obtain a combined dice roll greater than or equal to $10-3=7$ and greater than or equal to the result of player A. If, for example, player A had obtained a total of $12$, we then have to sum the probabilities of occurrence of $n=12,13...18$. Again, since these symmetrically correspond to the probabilities of occurrence of $n=3,4...9$, we get $$\frac{1+3+6+10+15+21+25}{216}=\frac{81}{216}=37.5\%$$

These calculations also allow to take into account the condition that a roll of $3$ is always a failure and a roll of $18$ is always a success. We only have to check whether the occurrences of combined roll equal to $3$ and equal to $18$ are already correctly included in the calculations. In the example above where $k=3$ and where player A needs a total combined dice roll greater than $10+3=13$ to hit, we have summed the probabilities of occurrence of $n=14,15...18$. So, the occurrence of $18$ is already correctly counted as a success, whereas that of $3$ has already been considered as a failure (in fact, it has not been counted).

As another example, if $k=9$, then player A would need a total combined dice roll greater than $10+9=19$ to hit. Clearly he cannot obtain such result, since the maximal value obtainable with three dice is $18$. However, under the condition that $18$ always implies a success, now we have to consider it within his possible successful outcomes. In this case, the successful occurrence of $18$ has still NOT already considered in the calculations, so that we have to add it. The resulting probability of success for player A is then equal to that of obtaining $18$, i.e. $\frac{1}{216}$. Also note that, in this example, the occurrence of $3$ is already considered as a failure (in fact, it has not been counted).

Lastly, similar considerations can be applied to take into account the condition that a roll of $3$ is always a failure and a roll of $18$ is always a success for player B as well.

• Does this answer take into consideration that a combined roll of 3 is always a failure, a combined roll of 18 is always a success? – Monika Nov 7 '15 at 18:12
• Yes, it takes it into account. I edited my answer to better explain it. – Anatoly Nov 7 '15 at 18:51
• Hi Monika, is it all OK with my explanation? – Anatoly Nov 8 '15 at 8:30
• Thank you, your explanation is Ok, It helps me understand how to do the calculation myself. The bounty should be yours. – Monika Nov 10 '15 at 10:17

It's actually quite fortunate that you used pseudocode.

With a sufficiently expressive language, it is possible to implement a monadic structure that allows one to compute such probabilities exactly (to machine precision). For example, using a definition of Distribution[X] as in this piece of code (beginning at line 105), your pseudocode can be translated into the following:

object Dice extends Distribution[Int] {
def sample = 1 + math.floor(math.random * 6).toInt
def integral(f: Int => Double) =
(f(1) + f(2) + f(3) + f(4) + f(5) + f(6)) / 6.0
}

// roll three dices, sum up the three values
val diceRoll = Dice.pow(3).map{ _.sum }

// Possible outcomes of the game:
// essentially just Boolean with a fancy name.
sealed trait Outcomes
case object aWins extends Outcomes
case object bWins extends Outcomes

for {
aBonus <- (0 to 10)
bBonus <- (0 to 10)
} {
// outcome-random-variable, defined by your game rules
val outcome = for {
a <- diceRoll
b <- diceRoll
} yield {
if (a == 3 || (a < 10 + bBonus - aBonus)) {
bWins
} else {
if (
b == 18 ||
(b > 3 && b >= 10 + aBonus - bBonus && b >= a)
) {
bWins
} else {
aWins
}
}
}

// print the (exact!) probability for A to win:
printf(
"aBonus = %2d bBonus = %2d P[aWins] = %.8f\n",
aBonus, bBonus, outcome.prob( _ == aWins)
)
}


For each possible combination of aBonus and bBonus, this code creates a probability distribution called outcome that can produce values aWins or bWins. This probability distribution is described by a direct 1:1 translation of your pseudocode. It computes the probabilities exactly, and prints them in one big table.

Here are the exact values for all combinations of aBonus and bBonus:

aBonus = -10 bBonus = -10 P[aWins] = 0.39866255
aBonus = -10 bBonus = -9 P[aWins] = 0.35178755
aBonus = -10 bBonus = -8 P[aWins] = 0.28928755
aBonus = -10 bBonus = -7 P[aWins] = 0.21694959
aBonus = -10 bBonus = -6 P[aWins] = 0.14493313
aBonus = -10 bBonus = -5 P[aWins] = 0.08674126
aBonus = -10 bBonus = -4 P[aWins] = 0.04473165
aBonus = -10 bBonus = -3 P[aWins] = 0.01823988
aBonus = -10 bBonus = -2 P[aWins] = 0.00460820
aBonus = -10 bBonus = -1 P[aWins] = 0.00000000
aBonus = -10 bBonus =  0 P[aWins] = 0.00000000
aBonus = -10 bBonus =  1 P[aWins] = 0.00000000
aBonus = -10 bBonus =  2 P[aWins] = 0.00000000
aBonus = -10 bBonus =  3 P[aWins] = 0.00000000
aBonus = -10 bBonus =  4 P[aWins] = 0.00000000
aBonus = -10 bBonus =  5 P[aWins] = 0.00000000
aBonus = -10 bBonus =  6 P[aWins] = 0.00000000
aBonus = -10 bBonus =  7 P[aWins] = 0.00000000
aBonus = -10 bBonus =  8 P[aWins] = 0.00000000
aBonus = -10 bBonus =  9 P[aWins] = 0.00000000
aBonus = -10 bBonus = 10 P[aWins] = 0.00000000
aBonus = -9 bBonus = -10 P[aWins] = 0.47215792
aBonus = -9 bBonus = -9 P[aWins] = 0.39866255
aBonus = -9 bBonus = -8 P[aWins] = 0.35178755
aBonus = -9 bBonus = -7 P[aWins] = 0.28928755
aBonus = -9 bBonus = -6 P[aWins] = 0.21694959
aBonus = -9 bBonus = -5 P[aWins] = 0.14493313
aBonus = -9 bBonus = -4 P[aWins] = 0.08674126
aBonus = -9 bBonus = -3 P[aWins] = 0.04473165
aBonus = -9 bBonus = -2 P[aWins] = 0.01823988
aBonus = -9 bBonus = -1 P[aWins] = 0.00460820
aBonus = -9 bBonus =  0 P[aWins] = 0.00000000
aBonus = -9 bBonus =  1 P[aWins] = 0.00000000
aBonus = -9 bBonus =  2 P[aWins] = 0.00000000
aBonus = -9 bBonus =  3 P[aWins] = 0.00000000
aBonus = -9 bBonus =  4 P[aWins] = 0.00000000
aBonus = -9 bBonus =  5 P[aWins] = 0.00000000
aBonus = -9 bBonus =  6 P[aWins] = 0.00000000
aBonus = -9 bBonus =  7 P[aWins] = 0.00000000
aBonus = -9 bBonus =  8 P[aWins] = 0.00000000
aBonus = -9 bBonus =  9 P[aWins] = 0.00000000
aBonus = -9 bBonus = 10 P[aWins] = 0.00000000
aBonus = -8 bBonus = -10 P[aWins] = 0.57863940
aBonus = -8 bBonus = -9 P[aWins] = 0.47215792
aBonus = -8 bBonus = -8 P[aWins] = 0.39866255
aBonus = -8 bBonus = -7 P[aWins] = 0.35178755
aBonus = -8 bBonus = -6 P[aWins] = 0.28928755
aBonus = -8 bBonus = -5 P[aWins] = 0.21694959
aBonus = -8 bBonus = -4 P[aWins] = 0.14493313
aBonus = -8 bBonus = -3 P[aWins] = 0.08674126
aBonus = -8 bBonus = -2 P[aWins] = 0.04473165
aBonus = -8 bBonus = -1 P[aWins] = 0.01823988
aBonus = -8 bBonus =  0 P[aWins] = 0.00460820
aBonus = -8 bBonus =  1 P[aWins] = 0.00000000
aBonus = -8 bBonus =  2 P[aWins] = 0.00000000
aBonus = -8 bBonus =  3 P[aWins] = 0.00000000
aBonus = -8 bBonus =  4 P[aWins] = 0.00000000
aBonus = -8 bBonus =  5 P[aWins] = 0.00000000
aBonus = -8 bBonus =  6 P[aWins] = 0.00000000
aBonus = -8 bBonus =  7 P[aWins] = 0.00000000
aBonus = -8 bBonus =  8 P[aWins] = 0.00000000
aBonus = -8 bBonus =  9 P[aWins] = 0.00000000
aBonus = -8 bBonus = 10 P[aWins] = 0.00000000
aBonus = -7 bBonus = -10 P[aWins] = 0.69705933
aBonus = -7 bBonus = -9 P[aWins] = 0.57863940
aBonus = -7 bBonus = -8 P[aWins] = 0.47215792
aBonus = -7 bBonus = -7 P[aWins] = 0.39866255
aBonus = -7 bBonus = -6 P[aWins] = 0.35178755
aBonus = -7 bBonus = -5 P[aWins] = 0.28928755
aBonus = -7 bBonus = -4 P[aWins] = 0.21694959
aBonus = -7 bBonus = -3 P[aWins] = 0.14493313
aBonus = -7 bBonus = -2 P[aWins] = 0.08674126
aBonus = -7 bBonus = -1 P[aWins] = 0.04473165
aBonus = -7 bBonus =  0 P[aWins] = 0.01823988
aBonus = -7 bBonus =  1 P[aWins] = 0.00460820
aBonus = -7 bBonus =  2 P[aWins] = 0.00000000
aBonus = -7 bBonus =  3 P[aWins] = 0.00000000
aBonus = -7 bBonus =  4 P[aWins] = 0.00000000
aBonus = -7 bBonus =  5 P[aWins] = 0.00000000
aBonus = -7 bBonus =  6 P[aWins] = 0.00000000
aBonus = -7 bBonus =  7 P[aWins] = 0.00000000
aBonus = -7 bBonus =  8 P[aWins] = 0.00000000
aBonus = -7 bBonus =  9 P[aWins] = 0.00000000
aBonus = -7 bBonus = 10 P[aWins] = 0.00000000
aBonus = -6 bBonus = -10 P[aWins] = 0.80832047
aBonus = -6 bBonus = -9 P[aWins] = 0.69705933
aBonus = -6 bBonus = -8 P[aWins] = 0.57863940
aBonus = -6 bBonus = -7 P[aWins] = 0.47215792
aBonus = -6 bBonus = -6 P[aWins] = 0.39866255
aBonus = -6 bBonus = -5 P[aWins] = 0.35178755
aBonus = -6 bBonus = -4 P[aWins] = 0.28928755
aBonus = -6 bBonus = -3 P[aWins] = 0.21694959
aBonus = -6 bBonus = -2 P[aWins] = 0.14493313
aBonus = -6 bBonus = -1 P[aWins] = 0.08674126
aBonus = -6 bBonus =  0 P[aWins] = 0.04473165
aBonus = -6 bBonus =  1 P[aWins] = 0.01823988
aBonus = -6 bBonus =  2 P[aWins] = 0.00460820
aBonus = -6 bBonus =  3 P[aWins] = 0.00000000
aBonus = -6 bBonus =  4 P[aWins] = 0.00000000
aBonus = -6 bBonus =  5 P[aWins] = 0.00000000
aBonus = -6 bBonus =  6 P[aWins] = 0.00000000
aBonus = -6 bBonus =  7 P[aWins] = 0.00000000
aBonus = -6 bBonus =  8 P[aWins] = 0.00000000
aBonus = -6 bBonus =  9 P[aWins] = 0.00000000
aBonus = -6 bBonus = 10 P[aWins] = 0.00000000
aBonus = -5 bBonus = -10 P[aWins] = 0.89332562
aBonus = -5 bBonus = -9 P[aWins] = 0.80832047
aBonus = -5 bBonus = -8 P[aWins] = 0.69705933
aBonus = -5 bBonus = -7 P[aWins] = 0.57863940
aBonus = -5 bBonus = -6 P[aWins] = 0.47215792
aBonus = -5 bBonus = -5 P[aWins] = 0.39866255
aBonus = -5 bBonus = -4 P[aWins] = 0.35178755
aBonus = -5 bBonus = -3 P[aWins] = 0.28928755
aBonus = -5 bBonus = -2 P[aWins] = 0.21694959
aBonus = -5 bBonus = -1 P[aWins] = 0.14493313
aBonus = -5 bBonus =  0 P[aWins] = 0.08674126
aBonus = -5 bBonus =  1 P[aWins] = 0.04473165
aBonus = -5 bBonus =  2 P[aWins] = 0.01823988
aBonus = -5 bBonus =  3 P[aWins] = 0.00460820
aBonus = -5 bBonus =  4 P[aWins] = 0.00000000
aBonus = -5 bBonus =  5 P[aWins] = 0.00000000
aBonus = -5 bBonus =  6 P[aWins] = 0.00000000
aBonus = -5 bBonus =  7 P[aWins] = 0.00000000
aBonus = -5 bBonus =  8 P[aWins] = 0.00000000
aBonus = -5 bBonus =  9 P[aWins] = 0.00000000
aBonus = -5 bBonus = 10 P[aWins] = 0.00000000
aBonus = -4 bBonus = -10 P[aWins] = 0.94986711
aBonus = -4 bBonus = -9 P[aWins] = 0.89332562
aBonus = -4 bBonus = -8 P[aWins] = 0.80832047
aBonus = -4 bBonus = -7 P[aWins] = 0.69705933
aBonus = -4 bBonus = -6 P[aWins] = 0.57863940
aBonus = -4 bBonus = -5 P[aWins] = 0.47215792
aBonus = -4 bBonus = -4 P[aWins] = 0.39866255
aBonus = -4 bBonus = -3 P[aWins] = 0.35178755
aBonus = -4 bBonus = -2 P[aWins] = 0.28928755
aBonus = -4 bBonus = -1 P[aWins] = 0.21694959
aBonus = -4 bBonus =  0 P[aWins] = 0.14493313
aBonus = -4 bBonus =  1 P[aWins] = 0.08674126
aBonus = -4 bBonus =  2 P[aWins] = 0.04473165
aBonus = -4 bBonus =  3 P[aWins] = 0.01823988
aBonus = -4 bBonus =  4 P[aWins] = 0.00460820
aBonus = -4 bBonus =  5 P[aWins] = 0.00000000
aBonus = -4 bBonus =  6 P[aWins] = 0.00000000
aBonus = -4 bBonus =  7 P[aWins] = 0.00000000
aBonus = -4 bBonus =  8 P[aWins] = 0.00000000
aBonus = -4 bBonus =  9 P[aWins] = 0.00000000
aBonus = -4 bBonus = 10 P[aWins] = 0.00000000
aBonus = -3 bBonus = -10 P[aWins] = 0.97700189
aBonus = -3 bBonus = -9 P[aWins] = 0.94986711
aBonus = -3 bBonus = -8 P[aWins] = 0.89332562
aBonus = -3 bBonus = -7 P[aWins] = 0.80832047
aBonus = -3 bBonus = -6 P[aWins] = 0.69705933
aBonus = -3 bBonus = -5 P[aWins] = 0.57863940
aBonus = -3 bBonus = -4 P[aWins] = 0.47215792
aBonus = -3 bBonus = -3 P[aWins] = 0.39866255
aBonus = -3 bBonus = -2 P[aWins] = 0.35178755
aBonus = -3 bBonus = -1 P[aWins] = 0.28928755
aBonus = -3 bBonus =  0 P[aWins] = 0.21694959
aBonus = -3 bBonus =  1 P[aWins] = 0.14493313
aBonus = -3 bBonus =  2 P[aWins] = 0.08674126
aBonus = -3 bBonus =  3 P[aWins] = 0.04473165
aBonus = -3 bBonus =  4 P[aWins] = 0.01823988
aBonus = -3 bBonus =  5 P[aWins] = 0.00460820
aBonus = -3 bBonus =  6 P[aWins] = 0.00000000
aBonus = -3 bBonus =  7 P[aWins] = 0.00000000
aBonus = -3 bBonus =  8 P[aWins] = 0.00000000
aBonus = -3 bBonus =  9 P[aWins] = 0.00000000
aBonus = -3 bBonus = 10 P[aWins] = 0.00000000
aBonus = -2 bBonus = -10 P[aWins] = 0.99076217
aBonus = -2 bBonus = -9 P[aWins] = 0.97700189
aBonus = -2 bBonus = -8 P[aWins] = 0.94986711
aBonus = -2 bBonus = -7 P[aWins] = 0.89332562
aBonus = -2 bBonus = -6 P[aWins] = 0.80832047
aBonus = -2 bBonus = -5 P[aWins] = 0.69705933
aBonus = -2 bBonus = -4 P[aWins] = 0.57863940
aBonus = -2 bBonus = -3 P[aWins] = 0.47215792
aBonus = -2 bBonus = -2 P[aWins] = 0.39866255
aBonus = -2 bBonus = -1 P[aWins] = 0.35178755
aBonus = -2 bBonus =  0 P[aWins] = 0.28928755
aBonus = -2 bBonus =  1 P[aWins] = 0.21694959
aBonus = -2 bBonus =  2 P[aWins] = 0.14493313
aBonus = -2 bBonus =  3 P[aWins] = 0.08674126
aBonus = -2 bBonus =  4 P[aWins] = 0.04473165
aBonus = -2 bBonus =  5 P[aWins] = 0.01823988
aBonus = -2 bBonus =  6 P[aWins] = 0.00460820
aBonus = -2 bBonus =  7 P[aWins] = 0.00000000
aBonus = -2 bBonus =  8 P[aWins] = 0.00000000
aBonus = -2 bBonus =  9 P[aWins] = 0.00000000
aBonus = -2 bBonus = 10 P[aWins] = 0.00000000
aBonus = -1 bBonus = -10 P[aWins] = 0.99076217
aBonus = -1 bBonus = -9 P[aWins] = 0.99076217
aBonus = -1 bBonus = -8 P[aWins] = 0.97700189
aBonus = -1 bBonus = -7 P[aWins] = 0.94986711
aBonus = -1 bBonus = -6 P[aWins] = 0.89332562
aBonus = -1 bBonus = -5 P[aWins] = 0.80832047
aBonus = -1 bBonus = -4 P[aWins] = 0.69705933
aBonus = -1 bBonus = -3 P[aWins] = 0.57863940
aBonus = -1 bBonus = -2 P[aWins] = 0.47215792
aBonus = -1 bBonus = -1 P[aWins] = 0.39866255
aBonus = -1 bBonus =  0 P[aWins] = 0.35178755
aBonus = -1 bBonus =  1 P[aWins] = 0.28928755
aBonus = -1 bBonus =  2 P[aWins] = 0.21694959
aBonus = -1 bBonus =  3 P[aWins] = 0.14493313
aBonus = -1 bBonus =  4 P[aWins] = 0.08674126
aBonus = -1 bBonus =  5 P[aWins] = 0.04473165
aBonus = -1 bBonus =  6 P[aWins] = 0.01823988
aBonus = -1 bBonus =  7 P[aWins] = 0.00460820
aBonus = -1 bBonus =  8 P[aWins] = 0.00000000
aBonus = -1 bBonus =  9 P[aWins] = 0.00000000
aBonus = -1 bBonus = 10 P[aWins] = 0.00000000
aBonus =  0 bBonus = -10 P[aWins] = 0.99076217
aBonus =  0 bBonus = -9 P[aWins] = 0.99076217
aBonus =  0 bBonus = -8 P[aWins] = 0.99076217
aBonus =  0 bBonus = -7 P[aWins] = 0.97700189
aBonus =  0 bBonus = -6 P[aWins] = 0.94986711
aBonus =  0 bBonus = -5 P[aWins] = 0.89332562
aBonus =  0 bBonus = -4 P[aWins] = 0.80832047
aBonus =  0 bBonus = -3 P[aWins] = 0.69705933
aBonus =  0 bBonus = -2 P[aWins] = 0.57863940
aBonus =  0 bBonus = -1 P[aWins] = 0.47215792
aBonus =  0 bBonus =  0 P[aWins] = 0.39866255
aBonus =  0 bBonus =  1 P[aWins] = 0.35178755
aBonus =  0 bBonus =  2 P[aWins] = 0.28928755
aBonus =  0 bBonus =  3 P[aWins] = 0.21694959
aBonus =  0 bBonus =  4 P[aWins] = 0.14493313
aBonus =  0 bBonus =  5 P[aWins] = 0.08674126
aBonus =  0 bBonus =  6 P[aWins] = 0.04473165
aBonus =  0 bBonus =  7 P[aWins] = 0.01823988
aBonus =  0 bBonus =  8 P[aWins] = 0.00460820
aBonus =  0 bBonus =  9 P[aWins] = 0.00000000
aBonus =  0 bBonus = 10 P[aWins] = 0.00000000
aBonus =  1 bBonus = -10 P[aWins] = 0.99076217
aBonus =  1 bBonus = -9 P[aWins] = 0.99076217
aBonus =  1 bBonus = -8 P[aWins] = 0.99076217
aBonus =  1 bBonus = -7 P[aWins] = 0.99076217
aBonus =  1 bBonus = -6 P[aWins] = 0.97700189
aBonus =  1 bBonus = -5 P[aWins] = 0.94986711
aBonus =  1 bBonus = -4 P[aWins] = 0.89332562
aBonus =  1 bBonus = -3 P[aWins] = 0.80832047
aBonus =  1 bBonus = -2 P[aWins] = 0.69705933
aBonus =  1 bBonus = -1 P[aWins] = 0.57863940
aBonus =  1 bBonus =  0 P[aWins] = 0.47215792
aBonus =  1 bBonus =  1 P[aWins] = 0.39866255
aBonus =  1 bBonus =  2 P[aWins] = 0.35178755
aBonus =  1 bBonus =  3 P[aWins] = 0.28928755
aBonus =  1 bBonus =  4 P[aWins] = 0.21694959
aBonus =  1 bBonus =  5 P[aWins] = 0.14493313
aBonus =  1 bBonus =  6 P[aWins] = 0.08674126
aBonus =  1 bBonus =  7 P[aWins] = 0.04473165
aBonus =  1 bBonus =  8 P[aWins] = 0.01823988
aBonus =  1 bBonus =  9 P[aWins] = 0.00460820
aBonus =  1 bBonus = 10 P[aWins] = 0.00000000
aBonus =  2 bBonus = -10 P[aWins] = 0.99076217
aBonus =  2 bBonus = -9 P[aWins] = 0.99076217
aBonus =  2 bBonus = -8 P[aWins] = 0.99076217
aBonus =  2 bBonus = -7 P[aWins] = 0.99076217
aBonus =  2 bBonus = -6 P[aWins] = 0.99076217
aBonus =  2 bBonus = -5 P[aWins] = 0.97700189
aBonus =  2 bBonus = -4 P[aWins] = 0.94986711
aBonus =  2 bBonus = -3 P[aWins] = 0.89332562
aBonus =  2 bBonus = -2 P[aWins] = 0.80832047
aBonus =  2 bBonus = -1 P[aWins] = 0.69705933
aBonus =  2 bBonus =  0 P[aWins] = 0.57863940
aBonus =  2 bBonus =  1 P[aWins] = 0.47215792
aBonus =  2 bBonus =  2 P[aWins] = 0.39866255
aBonus =  2 bBonus =  3 P[aWins] = 0.35178755
aBonus =  2 bBonus =  4 P[aWins] = 0.28928755
aBonus =  2 bBonus =  5 P[aWins] = 0.21694959
aBonus =  2 bBonus =  6 P[aWins] = 0.14493313
aBonus =  2 bBonus =  7 P[aWins] = 0.08674126
aBonus =  2 bBonus =  8 P[aWins] = 0.04473165
aBonus =  2 bBonus =  9 P[aWins] = 0.01823988
aBonus =  2 bBonus = 10 P[aWins] = 0.00460820
aBonus =  3 bBonus = -10 P[aWins] = 0.99076217
aBonus =  3 bBonus = -9 P[aWins] = 0.99076217
aBonus =  3 bBonus = -8 P[aWins] = 0.99076217
aBonus =  3 bBonus = -7 P[aWins] = 0.99076217
aBonus =  3 bBonus = -6 P[aWins] = 0.99076217
aBonus =  3 bBonus = -5 P[aWins] = 0.99076217
aBonus =  3 bBonus = -4 P[aWins] = 0.97700189
aBonus =  3 bBonus = -3 P[aWins] = 0.94986711
aBonus =  3 bBonus = -2 P[aWins] = 0.89332562
aBonus =  3 bBonus = -1 P[aWins] = 0.80832047
aBonus =  3 bBonus =  0 P[aWins] = 0.69705933
aBonus =  3 bBonus =  1 P[aWins] = 0.57863940
aBonus =  3 bBonus =  2 P[aWins] = 0.47215792
aBonus =  3 bBonus =  3 P[aWins] = 0.39866255
aBonus =  3 bBonus =  4 P[aWins] = 0.35178755
aBonus =  3 bBonus =  5 P[aWins] = 0.28928755
aBonus =  3 bBonus =  6 P[aWins] = 0.21694959
aBonus =  3 bBonus =  7 P[aWins] = 0.14493313
aBonus =  3 bBonus =  8 P[aWins] = 0.08674126
aBonus =  3 bBonus =  9 P[aWins] = 0.04473165
aBonus =  3 bBonus = 10 P[aWins] = 0.01823988
aBonus =  4 bBonus = -10 P[aWins] = 0.99076217
aBonus =  4 bBonus = -9 P[aWins] = 0.99076217
aBonus =  4 bBonus = -8 P[aWins] = 0.99076217
aBonus =  4 bBonus = -7 P[aWins] = 0.99076217
aBonus =  4 bBonus = -6 P[aWins] = 0.99076217
aBonus =  4 bBonus = -5 P[aWins] = 0.99076217
aBonus =  4 bBonus = -4 P[aWins] = 0.99076217
aBonus =  4 bBonus = -3 P[aWins] = 0.97700189
aBonus =  4 bBonus = -2 P[aWins] = 0.94986711
aBonus =  4 bBonus = -1 P[aWins] = 0.89332562
aBonus =  4 bBonus =  0 P[aWins] = 0.80832047
aBonus =  4 bBonus =  1 P[aWins] = 0.69705933
aBonus =  4 bBonus =  2 P[aWins] = 0.57863940
aBonus =  4 bBonus =  3 P[aWins] = 0.47215792
aBonus =  4 bBonus =  4 P[aWins] = 0.39866255
aBonus =  4 bBonus =  5 P[aWins] = 0.35178755
aBonus =  4 bBonus =  6 P[aWins] = 0.28928755
aBonus =  4 bBonus =  7 P[aWins] = 0.21694959
aBonus =  4 bBonus =  8 P[aWins] = 0.14493313
aBonus =  4 bBonus =  9 P[aWins] = 0.08674126
aBonus =  4 bBonus = 10 P[aWins] = 0.04473165
aBonus =  5 bBonus = -10 P[aWins] = 0.99076217
aBonus =  5 bBonus = -9 P[aWins] = 0.99076217
aBonus =  5 bBonus = -8 P[aWins] = 0.99076217
aBonus =  5 bBonus = -7 P[aWins] = 0.99076217
aBonus =  5 bBonus = -6 P[aWins] = 0.99076217
aBonus =  5 bBonus = -5 P[aWins] = 0.99076217
aBonus =  5 bBonus = -4 P[aWins] = 0.99076217
aBonus =  5 bBonus = -3 P[aWins] = 0.99076217
aBonus =  5 bBonus = -2 P[aWins] = 0.97700189
aBonus =  5 bBonus = -1 P[aWins] = 0.94986711
aBonus =  5 bBonus =  0 P[aWins] = 0.89332562
aBonus =  5 bBonus =  1 P[aWins] = 0.80832047
aBonus =  5 bBonus =  2 P[aWins] = 0.69705933
aBonus =  5 bBonus =  3 P[aWins] = 0.57863940
aBonus =  5 bBonus =  4 P[aWins] = 0.47215792
aBonus =  5 bBonus =  5 P[aWins] = 0.39866255
aBonus =  5 bBonus =  6 P[aWins] = 0.35178755
aBonus =  5 bBonus =  7 P[aWins] = 0.28928755
aBonus =  5 bBonus =  8 P[aWins] = 0.21694959
aBonus =  5 bBonus =  9 P[aWins] = 0.14493313
aBonus =  5 bBonus = 10 P[aWins] = 0.08674126
aBonus =  6 bBonus = -10 P[aWins] = 0.99076217
aBonus =  6 bBonus = -9 P[aWins] = 0.99076217
aBonus =  6 bBonus = -8 P[aWins] = 0.99076217
aBonus =  6 bBonus = -7 P[aWins] = 0.99076217
aBonus =  6 bBonus = -6 P[aWins] = 0.99076217
aBonus =  6 bBonus = -5 P[aWins] = 0.99076217
aBonus =  6 bBonus = -4 P[aWins] = 0.99076217
aBonus =  6 bBonus = -3 P[aWins] = 0.99076217
aBonus =  6 bBonus = -2 P[aWins] = 0.99076217
aBonus =  6 bBonus = -1 P[aWins] = 0.97700189
aBonus =  6 bBonus =  0 P[aWins] = 0.94986711
aBonus =  6 bBonus =  1 P[aWins] = 0.89332562
aBonus =  6 bBonus =  2 P[aWins] = 0.80832047
aBonus =  6 bBonus =  3 P[aWins] = 0.69705933
aBonus =  6 bBonus =  4 P[aWins] = 0.57863940
aBonus =  6 bBonus =  5 P[aWins] = 0.47215792
aBonus =  6 bBonus =  6 P[aWins] = 0.39866255
aBonus =  6 bBonus =  7 P[aWins] = 0.35178755
aBonus =  6 bBonus =  8 P[aWins] = 0.28928755
aBonus =  6 bBonus =  9 P[aWins] = 0.21694959
aBonus =  6 bBonus = 10 P[aWins] = 0.14493313
aBonus =  7 bBonus = -10 P[aWins] = 0.99076217
aBonus =  7 bBonus = -9 P[aWins] = 0.99076217
aBonus =  7 bBonus = -8 P[aWins] = 0.99076217
aBonus =  7 bBonus = -7 P[aWins] = 0.99076217
aBonus =  7 bBonus = -6 P[aWins] = 0.99076217
aBonus =  7 bBonus = -5 P[aWins] = 0.99076217
aBonus =  7 bBonus = -4 P[aWins] = 0.99076217
aBonus =  7 bBonus = -3 P[aWins] = 0.99076217
aBonus =  7 bBonus = -2 P[aWins] = 0.99076217
aBonus =  7 bBonus = -1 P[aWins] = 0.99076217
aBonus =  7 bBonus =  0 P[aWins] = 0.97700189
aBonus =  7 bBonus =  1 P[aWins] = 0.94986711
aBonus =  7 bBonus =  2 P[aWins] = 0.89332562
aBonus =  7 bBonus =  3 P[aWins] = 0.80832047
aBonus =  7 bBonus =  4 P[aWins] = 0.69705933
aBonus =  7 bBonus =  5 P[aWins] = 0.57863940
aBonus =  7 bBonus =  6 P[aWins] = 0.47215792
aBonus =  7 bBonus =  7 P[aWins] = 0.39866255
aBonus =  7 bBonus =  8 P[aWins] = 0.35178755
aBonus =  7 bBonus =  9 P[aWins] = 0.28928755
aBonus =  7 bBonus = 10 P[aWins] = 0.21694959
aBonus =  8 bBonus = -10 P[aWins] = 0.99076217
aBonus =  8 bBonus = -9 P[aWins] = 0.99076217
aBonus =  8 bBonus = -8 P[aWins] = 0.99076217
aBonus =  8 bBonus = -7 P[aWins] = 0.99076217
aBonus =  8 bBonus = -6 P[aWins] = 0.99076217
aBonus =  8 bBonus = -5 P[aWins] = 0.99076217
aBonus =  8 bBonus = -4 P[aWins] = 0.99076217
aBonus =  8 bBonus = -3 P[aWins] = 0.99076217
aBonus =  8 bBonus = -2 P[aWins] = 0.99076217
aBonus =  8 bBonus = -1 P[aWins] = 0.99076217
aBonus =  8 bBonus =  0 P[aWins] = 0.99076217
aBonus =  8 bBonus =  1 P[aWins] = 0.97700189
aBonus =  8 bBonus =  2 P[aWins] = 0.94986711
aBonus =  8 bBonus =  3 P[aWins] = 0.89332562
aBonus =  8 bBonus =  4 P[aWins] = 0.80832047
aBonus =  8 bBonus =  5 P[aWins] = 0.69705933
aBonus =  8 bBonus =  6 P[aWins] = 0.57863940
aBonus =  8 bBonus =  7 P[aWins] = 0.47215792
aBonus =  8 bBonus =  8 P[aWins] = 0.39866255
aBonus =  8 bBonus =  9 P[aWins] = 0.35178755
aBonus =  8 bBonus = 10 P[aWins] = 0.28928755
aBonus =  9 bBonus = -10 P[aWins] = 0.99076217
aBonus =  9 bBonus = -9 P[aWins] = 0.99076217
aBonus =  9 bBonus = -8 P[aWins] = 0.99076217
aBonus =  9 bBonus = -7 P[aWins] = 0.99076217
aBonus =  9 bBonus = -6 P[aWins] = 0.99076217
aBonus =  9 bBonus = -5 P[aWins] = 0.99076217
aBonus =  9 bBonus = -4 P[aWins] = 0.99076217
aBonus =  9 bBonus = -3 P[aWins] = 0.99076217
aBonus =  9 bBonus = -2 P[aWins] = 0.99076217
aBonus =  9 bBonus = -1 P[aWins] = 0.99076217
aBonus =  9 bBonus =  0 P[aWins] = 0.99076217
aBonus =  9 bBonus =  1 P[aWins] = 0.99076217
aBonus =  9 bBonus =  2 P[aWins] = 0.97700189
aBonus =  9 bBonus =  3 P[aWins] = 0.94986711
aBonus =  9 bBonus =  4 P[aWins] = 0.89332562
aBonus =  9 bBonus =  5 P[aWins] = 0.80832047
aBonus =  9 bBonus =  6 P[aWins] = 0.69705933
aBonus =  9 bBonus =  7 P[aWins] = 0.57863940
aBonus =  9 bBonus =  8 P[aWins] = 0.47215792
aBonus =  9 bBonus =  9 P[aWins] = 0.39866255
aBonus =  9 bBonus = 10 P[aWins] = 0.35178755
aBonus = 10 bBonus = -10 P[aWins] = 0.99076217
aBonus = 10 bBonus = -9 P[aWins] = 0.99076217
aBonus = 10 bBonus = -8 P[aWins] = 0.99076217
aBonus = 10 bBonus = -7 P[aWins] = 0.99076217
aBonus = 10 bBonus = -6 P[aWins] = 0.99076217
aBonus = 10 bBonus = -5 P[aWins] = 0.99076217
aBonus = 10 bBonus = -4 P[aWins] = 0.99076217
aBonus = 10 bBonus = -3 P[aWins] = 0.99076217
aBonus = 10 bBonus = -2 P[aWins] = 0.99076217
aBonus = 10 bBonus = -1 P[aWins] = 0.99076217
aBonus = 10 bBonus =  0 P[aWins] = 0.99076217
aBonus = 10 bBonus =  1 P[aWins] = 0.99076217
aBonus = 10 bBonus =  2 P[aWins] = 0.99076217
aBonus = 10 bBonus =  3 P[aWins] = 0.97700189
aBonus = 10 bBonus =  4 P[aWins] = 0.94986711
aBonus = 10 bBonus =  5 P[aWins] = 0.89332562
aBonus = 10 bBonus =  6 P[aWins] = 0.80832047
aBonus = 10 bBonus =  7 P[aWins] = 0.69705933
aBonus = 10 bBonus =  8 P[aWins] = 0.57863940
aBonus = 10 bBonus =  9 P[aWins] = 0.47215792
aBonus = 10 bBonus = 10 P[aWins] = 0.39866255


Do these numbers look similar to what you obtained from your simulation?

A detailed description of how the machinery behind this piece of code works would be quite long and complicated, it's way outside of the scope of the question.

However, I could post the explanation as an answer to a much more general question, if someone wants to see it.

EDIT: flipped the $>$ to $<$, as OP requested. The results have been updated.

EDIT 2: Well, not having your whole desktop with you is not an excuse. Your smartphone can run javascript, and it probably has some rudimentary text editor. If not, you can still use JSFiddle.

Here is a non-exact probabilistic solution of the same problem: JSFiddle dice game

Here is the JS-code:

function println(stuff) {
var elem = document.getElementById("console");
elem.innerHTML = elem.innerHTML + ('<p>' + stuff + '</p>');
}

function singleDice() {
return 1 + Math.floor(Math.random() * 6);
}

function threeDice() {
return singleDice() + singleDice() + singleDice();
}

var retries = 1000000;
for (var bonusDiff = -20; bonusDiff <= 20; bonusDiff++) {
var aWinCounter = 0;
for (var t = 0; t < retries; t++) {
var a = threeDice();
var b = threeDice();
if (a == 3 || (a < 10 + bonusDiff)) {
// bWins
} else {
if (b == 18 || (b > 3 && b >= 10 - bonusDiff && b >= a)) {
// bWins
} else {
aWinCounter++;
}
}
}
println("bonusDiff = " + bonusDiff + " P[A wins] = " + (aWinCounter / retries));
}


Here are the approximate results:

bonusDiff = -20 P[A wins] = 0.990686
bonusDiff = -19 P[A wins] = 0.990722
bonusDiff = -18 P[A wins] = 0.99092
bonusDiff = -17 P[A wins] = 0.990814
bonusDiff = -16 P[A wins] = 0.990686
bonusDiff = -15 P[A wins] = 0.990874
bonusDiff = -14 P[A wins] = 0.990696
bonusDiff = -13 P[A wins] = 0.990838
bonusDiff = -12 P[A wins] = 0.990741
bonusDiff = -11 P[A wins] = 0.990817
bonusDiff = -10 P[A wins] = 0.990591
bonusDiff = -9 P[A wins] = 0.990672
bonusDiff = -8 P[A wins] = 0.990859
bonusDiff = -7 P[A wins] = 0.977035
bonusDiff = -6 P[A wins] = 0.950184
bonusDiff = -5 P[A wins] = 0.893029
bonusDiff = -4 P[A wins] = 0.808343
bonusDiff = -3 P[A wins] = 0.697359
bonusDiff = -2 P[A wins] = 0.57819
bonusDiff = -1 P[A wins] = 0.472485
bonusDiff = 0 P[A wins] = 0.39806
bonusDiff = 1 P[A wins] = 0.351532
bonusDiff = 2 P[A wins] = 0.288944
bonusDiff = 3 P[A wins] = 0.218179
bonusDiff = 4 P[A wins] = 0.145732
bonusDiff = 5 P[A wins] = 0.086522
bonusDiff = 6 P[A wins] = 0.044856
bonusDiff = 7 P[A wins] = 0.018261
bonusDiff = 8 P[A wins] = 0.004542
bonusDiff = 9 P[A wins] = 0
bonusDiff = 10 P[A wins] = 0
bonusDiff = 11 P[A wins] = 0
bonusDiff = 12 P[A wins] = 0
bonusDiff = 13 P[A wins] = 0
bonusDiff = 14 P[A wins] = 0
bonusDiff = 15 P[A wins] = 0
bonusDiff = 16 P[A wins] = 0
bonusDiff = 17 P[A wins] = 0
bonusDiff = 18 P[A wins] = 0
bonusDiff = 19 P[A wins] = 0
bonusDiff = 20 P[A wins] = 0


As one can hopefully see, these approximate results are essentially the same as the exactly computed results above.

• Your results mismatch with the output from my script, because I (me, myself, not you) made a typo in the OP (first line of pseudocode had a '>' instead of the '<' that I should have placed there; see edit). Unfortunately, I only have the result with me on my phone. I'll only have access to the script on Monday again :-( – Monika Nov 7 '15 at 18:11
• Note that only the (signed) difference between the bonuses matters. You can just loop over $d \equiv B_a - B_b$, from $-20$ to $+20$. – mjqxxxx Nov 7 '15 at 18:50
• @mjqxxxx: I've noticed that, but didn't bother to change the code. Maybe the OP comes up with some other rule, where aBonus and bBonus actually do matter... The computation costs nothing anyway. – Andrey Tyukin Nov 7 '15 at 19:37
• thank you, a very helpful answer in that I can now calculate the result using the script you linked. However useful, I choose to give the bounty to Anatoly because he explained how to do the calculations myself. – Monika Nov 10 '15 at 10:16