README.md

RollR

Lifecycle:
experimental

This R package provides a simple way to make all sorts of dice rolls using syntax inspired from tabletop roleplaying games like Dungeons & Dragons.

Installation

# install.packages("remotes")
remotes::install_github("felixmil/rollr")

Examples

library(rollr)

roll_dice("1d12") # rolls one 12-sided dice

roll_dice("1d20+2") # roll one 20-sided dice then adds 2

roll_dice("2d10 + 1d4") # rolls two 10-sided dice and one 4-sided diced and sums their results 

roll_dice("4d6h3") # rolls four 6-sided dice and sum the 3 highests

roll_dice("2d20l1") # rolls two 20-sided dice and keeps the lowest one

Use Case

in Dungeon & Dragons 5th Edition, ability scores are set by rolling 4d6 (four 6-sided dice) and keeping the 3 highest ones (ability scores can range between 3 and 18).

Let’s say we want to create a new character: Dunrill, a strong and muscular Dwarf. We roll our first set of 4 6-sided dice and keep the 3 highests.

library(rollr)

set.seed(42)

roll_results <- roll_dice("4d6h3", roll_history = TRUE) 
#> Evaluating "4d6h3" 
#> ==========
#> rolls: 1, 5, 1, 1
#> keeping 3 highest(s): 5, 1, 1
#> ==========
#>  Result is 7

That’s a 7. Now, the same roll (4d6h3) must be reproduced 5 more times:

more_roll_results <- replicate(5, roll_dice("4d6h3"))

all_results <- c(roll_results, more_roll_results)

print(all_results)
#> [1]  7  8 10 12  7 15

Now, we can assign these 6 values to Dunrill abilities (Strength, Dexterity, Constitution…) move on with character creation.

But were we lucky rolling these values: 7, 8, 10, 12, 7, 15 ?

To know that, we’ll simulate 9999 4d6h3 rolls and approximate the probability distribution.

random_rolls <- replicate(9999, roll_dice("4d6h3"))

Probability distribution for 4d6h3 looks like this:

Distribution’s mode is 13, however, the mean of our rolls is 9.83:

Rolls syntax (supported dice rolls)

Features list derivated from Sidekick

TO DO



Felixmil/rollR documentation built on July 11, 2020, 2:36 a.m.