diff options
-rw-r--r-- | rules.js | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -35,6 +35,8 @@ const BOTH = "Both" const CAESAR = "Caesar" const POMPEIUS = "Pompeius" +const PLAYER_MASK = { Caesar: 1, Pompeius: 2 } + const B_CAESAR = find_block("Caesar") const B_POMPEIUS = find_block("Pompeius") const B_CLEOPATRA = find_block("Cleopatra") @@ -238,7 +240,7 @@ function deal_cards(deck, n) { function reset_road_limits() { game.sea_moved = [] - game.sea_retreated = false + game.sea_retreated = 0 game.limits = [] } @@ -430,6 +432,21 @@ function is_pinned(who) { return false } +function is_transport(b) { + return is_navis(b) && set_has(game.sea_moved, b) && !set_has(game.moved, b) +} + +function count_friendly_transports(where) { + let count = 0 + let p = game.active + for (let b = 0; b < block_count; ++b) { + if (game.location[b] === where && block_owner(b) === p) + if (is_transport(b)) + ++count + } + return count +} + function is_city(where) { let t = SPACES[where].type return t === "city" || t === "major-port" || t === "port" @@ -677,7 +694,7 @@ function can_block_move(b) { let from = game.location[b] if (is_pinned(b)) return false - if (set_has(game.sea_moved, from) && count_friendly(from) <= 1) + if (is_transport(b) && count_friendly_transports(from) <= 1) return false for (let to of SPACES[from].exits) { if (can_block_move_to(b, to)) { @@ -700,7 +717,7 @@ function can_block_continue(b, last_from) { } function can_sea_retreat(who, _from, to) { - if (game.sea_retreated) + if (game.sea_retreated & PLAYER_MASK[game.active]) return false if (BLOCKS[who].type === "navis") return false @@ -1494,7 +1511,9 @@ states.move_where = { log_move_start(from, to) logp("amphibious moved.") if (is_sea(to)) { - set_add(game.sea_moved, to) + for (let b = 0; b < block_count; ++b) + if (is_navis(b) && game.location[b] === to) + set_add(game.sea_moved, b) game.state = "amphibious_move_to" } else { set_add(game.moved, game.who) @@ -1568,7 +1587,9 @@ states.amphibious_move_to = { game.location[game.who] = to log_move_continue(to) if (is_sea(to)) { - set_add(game.sea_moved, to) + for (let b = 0; b < block_count; ++b) + if (is_navis(b) && game.location[b] === to) + set_add(game.sea_moved, b) game.state = "amphibious_move_to" } else { set_add(game.moved, game.who) @@ -2299,7 +2320,7 @@ states.retreat = { if (is_sea(to) && !is_navis(game.who)) { push_undo() move_to(game.who, from, to) - game.sea_retreated = true + game.sea_retreated |= PLAYER_MASK[game.active] game.state = "sea_retreat" } else { move_to(game.who, from, to) |