diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-10-23 23:15:45 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-02-18 12:42:59 +0100 |
commit | ec2e9dae938387eeea59e6679accabe5ddb11939 (patch) | |
tree | 5dfce56150061f483876342226fb73a37e2e1c53 | |
parent | 86fb9cc113e1507183639987d53fe6a359c32a9d (diff) | |
download | 300-earth-and-water-ec2e9dae938387eeea59e6679accabe5ddb11939.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 | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -196,6 +196,10 @@ const ROADS = { let states = {}; let game = null; +function random(n) { + return Math.floor(((game.seed = game.seed * 48271 % 0x7fffffff) / 0x7fffffff) * n); +} + function $(msg) { return msg .replace(/ 1 cards/, " 1 card") @@ -300,7 +304,7 @@ function gen_action(view, action, argument) { } function roll_d6() { - return Math.floor(Math.random() * 6) + 1; + return random(6) + 1; } function create_deck() { @@ -321,7 +325,7 @@ function draw_card(deck) { reshuffle(); if (deck.length === 0) throw Error("can't draw from empty deck"); - let k = Math.floor(Math.random() * deck.length); + let k = random(deck.length); let card = deck[k]; deck.splice(k, 1); return card; @@ -2251,6 +2255,7 @@ function can_play_hippias() { } function play_hippias() { + clear_undo(); game.state = 'hippias'; } @@ -3263,10 +3268,9 @@ exports.ready = function (scenario, players) { return (players.length === 2); } -exports.setup = function (scenario) { +exports.setup = function (seed, scenario) { game = { - log: [], - undo: [], + seed: seed, // game board state campaign: 1, @@ -3321,6 +3325,9 @@ exports.setup = function (scenario) { attrition: 0, from: null, where: null, + + undo: [], + log: [], }; start_campaign(); |