# AnyDice: How to model opposed rolls from YZE?

Year Zero Engine uses d6's dice pools. On the standard roll you throw a bunch of d6's and count 6's as succesess. One is enough, but 2 and more can give you additional results (such as additional damage). But in opposed rolls your successes are negated by enemy successes. For example, if you got 3 successes, but enemy got 2, than your final value is one.

How to see possibilities of opposed rolls on AnyDice?

Trish's answer is perfectly correct, but I can't resist pointing out that, for large dice pools, this is much faster:

SUCCESS: d6 = 6
output 3dSUCCESS - 2dSUCCESS


This defines a custom die named SUCCESS that rolls 1 with probability 1/6 and 0 with probability 5/6. You can also think of it as a d6 with the 6 side relabeled as "1" and all the other sides relabeled as "0". Then it just rolls two groups of these dice (one with three and one with two of them) and subtracts the sum of one roll from the other.

The reason this is faster is that it avoids the need for AnyDice to loop though all the possible rolls of 3d6 just to count the number of 6s in each of them. By telling AnyDice in advance that we consider all the non-6 sides of the dice to be equivalent, the number of distinct possible combinations that AnyDice needs to consider is reduced by a lot.

For 3d6 and 2d6 there aren't enough combinations for the "brute force" way in Trish's answer to be a problem in any way. But if you tried it with, say, 30d6 vs. 20d6, the difference in calculation time would be much more noticeable.

Ps. Your don't technically need the SUCCESS variable, but the syntax without it looks a bit awkward:

output 3d(d6 = 6) - 2d(d6 = 6)


Also, there are several possible equivalent ways to define the SUCCESS die. For example, all of these will produce the exact same custom die:

SUCCESS: [count 6 in d6]
SUCCESS: d6 >= 6
SUCCESS: d6 > 5
SUCCESS: d6 = 1
SUCCESS: d12 >= 11
SUCCESS: d{0, 0, 0, 0, 0, 1}
SUCCESS: d{0:5, 1}


Addendum: In the comments below, there was a question about how pushing the roll affects the result.

AIUI, in the Year Zero Engine "pushing a roll" means rerolling all dice that didn't succeed or roll a 1 (i.e. those that rolled from 2 to 5). This normally comes at some cost, although the YZE Standard Reference Document doesn't specify what that cost should be. The SRD also says that, in an opposed roll, only the "active party" may push their roll, and can decide whether to do so after both initial rolls have been made. This complicates things a bit, as I'll discuss below.

Anyway, if you knew that you were always going to push your roll no matter what, you could just define a "pushed d6" in AnyDice and use it for your roll. Probably the easiest way to that is with a custom function, like this:

function: push ROLL:n {
if ROLL = 1 | ROLL = 6 { result: ROLL } else { result: d6 }
}
PUSHED: [push d6] = 6
NORMAL: d6 = 6
output 3dPUSHED - 2dNORMAL


Of course, normally you wouldn't push your roll if you were going to win anyway, or if you knew that you couldn't win even with a push. Modelling this accurately in AnyDice is technically possible, but can get a bit complicated.

However, if you only care about how likely you are to win the opposed roll, it turns out that "always push" and "only push if it can make a difference" actually give the same win rate (because pushing when it can't make a difference obviously… doesn't make a difference)! Thus, you can use the simple program above to calculate this probability just fine.

What the program above does not tell you is how likely you are to have to pay the cost of pushing in order to win, or how likely you are to end up pushing and still not winning. It also doesn't accurately model more subtle decision-making strategies like "only push if it gives me at least an X% chance of winning", although in practice it should at least give a decent approximation for low values of X.

Addendum 2: OK, I went and wrote a program to calculate the respective probabilities on an opposed roll of:

• succeeding on the initial roll without having to push;
• succeeding after pushing the roll;
• failing after pushing the roll; and
• failing the initial roll with no chance of success by pushing.

I won't explain this code in detail, so figuring out how it works is left as an exercise, but I'll share it just as a general example of how this kind of modelling can be done in AnyDice and what it takes:

\ opposed roll with no pushing; returns 0 on failure and 1 on success \
function: ACTOR:s vs OPPONENT:s {
result: (ACTOR = 6) - (OPPONENT = 6) > 0
}

\ opposed roll with push; returns -1 on failure without push, 0 on failure \
\ after pushing, 1 on success after pushing and 2 on success without push \
function: push ACTOR:s vs OPPONENT:s {
BASELINE: (ACTOR = 6) - (OPPONENT = 6)
PUSHABLE: [count {2..5} in ACTOR]
if BASELINE > 0 { result: 2 }
if BASELINE + PUSHABLE <= 0 { result: -1 }
result: BASELINE + (PUSHABLE d (d6 = 6)) > 0
}

\ optimized d6 with all sides from 2 to 5 relabeled to be equivalent \
X: d{1, 2:4, 6}

output [3dX vs 2dX] named "no push: 0 = fail; 1 = success"
output [push 3dX vs 2dX] named "with push: -1 = fail, no push; 0 = fail with push; 1 = success with push; 2 = success, no push"


One detail I probably should note is that the code above assumes that you're always willing to push the roll if you're failing and might succeed, even if the odds of success are vanishingly small. For example, in the 3d6 vs 2d6 example, the code will happily push a roll of (2, 2, 2) against (6, 6) in the hope of rolling triple sixes on the reroll. Modifying the code to be more conservative about when to push a roll is also left as an exercise.

Also, the code above implicitly assumes that all ties are failures. The SRD says that's typically the case, but leaves open the possibility that "in some cases, ties have specific effects."

• It it so detailed question, thank you! One more question too, how can you add Push mechanic here? It is when attacker can reroll all non-sixes. Commented Mar 27 at 5:27
• @IverCold: See addendum above. Commented Mar 27 at 9:54
• I decided to accept your answer, I hope it is right thing to do. I need this probabilities for my YZE-hack, so I am using sub-system from YZE SRD where you take -1 and reroll all dice except 6's. Thank you again, I will use this info! Commented Mar 27 at 10:42
• @IverCold: Having the push penalty be -1 to the roll changes things a bit (and somewhat simplifies them, since the question "should I push this roll?" now has an objective answer independent of broader context). Asking a followup question specifically about your YZE hack might make sense… but in the mean time, try this. Commented Apr 2 at 12:36

### Count!

 output [count 6 in 3d6]-[count 6 in 2d6]


The left part is the aggressor, the right side the defender. Each side of the differentiation counts the 6s in the pools (here 3 and 2). The eventual output is the number of net successes of the aggressor. Negative numbers are net successes of the defender.

• One more question, how can you add Push mechanic here? It is when attacker can reroll all non-sixes. Commented Mar 27 at 5:25
• @IverCold That should maybe be asked as a new question. Commented Mar 27 at 13:18
• @IverCold comments like this are known as "shifting goalposts" and very impolite and not conform with the rules. Commented Mar 27 at 13:19
• @IverCold to clarify Trish's comment: if you were to edit the original post to address your newer question, that would invalidate existing answers and would be reverted by other users. As Oblivious Sage suggested, there's nothing against you newly posting a second question that addresses Pushing.
– nitsua60
Commented Mar 27 at 13:46