function rollDice(max) {
return 1 + Math.floor(Math.random()*max)
}
function deathRoll(bet) {
let p1 = Math.floor(bet * 10);
let p2 = Math.floor(bet * 10);
while (true) {
p1 = rollDice(p2);
if (p1 <= 1) {
return 2; // 2 wins
}
p2 = rollDice(p1);
if (p2 <= 1) {
return 1; // 1 wins
}
}
}
const stats = {1:0, 2:0}
const samples = 1000000
for (let i = 0; i < samples; i++) {
const winner = deathRoll(20);
stats[winner]++;
}
console.log(
Object.values(stats).map(n => Math.round(n / samples * 10000) / 100)
);