[RPG] How to model the fighter’s Great Weapon Fighting fighting style in Anydice

anydicednd-5efighterfighting-styletools

I was trying to create an AnyDice function to model the Great Weapon Fighting fighting style (which lets you reroll 1s and 2s), but I couldn't get it to work on any arbitrary dice.

I've found this one:

function: reroll R:n under N:n {
   if R < N { result: d12 } else {result: R}
}
output [reroll 1d12 under 3] named "greataxe weapon fighting"

And it works fine. But I don't know how to make the function generic so i don't need to change the d12 every time i want a different dice to reroll.

I've tried

function: reroll R:n under N:n {
   if R < N { result: d{1..R} } else {result: R}
}
output [reroll 1d12 under 3] named "greataxe weapon fighting"

but it is not giving the right probabilities. Maybe if I could fetch the die size inside the function…

Best Answer

It's a common mistake with anydice to look for a procedural solution- anydice models dice. Therefore cast your problem as "What does the dice look like that gives the answer?"

Think about how Great Weapon Fighting works with a d8. We are potentially rolling 2 8 sided dice so our result die has 8x8=64 faces. There are 2 ways we can get a 1 (or 2) - rolling a 1 or 2 followed by a 1 (or 2) so our dice has 2 1s and 2 2s. That leaves 60 faces which are equally divided between the numbers 3 to 8, so 10 each. So in anydice our dice looks like:

EIGHT: {{1..2}:2, {3..8}:10}

More generally, for an N sided die:

DGW: {{1..2}:2, {3..N}:N+2}

For a dice with an even number of sides (i.e. all of them) this can be simplified by dividing the number of faces by 2:

DGW: {{1..2}, {3..N}:N/2+1}

You can use this sequence like any other dice so a great sword can be modelled as:

2d{{1..2}, {3..6}:4}