# Modeling a system where you roll Xd20 and take highest, plus the second highest if the first one is a critical, etc

I'm making my own combat/task resolution system (loosely based the advantage mechanic from D&D 5e). In this system a roll with "advantage" is resolved as follows:

1. Roll Xd20 and take the result of the highest rolled die.
2. If the highest roll is a "critical" (i.e. equal to or greater than a certain threshold, usually 20 but possibly 19 or even lower), add the result of the second highest roll.
3. If the second highest roll was also a critical, add the third highest roll, and so on, until you either get a non-critical result or run out of dice.
4. Finally, you add a modifier (based on your stats etc.) to the result.

Rolling with "disadvantage" works the same way, except that you start with the lowest roll and work upwards instead with criticals resulting from the low end of the dice.

1. Roll Xd20 and take the result of the lowest rolled die.
2. If the lowest roll is a "critical" (i.e. less than or equal to a certain threshold, usually 1 but possibly 2 or even higher), add the result of the second lowest roll.
3. If the second lowest roll was also a critical, add the third lowest roll, and so on, until you either get a non-critical result or run out of dice.
4. Finally, you add a modifier (based on your stats etc.) to the result.

1. You roll 3d20 and score no critials → keep highest die, add modifier.

2. You roll 3d20 and score 1 critical → keep the sum of the two highest dice, add modifier.

3. You roll 3d20 and score 2 criticals → sum all three dice, add modifier.

I want to calculate the distribution of the results using this dice rolling mechanic to see what would be the effect of such changes compared to a simple "roll 2d20 keep highest" as in D&D 5e, but I'm having trouble doing so. This is how far I've gotten so far using AnyDice: https://anydice.com/program/2122a

Can anyone help me fix my program or otherwise model this dice rolling system?

• Oh, and Welcome to RPG.SE! Take the tour if you haven't already and see the help center or ask us here in the comments (use @ to ping someone) if you need more guidance. Good Luck and Happy Gaming! – Someone_Evil Mar 17 at 21:42
• OK, so the higher/lower modifier thing is basically a red herring, and you really do just want to model the "roll Xd20 take highest, add one more die for each crit" mechanic? I just made a fairly bold edit to your question based on that assumption, trying to clarify it as I understood it based on your writing and comment. Please check that I didn't make a mess of your question, and if I did, please either edit the question yourself to fix it or even roll back my edits entirely. (You can do that from the edit history.) And let me know when you've done that so I can vote to reopen. :) – Ilmari Karonen Mar 18 at 21:08
• Your disadvantage mechanic mean that Critical Failures (roll of 1-2) result in a higher net result than a regular low roll/failure (roll of 3). It's unclear how this relates to your resolution mechanic. For the sake of clarity in the question, you might be better off just focusing on modelling the advantage mechanic as you should be able to get clear answers to that. – linksassin Mar 19 at 1:11
• What happens when you roll a "critical success" on one die and a "critical failure" on another? For example, if you get 20/1/14 or 1/6/20 ? – Eddymage Mar 19 at 9:07

Based on your clarifications (and assuming that you meant to count rolls equal to or below the threshold as crits when rolling with disadvantage, as described in your comment), these AnyDice functions should model your mechanic:

function: advantage ROLL:s crit CRIT:n {
N: ROLL >= CRIT
result: {1..1+N}@ROLL
}

function: disadvantage ROLL:s crit CRIT:n {
N: ROLL <= CRIT
result: {1..1+N}@[reverse ROLL]
}


You can use them like this:

output [advantage 3d20 crit 20] named "3d20 with advantage, crit on nat 20"
output [advantage 3d20 crit 19] named "3d20 with advantage, crit on nat 19-20"

output [disadvantage 3d20 crit 1] named "3d20 with disadvantage, crit on nat 1"
output [disadvantage 3d20 crit 2] named "3d20 with disadvantage, crit on nat 1-2"


Note that the way I've written the functions makes use of the fact that high rolls crit when rolling with advantage and low rolls crit when rolling with disadvantage. This means that your mechanics will always return the sum of all dice that roll a crit, plus the highest / lowest non-crit roll if there is any. So what the functions do is first count the number of crits N, and then return the sum of the N+1 highest (or lowest) of the rolled numbers.

The resulting distributions are… interesting:

Rolling with advantage using your system gives much more favorable results than using the D&D 5e "2d20 take highest" mechanic: not only is taking the highest of three dice much better than the highest of just two dice on its own, but your crit mechanic gives a non-trivial chance of getting results up to 40 (and a tiny but non-zero chance of rolling up to 60).

Meanwhile, your disadvantage rolls actually aren't that far off from D&D 5e disadvantage rolls, at least as far as the average result goes. While taking the lowest of 3d20 is less favorable than taking the lowest of 2d20, the crit mechanic compensates for this somewhat. Here the crits don't cause such wild explosions as they do when rolling with advantage, since each crit roll basically just adds 1 or 2 pips to the outcome instead of 19 or 20. Still, the shape of the distribution is quite different, generally favoring low rolls more heavily, but compensated by the impossibility(!) of rolling a 1 and the small but non-zero chance of rolling above 20.

• This answer demonstrates why graphing expected results is so important. It can point out... interesting quirks that may not be intentional. – Red Orca Mar 19 at 18:24