Skip to content

Instantly share code, notes, and snippets.

@kalebr
Last active December 22, 2015 12:28
Show Gist options
  • Save kalebr/6472668 to your computer and use it in GitHub Desktop.
Save kalebr/6472668 to your computer and use it in GitHub Desktop.
last night on earth combat sim
fight <- function(numZombieDie, numHumanDie) {
zd <- expand.grid(rep(list(1:6), numZombieDie))
hd <- expand.grid(rep(list(1:6), numHumanDie))
results <- vector()
for (z in 1:nrow(zd)) {
for (h in 1:nrow(hd)) {
zroll <- as.numeric(zd[z, ])
hroll <- as.numeric(hd[h, ])
if(max(hroll) > max(zroll)) {
if(length(hroll) > length(unique(hroll))) {
results <- c(results, "kill")
} else {
results <- c(results, "defend")
}
} else {
results <- c(results, "wound")
}
}
}
output = list(counts = table(results), ratios = table(results) / length(results))
return(output)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment