summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js41
1 files changed, 20 insertions, 21 deletions
diff --git a/rules.js b/rules.js
index 5645b57..20eb840 100644
--- a/rules.js
+++ b/rules.js
@@ -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