-
-
Save sma/c37f8a185e98c21fdda5f9b34060bd07 to your computer and use it in GitHub Desktop.
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
function d6() { | |
return Math.floor(Math.random()*6)+1; | |
} | |
function kill() { | |
let hp = 40; | |
let sp = 7; | |
let turn = 0; | |
while (hp > 0) { | |
let d = d6() + d6(); | |
if (d === 12) hp -= 5; | |
if (sp > 0 && d > sp) { | |
d -= sp; | |
sp--; | |
hp -= d; | |
} else if (sp == 0) { | |
hp -= d; | |
} | |
turn++; | |
} | |
return turn; | |
} | |
let turns = 0; | |
for (let i = 0; i < 1000; i++) { | |
turns += kill(); | |
} | |
console.log(turns / 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment