14
1
In Dungeons & Dragons, almost everything is decided by rolling a die. Typically, if the roll is greater than or equal to a specified value, your attempt at doing whatever you wanted to do succeeds, and fails otherwise. Most commonly, a 20-sided die (aka d20) is used to roll.
Other times, the skill challenge system is used. It is similar to the simple system described above, but success is determined by whether or not the player(s) succeed individual rolls a certain number of times before failing a certain number of times. For example, the player(s) may be trying to pick multiple locks on a door with a limited number of lockpicks. Individual successful rolls represent successfully picking one of the locks, and individual failing rolls represent breaking a lockpick. Overall success would mean successfully picking all of the locks before breaking all of the lockpicks.
Furthermore, certain rolls can be critical rolls. On a d20, rolling a 1 is a critical failure, resulting in immediately failing the entire challenge (in the above example, the player(s) might accidentally alert a guard). Rolling a 20 is a critical success, resulting in immediately succeeding the entire challenge (in the above example, the player(s) might find a set of keys to the locks, removing the need to pick them). In the case of a critical roll, the challenge is immediately over and the outcome decided, regardless of the previous number of successes and failures.
In this challenge, you will be given a difficulty, the number of successes needed, and the number of failures at which the challenge is failed. You must simulate a player attempting the challenge, and output the result.
Input
3 integers, representing the value that must be met or exceeded to succeed at an individual roll, the number of successes needed to succeed at the challenge, and the number of failures at which the challenge is failed. The order and format of the inputs does not matter, as long as you specify what order you will be using. The difficulty will be between 1 and 20, inclusive, and the number of successes and failures will both be between 1 and 100, inclusive.
Output
The results of each of the d20 rolls (integers, in order), and the overall result of the challenge (a truthy/falsey value). The format does not matter, as long as the individual results are in order, the overall result either comes before or after all of the individual rolls (you can't output the overall result in the middle of the rolls, for example), and you specify what output format you use and use it consistently.
Examples (values in parentheses are for explanation and need not be included):
Input:
12 5 3 (difficulty successes failures)
Output:
15 (success, 1-0)
10 (failure, 1-1)
5 (failure, 1-2)
16 (success, 2-2)
12 (success, 3-2)
15 (success, 4-2)
19 (success, 5-2)
True (overall success)
Input:
15 2 3 (difficulty failures successes)
Output:
0 (overall failure)
15 (success, 1-0)
12 (failure, 1-1)
13 (failure, 1-2)
Input:
5 5 10 (successes failures difficulty)
Output:
11 (success, 1-0)
5 (failure, 1-1)
20 (critical success)
1 (overall success)
Input:
3 10 3 (failures difficulty successes)
Output:
12 (success, 1-0)
11 (success, 2-0)
1 (critical failure)
False (overall failure)
Rules
- This is code-golf, so shortest code in bytes wins
- You must randomly choose an integer value between 1 and 20 (inclusive) for each roll. Each value should have an equal probability of being chosen (or as close to equal as possible).
@BradGilbertb2gills
the number of successes and failures will both be between 1 and 100, inclusive.
So, yes, there is the possibility that a single failure results in failing the entire challenge. – Mego – 2015-12-17T03:34:49.320Should I assume that the true value representing overall success always has to be the same true value? Or could it just be the number of failures left? – Brad Gilbert b2gills – 2015-12-17T05:59:58.240
@BradGilbertb2gills It does not have to be the same true value; I use the number of failures left in my Python answer.
– Mego – 2015-12-17T06:00:59.440Ehh, I'm going to probably just leave it as returning a Bool, as that is only one byte, and it helps improve the readability of the output. – Brad Gilbert b2gills – 2015-12-17T06:08:38.993
@BradGilbertb2gills Readability is much less important than score. – Mego – 2015-12-17T06:09:12.707