diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-10-23 23:15:45 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 12:53:17 +0100 |
commit | 3aec639f39c1d035a5a2aa6f12e139d70e58c9fa (patch) | |
tree | 434ad9222d755a4b039909ddb823f97ca5b9c900 /rules.js | |
parent | 2d12d83ac82b65393bd40139cba58e39987ac15a (diff) | |
download | hammer-of-the-scots-3aec639f39c1d035a5a2aa6f12e139d70e58c9fa.tar.gz |
Add PRNG seed to game state.
Log all game actions to a table so they can be replayed.
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: {}, |