diff options
author | Tor Andersson <tor@ccxvii.net> | 2025-04-26 00:00:43 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2025-04-26 00:00:43 +0200 |
commit | a1e4c8d153c58f3de85d2cf3e5046ea36be1b5b4 (patch) | |
tree | 3d1dca782d6159e84c8120a2baf6f9e2939c331c | |
parent | e710bda1ae2527a1878275d7d151a0e798e8496a (diff) | |
download | julius-caesar-a1e4c8d153c58f3de85d2cf3e5046ea36be1b5b4.tar.gz |
-rw-r--r-- | rules.js | 41 |
1 files changed, 20 insertions, 21 deletions
@@ -31,10 +31,13 @@ const PLUTO = 6 const VULCAN = 7 const OBSERVER = "Observer" -const BOTH = "Both" const CAESAR = "Caesar" const POMPEIUS = "Pompeius" +const MA_BOTH = [ CAESAR, POMPEIUS ] +const MA_CAESAR = [ CAESAR ] +const MA_POMPEIUS = [ POMPEIUS ] + const PLAYER_MASK = { Caesar: 1, Pompeius: 2 } const B_CAESAR = find_block("Caesar") @@ -155,8 +158,12 @@ function print_turn_log(verb) { print_turn_log_no_active(game.active + " " + verb + ":") } +function is_active_player(current) { + return (game.active === current) || (Array.isArray(game.active) && game.active.includes(current)) +} + function is_inactive_player(current) { - return current === OBSERVER || (game.active !== current && game.active !== BOTH) + return !is_active_player(current) } function remove_from_array(array, item) { @@ -946,7 +953,7 @@ function start_year() { game.p_card = 0 game.c_discard = 0 game.p_discard = 0 - game.active = BOTH + game.active = MA_BOTH game.state = "discard_and_play_card" game.show_cards = false } @@ -955,11 +962,11 @@ function resume_discard_and_play_card() { if (game.c_card && game.p_card) start_first_turn() else if (game.c_card) - game.active = POMPEIUS + game.active = MA_POMPEIUS else if (game.p_card) - game.active = CAESAR + game.active = MA_CAESAR else - game.active = BOTH + game.active = MA_BOTH } states.discard_and_play_card = { @@ -1061,7 +1068,7 @@ function start_turn() { game.reserves = [] game.c_card = 0 game.p_card = 0 - game.active = BOTH + game.active = MA_BOTH game.state = "play_card" game.show_cards = false game.surprise = 0 @@ -1073,11 +1080,11 @@ function resume_play_card() { if (game.c_card && game.p_card) reveal_cards() else if (game.c_card) - game.active = POMPEIUS + game.active = MA_POMPEIUS else if (game.p_card) - game.active = CAESAR + game.active = MA_CAESAR else - game.active = BOTH + game.active = MA_BOTH } states.play_card = { @@ -2453,7 +2460,7 @@ function check_victory() { count_vp() if (game.c_vp >= 10) { game.result = CAESAR - game.active = null + game.active = "None" game.state = "game_over" game.victory = "Caesar won an early victory." logbr() @@ -2461,7 +2468,7 @@ function check_victory() { } else if (game.p_vp >= 10) { game.victory = "Pompeius won an early victory." game.result = POMPEIUS - game.active = null + game.active = "None" game.state = "game_over" logbr() log(game.victory) @@ -2657,7 +2664,7 @@ function end_game() { game.victory = "Pompeius won!" else game.victory = "The game ended in a draw." - game.active = null + game.active = "None" game.state = "game_over" logbr() log(game.victory) @@ -2871,14 +2878,6 @@ function observer_hand() { return hand } -exports.dont_snap = function (state) { - if (state.state === "play_card" && state.active !== BOTH) - return true - if (state.state === "discard_and_play_card" && state.active !== BOTH) - return true - return false -} - exports.view = function (state, current) { game = state |