diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -37,6 +37,10 @@ let states = {}; let game = null; +function random(n) { + return Math.floor(((game.seed = game.seed * 48271 % 0x7fffffff) / 0x7fffffff) * n); +} + function log(...args) { let s = Array.from(args).join(" "); game.log.push(s); @@ -144,7 +148,7 @@ function gen_action(view, action, argument) { } function roll_d6() { - return Math.floor(Math.random() * 6) + 1; + return random(6) + 1; } function shuffle_deck() { @@ -157,7 +161,7 @@ function shuffle_deck() { function deal_cards(deck, n) { let hand = []; for (let i = 0; i < n; ++i) { - let k = Math.floor(Math.random() * deck.length); + let k = random(deck.length); hand.push(deck[k]); deck.splice(k, 1); } @@ -631,7 +635,7 @@ function draw_from_bag(bag, exclude_list) { if (game.location[b] === bag) list.push(b); } - return list[Math.floor(Math.random() * list.length)]; + return list[random(list.length)]; } function deploy_english(count) { @@ -640,7 +644,7 @@ function deploy_english(count) { if (game.location[b] === E_BAG) list.push(b); for (let i = 0; i < count; ++i) { - let x = Math.floor(Math.random() * list.length); + let x = random(list.length); let b = list[x]; list.splice(x,1); game.location[b] = ENGLAND; @@ -2827,8 +2831,9 @@ exports.ready = function (scenario, players) { return players.length === 2; } -exports.setup = function (scenario) { +exports.setup = function (seed, scenario) { game = { + seed: seed, attacker: {}, border_limit: {}, last_used: {}, |