[RPG] How to model a fudge dice roll with re-rolls in Anydice

anydicefudgestatistics

I need a little help with a probability calculation in Anydice. We are making a fudge based game using 4 fudge dice, so basically a d3 system: -1,0,1

We are allowing your attribute or stats in the game go to go from -3 to 4 and high stats allows you to re-roll a die.

So basically on any fudge roll a character can re-roll a number of dice up to his stat maximum. If he has a negative stat he has to take away dice from the initial roll.

I figured out how to determine the probabilities of rolling with 4 dice and lower representing a negative stat:

output 4d{-1,0,1} 

What I need help with is determining the probability of re-rolling a die when a character has a positive stat.

An example of what I am talking about: My fighter has a 1 strength and I roll my 4 fudge dice I get 3 blanks and 1 – on the dice. I decide to re-roll the 1 – to try and get a better result on the second roll.

A formula I tried in Anydice to represent the example above is 4d{-1,0,1}-1

The problem with this formula is it only works if the second re-roll is better: there is a possibility the second re-roll will be the same so it does not quite work.

Does anyone have some insight on a way I can make a proper formula in Anydice to represent a re-roll of 4 fudge dice with the possibility of 1-4 dice being re-rolled and the possibility that the second re-roll has only a 66% chance of being better than the first re-roll.

I am making assumptions that a player will only re-roll dice if they have a negative appear on the fudge dice.

Best Answer

Here, use this code:

set "position order" to "lowest first"

function: roll R:s reroll N {
 A: 0
 loop I over {1..N}{
  if I@R = -1 {
   A: A + 1 + d{-1, 0, 1}
  }
 }
 result: R + A
}

output [roll 4d{-1, 0, 1} reroll 1]

This code creates a function where the initial fudge dice are turned into a sequence. This means every possible roll is evaluated. For any one roll we check the N lower dice and if it's a -1 we "reroll" it. The hack to emulate the reroll is to add 1 cancling the old value, then adding d{-1, 0, 1}. This hack value is added to A which is added at the end.

Related Topic