[RPG] How to implement this specialized roll-and-keep mechanic in AnyDice


I need help with an anydice function.

I'm looking for a modified Roll and Keep type of mechanic, where if you have more dice that roll the max result than you are keeping, each discarded max result adds +1 to the total.

Example: if you were rolling 6d10 and keeping two (equivalent to HIGHEST 2 of 6d10 in anydice), and you rolled 10, 10, 10, 8, 3, and 1, your total would be 21–that's 20 for the two 10s you kept, and +1 for the 10 you couldn't keep.

Example 2: if you were rolling 5d6 drop 2 (equivalent to HIGHEST 3 of 5d6 in anydice), and rolled 6, 6, 6, 6, and 6, your result would be 20.

Maybe I don't know how to word what I am looking for correctly, but I have not been able to find any answers to this question when searching around online.

Thanks in advance.

Best Answer

Here's an implementation of Ben Barden's algorithm to compute the distributions you want.

function: N:n of SIZE:n keep K:n extras add {
    result: [helper NdSIZE SIZE K]

function: helper ROLL:s SIZE:n K:n {
    COUNT: [count SIZE in ROLL]
    if COUNT > K { result: K*SIZE - K + COUNT }
    result: {1..K}@ROLL

The output is somewhat underwhelming, since your bonus points for having lots of extra maximum values on your dice rarely happens. You need very large die pools relative to the number of dice you're keeping for the rule to have any noticeable effect. Here's some code that computes the distributions for keeping three dice from varying pools of d6s. The effect of the special rule only really matters for pools that are many times larger than the number of dice you're keeping.

D: 6
K: 3

loop N over {K+1..K+8} {
  output [N of D keep K extras add] named "[N]d[D] keep [K] extras add +1"
loop N over {K+1..K+8} {
  output {1..K}@NdD named "[N]d[D] keep [K]"

graphs of statistical distributions

Your special rule only effects the small part of the graph over on the right, where the circle-marked lines diverge from the square marked lines out beyond 18 (the normal maximum for 3d6). For values less than 18 (which is 95% or more of the distribution for most of the pool sizes), the two kinds of lines are exactly coincident.

Related Topic