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:
- Roll Xd20 and take the result of the highest rolled die.
- 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.
- 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.
- 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.
- Roll Xd20 and take the result of the lowest rolled die.
- 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.
- 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.
- Finally, you add a modifier (based on your stats etc.) to the result.
Examples of rolls with advantage:
You roll 3d20 and score no critials → keep highest die, add modifier.
You roll 3d20 and score 1 critical → keep the sum of the two highest dice, add modifier.
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?