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:08:56 +0100 |
commit | 23ca24db3e0a84066bc14af0841f0ba87d5141d5 (patch) | |
tree | 12cc4bb1bf62feae935ce52ab26399b2b592099d /rules.js | |
parent | 2ad31c79096b21ff9501f3997e56d54600757678 (diff) | |
download | julius-caesar-23ca24db3e0a84066bc14af0841f0ba87d5141d5.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
@@ -35,6 +35,10 @@ const RESERVE_MARK = ""; 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); @@ -171,7 +175,7 @@ function edge_id(A, B) { } function roll_d6() { - return Math.floor(Math.random() * 6) + 1; + return random(6) + 1; } function reset_deck() { @@ -184,7 +188,7 @@ function reset_deck() { function deal_cards(deck, n) { let hand = []; for (let i = 0; i < n; ++i) { - let c = Math.floor(Math.random() * deck.length); + let c = random(deck.length); hand.push(deck[c]); deck.splice(c, 1); } @@ -1138,7 +1142,7 @@ states.jupiter = { for (let x in BLOCKS) if (game.location[x] === where) list.push(x); - let i = Math.floor(Math.random() * list.length); + let i = random(list.length); jupiter_block(list[i]); }, secret: function (args) { @@ -1151,7 +1155,7 @@ states.jupiter = { for (let b in BLOCKS) if (game.location[b] === where && BLOCKS[b].owner === owner) list.push(b); - let i = Math.floor(Math.random() * list.length); + let i = random(list.length); jupiter_block(list[i]); } }, @@ -2376,8 +2380,9 @@ exports.ready = function (scenario, players) { return players.length === 2; } -exports.setup = function (scenario) { +exports.setup = function (seed, scenario) { game = { + seed: seed, tournament: (scenario === "Tournament"), c_hand: [], p_hand: [], |