Skip to content

Instantly share code, notes, and snippets.

@DarwinAwardWinner
Created May 19, 2019 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarwinAwardWinner/03393c59461db70028f9f47f5a5c150b to your computer and use it in GitHub Desktop.
Save DarwinAwardWinner/03393c59461db70028f9f47f5a5c150b to your computer and use it in GitHub Desktop.
library(dplyr)
library(tidyr)
d6 <- 1:6
# We'll call the 3 dice X, Y, and D (D is the dragon die)
all_rolls <- expand.grid(X=d6, Y=d6, D=d6) %>%
mutate(
## Sum of all 3 dice; determines if you hit
sum = X + Y + D,
## TRUE if this roll has doubles in it
double = X == Y | X == D | Y == D,
## Number of stunt points for this roll (0 if no doubles)
SP = double * D)
## Compare every roll against every to-hit value, and set the stunt
## points to zero for all misses
all_results <- all_rolls %>%
crossing(data.frame(to_hit = 3:18)) %>%
mutate(hit = sum >= to_hit,
SP=SP * hit)
attack_summary <- all_results %>%
group_by(to_hit) %>%
summarize(Mean_SP = mean(SP))
print(attack_summary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment