2
\$\begingroup\$

Been trying to figure this out and it's just not coming to me. Hoping it's possible with anydice...

So the player has a dice pool of 6d6. Success on a 5 or 6. That's easy enough to model. But I also want the player to have a pool of points. Say... 3 of them for sake of argument. I want them to be able to spend points to turn failures into successes.

example: Player rolls 3, 4, 4, 5, 6, 6 and has 3 points. Each point increments a die by 1 so he spends his points to bring the two 4s up to 5s and has one point left over that does no good.

Assuming points are always spent to bring up 4s first, then 3s etc, how would I model this in anydice? Is it even possible?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Here's one way to do it.

First, let's simplify the problem a little by relabeling the sides of the dice with the number of points needed to upgrade them into a success. So 5 and 6 become 0, 4 becomes 1, 3 becomes 2, and so on.

In AnyDice, we can construct such a relabeled die D e.g. like this:

MIN_SUCCESS: 5
D: [highest of 0 and MIN_SUCCESS - d6]

or, if you prefer, manually like this:

D: d{4, 3, 2, 1, 0, 0}

Next, let's write a function that takes a bunch of numbers rolled on such relabelled dice (as a sequence, in descending order by value) and a number of points and returns the maximum number of successes we can obtain from them.

We can do this by looping over the sequence of rolls (in reverse order, i.e. from lowest to highest) and, if we still have points left to upgrade the roll into a success, incrementing a success counter and decrementing the number of points left:

function: successes in ROLL:s with POINTS:n points {
  SUCCESSES: 0
  REMAINING: POINTS
  loop X over [reverse ROLL] {
    if X <= REMAINING {
      SUCCESSES: SUCCESSES + 1
      REMAINING: REMAINING - X
    }
  }
  result: SUCCESSES
}

Note the :s that tells AnyDice that the ROLL argument should be a sequence. When we call this function with a dice pool (e.g. 6dD) as the first argument, like below, AnyDice will automatically call it for each possible result of the roll (sorted in descending order by default) and collect the results into a custom die weighted by their probability:

output [successes in 6dD with 3 points]

If we want, we can also use a loop to produce multiple outputs from the code and compare them, e.g. like this:

N: 6
loop P over {0..5} {
  output [successes in NdD with P points] named "[N]d6 with [P] points"
}

And there we go, that's the whole script.

\$\endgroup\$
1
  • \$\begingroup\$ I really like how you explain the steps to arrive at the solution. On how to use anydice, I've been learning as many useful ways if not more from your posts here as from the documentation of anydice itself (which is somewhat terse). \$\endgroup\$ Commented Oct 13, 2023 at 6:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .