[RPG] How to calculate the distribution of “Roll 3D6, reroll any dice once, treat all 1’s as a 2” in AnyDice

anydicedicestatistics

I'm wondering how to use Anydice to calculate the following:
Roll 3d6, treating all 1's as 2's, you may reroll each die once, so we do this if the roll is below the average.

So 3d6, can reroll each dice once, and we'll reroll on 2 and 3 because its below average.

I've given it a go, but I'm not sure if I got it right

Here is my anydice attempt

Best Answer

The first step to make it easier to recognise that our dice are independent of each other meaning we can figure out how one of them works and then add them together.

Firstly, treating all 1s as 2s is actually pretty easy if you know how to define custom dice:

D: {2, 2..6}

Which is a d6 but with the 1 replaced with a 2. (This is technically a sequence which is why we use 1dD to roll it later.)

We then need to work our how to do a singular reroll for which we can use a custom function. Note that it is not equivalent to taking the higher of two rolls as you keep 4s and 5s even if the second (then unrolled roll) would be higher.

function: reroll X:n {
   if X <= 3 {
       result: 1dD
   }
   else { result: X}
}

This function takes in a die and converts it to a number, which means it will be iterated for each possible result (make sure not to pass a sequence as that will be converted to the sum). We then check if the 'roll' is 3 or less and if it is we return a new roll (the reroll), otherwise we just return the value roll.

To get the output for 3 such rolls we just call:

output 3d[reroll 1dD]

Which gives the following distribution:

enter image description here

You can check out my anydice program for this here (includes some outputs for singular rolls as a sanity check).