Skip to content

Instantly share code, notes, and snippets.

@paganre
Last active October 23, 2022 05:13
Show Gist options
  • Save paganre/7054384f8fdd76e74bd6839b4c9b38fa to your computer and use it in GitHub Desktop.
Save paganre/7054384f8fdd76e74bd6839b4c9b38fa to your computer and use it in GitHub Desktop.
Death saves
for (let i = 0; i < 4; i ++) {
for (let j = 0; j < 4; j++) {
if (i === 0 && j === 0) {
dp[i][j] = STARTING_VAL
} else {
if (j === 3) { // life
dp[i][j] = ((dp[i][j-1]/20) * 11) + (dp[i][j-2]/20) + (dp[i][j-3]/20)
} else if (i === 3) { // death
dp[i][j] = ((dp[i-1][j]/20) * 9) + (dp[i-2][j]/20)
} else {
// we are somewhere in the middle and rolling a 20 is taken care of
// you maybe ended up here by rolling a 1
if (i >= 2) {
dp[i][j] += dp[i-2][j]/20
}
// you maybe ended up here by rolling a 2-9
if (i >= 1) {
dp[i][j] += (dp[i-1][j]/20)*8
}
// you maybe ended up here by rolling 10-19
if (j >= 1) {
dp[i][j] += (dp[i][j-1]/20)*10
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment