# How can I create an AnyDice function where I can roll 3d20 and then lower the results of the individual die rolls?

In Neuroshima system you throw 3D20, ignore the highest result and use your skill to lower the results on 2 remaining dice, to get them equal or below your characteristic value, such as agility. Each point in skill can be used to lower any die roll by one; it is a pool of points that can be used to subtract from individual rolls. For example, skill on level 5 could be used to lower one die roll by 5, or one roll by 3 and the other by 2.

The test is passed when at least 2 out of 3 dice are equal or lower than the characteristic.

Example:

{12, 11, 17} skill 3, characteristic 11 - ignore 17, lower the other two to 10 and 10, so it's a pass

{2, 18, 19} skill 5, characteristic 12 - ignore 19, lower 18 to 13, still a failure though, as one would need at most 12 on that die.

I tried to create a function of my own, with skill level fixed to 1 to make a baby step, but failed nonetheless.

function: neuro {

DICE:3D20

MID: 2@DICE

LOW: 3@DICE

MID:MID-1

ROLL: [sort {LOW, MID}]

result: 1@ROLL

}


Result of this is 20 100% and I don't know why. It's probably, because LOW and MID are "d" (dice) and sorting them is sort of wrong, I think?

Has anyone did anything similar? How can I use AnyDice to model this function?

• Can you provide some more detail about how a success or failure is determined? How many dice need to roll under the characteristic for the entire roll to succeed? Is a roll that is equal to the characteristic a success or failure? How exactly is the skill value used? It seems from your examples that the skill value can be split across d20 rolls, but this isn't clearly explained. – Ryan C. Thompson Apr 19 at 12:39
• Sorry, my fault. So a success is when 2 out of 3 dice are equal or lower than characteristic. Skill value can be split in across rolls. – Irrehaare Apr 19 at 12:48
• In your second example should that be {2,19,19}, not {2,18,19}? – nitsua60 Apr 19 at 14:44
• Welcome to RPG.SE! Take the tour if you haven't already, and check out the help center for more guidance. – V2Blast Apr 19 at 17:57

So you want to pick the two lowest dice, and see if there is any 'deficit' above a certain target number. The target number is one less than your attribute. Rolling less than the target number gives no benefit, but rolling higher produces a deficit equal to the difference. Finally you need to make sure the deficit is small enough that it can be compensated for with your skill. In code form, it looks like this:

SKILL: 0
ATTRIBUTE: 11

function:  deficit DICE:s against TARGET:n
{
DEF : 0
if (3@DICE>TARGET)
{
DEF : DEF + (3@DICE-TARGET)
}
if (2@DICE>TARGET)
{
DEF : DEF + (2@DICE-TARGET)
}
result: DEF
}

output [deficit 3d20 against ATTRIBUTE-1]<=SKILL

• The OP's description isn't clear, but from the examples, it sounds like the skill value is not subtracted from every roll, but rather represents a pool of points to subtract from individual rolls. For example, with a skill of 5, one could subtract 3 from one roll and 2 from another, rather than subtracting 5 from both. – Ryan C. Thompson Apr 19 at 12:31
• Exactly, thank you. That is what makes it so difficult, as subtraction is conditional. – Irrehaare Apr 19 at 12:51
• I think this is the right approach: compute what skill value would be required to make the roll a success, then compare that to the actual skill value. – Ryan C. Thompson Apr 19 at 13:36
• After quick check it looks awesome, I'll confirm this evening when I'll have more time. – Irrehaare Apr 19 at 13:44
• @Ifusaso I though about it, but no: {2, 19, 19} with 16 in attribute and 1 in skill would be calculated as a pass while it isn't. – Irrehaare Apr 19 at 14:16

Here's a somewhat simpler solution, in two steps:

1. First, make a custom d20 whose sides show the number of points needed to bring it under the target characteristic value:

DIE: [highest of 0 and d20 - CHARACTERISTIC + 1]

2. Then roll three of these dice, take the sum of the two lowest (i.e. the number of points needed to bring both of them under the target) and see if it's less than the number of skill points available:

output [lowest 2 of 3dDIE] <= SKILL


Actually, we don't even need the <= SKILL part, if we just plot the cumulative probability of needing at most a given number of skill points to succeed. From this output, we can directly read that the success rate for characteristic 11 is 50% with skill 0, 57.13% with skill 1, 63.85% with skill 2, 70.11% with skill 3, etc.

If we wanted, we could even automatically run the same code for a range of characteristics and plot the results as a nice graph:

This is what the entire code to generate the graph above looks like:

loop CHARACTERISTIC over {1..20} {
DIE: [highest of 0 and d20 - CHARACTERISTIC + 1]
output [lowest 2 of 3dDIE] named "characteristic [CHARACTERISTIC]"
}


Ps. One thing we can observe from the results is that one extra skill level is almost, but not quite as good as one extra point in the relevant characteristic. But two skill levels is still way better than one point in the characteristic.

That might seem a bit surprising, given that raising the characteristic effectively reduces all of your dice rolls by one, whereas an extra skill point only lets you reduce one of them. However, if one of your three dice is already less than your current characteristic, then there's no need to lower it any further, and in that case one extra skill level is indeed just as good as one extra point in the characteristic. And it turns out that this is a pretty common case — for example, the probability of rolling naturally under 11 (i.e. at most 10) on at least one out of 3d20 is 87.5%.

Also, it's worth noting that the values of the lowest and the middle roll on 3d20 are correlated: the larger the lowest roll is, the larger the middle roll must also be. Thus, at least for relatively low skill levels, the situations where an extra point in the characteristic would be more helpful than an extra skill point (i.e. where none of your natural rolls are under the characteristic) are usually also those where you've rolled so badly that neither will actually help.

For an illustrative example, this AnyDice script (using the empty die trick for calculating conditional probabilities) shows the skill level needed to succeed (with characteristic 11, although you can easily change that) when the lowest roll is either < 11 or ≥ 11. Notably, in the former case you have 57% chance of success even at skill 0, and a further 8% chance on top of that with skill 1, whereas in the latter case you need at least skill 2 to have any chance of success at all (since you need to lower both rolls by at least one)!