Last active
October 23, 2022 05:13
-
-
Save paganre/7054384f8fdd76e74bd6839b4c9b38fa to your computer and use it in GitHub Desktop.
Death saves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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