diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-10-23 23:15:45 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-16 19:12:55 +0100 |
commit | 38fa36af32d179a5c8e12a20a07e41d65756a7d2 (patch) | |
tree | fc8717ba438086bcc42a284f68a8188076b15205 | |
parent | 02566a2f324132f96a2a64aae6c8f3edd76e489c (diff) | |
download | richard-iii-38fa36af32d179a5c8e12a20a07e41d65756a7d2.tar.gz |
Add PRNG seed to game state.
Log all game actions to a table so they can be replayed.
-rw-r--r-- | rules.js | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -33,6 +33,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); @@ -160,7 +164,7 @@ function gen_action(view, action, argument) { } function roll_d6() { - return Math.floor(Math.random() * 6) + 1; + return random(6) + 1; } function shuffle_deck() { @@ -173,7 +177,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); } @@ -3338,8 +3342,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: {}, |