>>391 https://repl.it/@vip0/bullet#index.js // 0-5
const rand6 = () => Math.floor(Math.random() * 6);
const gun = (() => {
let pos = 0;
const shuffle = () => (pos = rand6());
shuffle();
const shut = () => pos-- === -1
return { shuffle, pos, shut }
})()
// mock 1/2 rand
const readDoShuffleAsync = () => {
const y = Math.random() >= 0.5
console.log(y ? "y" : "n")
return y
}
let i = 1;
while (true) {
console.log("リボルバーを回しますか?");
if (readDoShuffleAsync()) gun.shuffle()
const bomb = gun.shut();
console.log(`${i}回目: ${bomb ? "バーン!" : "不発"}`);
i++;
if (bomb) break