diff options
-rw-r--r-- | data.js | 15 | ||||
-rw-r--r-- | play.css | 10 | ||||
-rw-r--r-- | play.html | 12 | ||||
-rw-r--r-- | play.js | 25 | ||||
-rw-r--r-- | rules.js | 353 |
5 files changed, 217 insertions, 198 deletions
@@ -489,7 +489,8 @@ const cards = [ /* 71 */ { - title: "North's Government Falls - The War Ends in 1779", + full_title: "North's Government Falls - The War Ends in 1779", + title: "The War Ends in 1779", type: "mandatory-event", event: "the_war_ends", year: 1779, @@ -497,7 +498,8 @@ const cards = [ /* 72 */ { - title: "North's Government Falls - The War Ends in 1780", + full_title: "North's Government Falls - The War Ends in 1780", + title: "The War Ends in 1780", type: "mandatory-event", event: "the_war_ends", year: 1780, @@ -505,7 +507,8 @@ const cards = [ /* 73 */ { - title: "North's Government Falls - The War Ends in 1781", + full_title: "North's Government Falls - The War Ends in 1781", + title: "The War Ends in 1781", type: "mandatory-event", event: "the_war_ends", year: 1781, @@ -513,7 +516,8 @@ const cards = [ /* 74 */ { - title: "North's Government Falls - The War Ends in 1782", + full_title: "North's Government Falls - The War Ends in 1782", + title: "The War Ends in 1782", type: "mandatory-event", event: "the_war_ends", year: 1782, @@ -521,7 +525,8 @@ const cards = [ /* 75 */ { - title: "North's Government Falls - The War Ends in 1783", + full_title: "North's Government Falls - The War Ends in 1783", + title: "The War Ends in 1783", type: "mandatory-event", event: "the_war_ends", year: 1783, @@ -1,10 +1,10 @@ main { background-color: slategray; } header { background-color: silver; } aside { background-color: #f5e8d7; } -body.British header.your_turn { background-color: salmon; } -body.American header.your_turn { background-color: skyblue; } -#role_American { background-color: skyblue; } -#role_British { background-color: salmon; } +body.America header.your_turn { background-color: skyblue; } +body.Britain header.your_turn { background-color: salmon; } +#role_Britain { background-color: salmon; } +#role_America { background-color: skyblue; } #log > div { padding-left: 20px; text-indent: -12px; } @@ -85,7 +85,7 @@ aside { /* CARD ACTION POPUP MENU */ #popup { max-width: 250px; } -#popup li.title { text-align: center } +#popup li.title { text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis } #popup li.disabled { display: none } /* MAP WITH MARKERS, CUs, LEADERS, AND SPACES */ @@ -38,9 +38,9 @@ <details> <summary><img src="/images/cog.svg"></summary> <menu> - <li><a href="info/playbook.html" target="blank">Playbook</a> <li><a href="info/rulebook.html" target="blank">Rulebook</a> - <li><a href="cards.html" target="blank">Cards</a> + <li><a href="info/playbook.html" target="blank">Playbook</a> + <li><a href="info/cards.html" target="blank">Cards</a> </menu> </details> <button onclick="toggle_markers()"><img src="/images/earth-america.svg"></button> @@ -49,14 +49,14 @@ <aside> <div id="roles"> - <div class="role" id="role_American"> - <div class="role_name">American</div> + <div class="role" id="role_Britain"> + <div class="role_name">Britain</div> <div class="role_stat">VP</div> <div class="role_user">-</div> <div class="role_info"></div> </div> - <div class="role" id="role_British"> - <div class="role_name">British</div> + <div class="role" id="role_America"> + <div class="role_name">America</div> <div class="role_stat">VP</div> <div class="role_user">-</div> <div class="role_info"></div> @@ -19,8 +19,8 @@ const BOXES = data.BOXES const CONTINENTAL_CONGRESS_DISPERSED = data.space_index["Continental Congress Dispersed"] const BLOCKADE_ZONES = [ "Sea1", "Sea2", "Sea3", "Sea4", "Sea5", "Sea6", "Sea7" ] -const BRITISH = "British" -const AMERICAN = "American" +const P_BRITAIN = "Britain" +const P_AMERICA = "America" const space_count = 66 const general_count = data.generals.length @@ -370,7 +370,7 @@ build_map() function player_info(player, nc, nq) { let info = "" - if (player == AMERICAN) { + if (player == P_AMERICA) { if (view.pennsylvania_and_new_jersey_line_mutinies || view.congress === CONTINENTAL_CONGRESS_DISPERSED) info += "\u{1f6ab} " } @@ -383,8 +383,8 @@ function player_info(player, nc, nq) { function on_update() { let e - roles.American.stat.textContent = player_info(AMERICAN, view.a_cards, view.a_queue) - roles.British.stat.textContent = player_info(BRITISH, view.b_cards, view.b_queue) + roles.America.stat.textContent = player_info(P_AMERICA, view.a_cards, view.a_queue) + roles.Britain.stat.textContent = player_info(P_BRITAIN, view.b_cards, view.b_queue) if (!view.last_played) document.getElementById("last_played").className = "card show card_back" @@ -397,8 +397,8 @@ function on_update() { action_button("drop_british_cu", "Drop off British CU") action_button("drop_american_cu", "Drop off American CU") action_button("drop_french_cu", "Drop off French CU") - action_button("british_first", "British") - action_button("american_first", "American") + action_button("britain_first", "Britain") + action_button("america_first", "America") action_button("surrender", "Surrender") action_button("pass", "Next") action_button("undo", "Undo") @@ -416,21 +416,22 @@ function on_update() { e.classList.remove("ops_1") e.classList.remove("ops_2") e.classList.remove("ops_3") - e.classList.add("ops_" + view.played_british_reinforcements) + if (view.reinforcements[0] > 0) + e.classList.add("ops_" + CARDS[view.reinforcements[0]].count) e = document.getElementById("played_american_reinforcements_1") e.classList.remove("ops_1") e.classList.remove("ops_2") e.classList.remove("ops_3") - if (view.played_american_reinforcements.length >= 1) - e.classList.add("ops_" + view.played_american_reinforcements[0]) + if (view.reinforcements[1] > 0) + e.classList.add("ops_" + CARDS[view.reinforcements[1]].count) e = document.getElementById("played_american_reinforcements_2") e.classList.remove("ops_1") e.classList.remove("ops_2") e.classList.remove("ops_3") - if (view.played_american_reinforcements.length >= 2) - e.classList.add("ops_" + view.played_american_reinforcements[1]) + if (view.reinforcements[2] > 0) + e.classList.add("ops_" + CARDS[view.reinforcements[2]].count) let cards = view.hand for (let c = 1; c <= 110; ++c) { @@ -3,9 +3,7 @@ // TODO: campaign messed up who is who after battle // TODO: retreat with 0 CU after battle -exports.scenarios = [ "Historical" ] - -exports.roles = [ "American", "British" ] +// TODO: bit flags for regulars, european_war, french alliance triggered const data = require("./data") @@ -29,9 +27,8 @@ const NC = 11 const SC = 12 const GA = 13 -const BRITISH = "British" -const AMERICAN = "American" -const FRENCH = "French" +const P_BRITAIN = "Britain" +const P_AMERICA = "America" const PC_NONE = 0 const PC_BRITISH = 1 @@ -100,7 +97,11 @@ const all_spaces = new Array(space_count).fill(0).map((_,i)=>i) // 66 * 2 / 32 = 5 words for all PC data // cu stacks -const ENEMY = { American: BRITISH, British: AMERICAN } +const ENEMY = { [P_AMERICA]: P_BRITAIN, [P_BRITAIN]: P_AMERICA } + +exports.scenarios = [ "Standard" ] + +exports.roles = [ P_BRITAIN, P_AMERICA ] let states = {} let events = {} @@ -111,39 +112,44 @@ let view function setup_game(seed) { game = { seed: seed, + log: [], + undo: [], + active: P_AMERICA, + state: null, + + // tracks year: 1775, - congress: data.space_index["Philadelphia"], - french_alliance: 0, french_alliance_triggered: false, european_war: false, - french_navy: -1, regulars: true, + + // played cards war_ends: 0, - played_british_reinforcements: 0, - played_american_reinforcements: [], + reinforcements: [0,0,0], + // pieces and markers + french_alliance: 0, + congress: PHILADELPHIA, + french_navy: -1, loc: new Array(general_count).fill(NOWHERE), spc: new Array(space_count + 2).fill(PC_NONE), - moved: [], - mcu: [], - // TODO: compute on the fly - control: [], - - - deck: create_deck(), - discard: [], - reshuffle: false, + // hands & card deck a_hand: [], b_hand: [], a_queue: 0, b_queue: 0, - log: [], - undo: [], + reshuffle: false, + deck: null, + removed: [], + + // transient state + moved: [], + mcu: [], - prompt: null, - actions: [], + // TODO: compute on the fly + control: [], } set_space_pc(QUEBEC, PC_BRITISH) @@ -187,27 +193,45 @@ function setup_game(seed) { place_french_cu(FRENCH_REINFORCEMENTS, 5) + create_deck() + goto_committees_of_correspondence() } /* GAME STATE */ function create_deck() { - let deck = [] + game.deck = [] for (let i = 1; i <= 110; ++i) { // No DoI or Baron von Steuben first year. if (i === DECLARATION_OF_INDEPENDENCE || i === BARON_VON_STEUBEN) continue - deck.push(i) + game.deck.push(i) } - return deck + shuffle(game.deck) } function reshuffle_deck() { log("Reshuffled the deck.") game.reshuffle = false - game.deck = game.deck.concat(game.discard) - game.discard = [] + + // Reconstitute deck, minus removed cards, cards in hand, war_ends, and reinforcement cards. + // Rule 6.1B clarification. + for (let c = 1; c <= 110; ++c) { + if (game.a_hand.includes(c)) + continue + if (game.b_hand.includes(c)) + continue + if (game.reinforcements.includes(c)) + continue + if (set_has(game.removed, c)) + continue + if (game.war_ends === c) + continue + game.deck.push(c) + } + + shuffle(game.deck) } function roll_d6() { @@ -217,20 +241,11 @@ function roll_d6() { function deal_card() { if (game.deck.length === 0) reshuffle_deck() - let i = random(game.deck.length) - let c = game.deck[i] - game.deck.splice(i, 1) - return c -} - -function last_discard() { - if (game.discard.length > 0) - return game.discard[game.discard.length - 1] - return 0 + return game.deck.pop() } function active_hand() { - return game.active === AMERICAN ? game.a_hand : game.b_hand + return game.active === P_AMERICA ? game.a_hand : game.b_hand } function play_card(c, reason) { @@ -240,17 +255,16 @@ function play_card(c, reason) { log(game.active[0] + " played #" + c) if (CARDS[c].reshuffle === "if_played") game.reshuffle = true - array_remove_item(active_hand(), c) + set_delete(active_hand(), c) game.last_played = c - if (!CARDS[c].once) - game.discard.push(c) - else + if (CARDS[c].once) { log("Removed card " + c + ".") + set_add(game.removed, c) + } } function discard_card_from_hand(hand, c) { - array_remove_item(hand, c) - game.discard.push(c) + set_delete(hand, c) if (CARDS[c].reshuffle === "if_discarded") game.reshuffle = true logp("discarded #" + c) @@ -266,8 +280,8 @@ function discard_card(c, reason) { } function can_exchange_for_discard(c) { - if (game.did_discard_event) { - if (game.active === BRITISH) + if (game.did_discard_event > 0) { + if (game.active === P_BRITAIN) return true return CARDS[c].count > 1 } @@ -292,8 +306,8 @@ function can_play_event(c) { } function can_play_reinforcements() { - if (game.active === BRITISH) { - if (game.played_british_reinforcements === 0) { + if (game.active === P_BRITAIN) { + if (game.reinforcements[0] === 0) { let n = count_british_cu(BRITISH_REINFORCEMENTS) for (let g of BRITISH_GENERALS) if (is_general_at_location(g, BRITISH_REINFORCEMENTS)) @@ -302,8 +316,8 @@ function can_play_reinforcements() { } return false } - if (game.active === AMERICAN) - return game.played_american_reinforcements.length < 2 + if (game.active === P_AMERICA) + return game.reinforcements[1] === 0 || game.reinforcements[2] === 0 return false } @@ -384,7 +398,7 @@ function has_american_pc(space) { } function has_enemy_pc(space) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return has_american_pc(space) else return has_british_pc(space) @@ -414,7 +428,7 @@ function is_adjacent_to_american_pc(a) { function place_british_pc(space) { logp("placed PC in " + space) if (game.british_pc_space_list) - array_remove_item(game.british_pc_space_list, space) + set_delete(game.british_pc_space_list, space) set_space_pc(space, PC_BRITISH) } @@ -424,7 +438,7 @@ function place_american_pc(space) { } function remove_pc(space) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) logp("removed PC in " + space) else logp("removed PC in " + space) @@ -432,7 +446,7 @@ function remove_pc(space) { } function flip_pc(space) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) logp("flipped PC in " + space) else logp("flipped PC in " + space) @@ -514,7 +528,7 @@ function has_french_cu(space) { } function has_enemy_cu(where) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return has_american_or_french_cu(where) else return has_british_cu(where) @@ -556,7 +570,7 @@ function count_american_and_french_cu(where) { } function count_enemy_cu(where) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return count_american_and_french_cu(where) else return count_british_cu(where) @@ -654,7 +668,7 @@ function has_american_or_french_general(where) { } function has_enemy_general(where) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return has_american_or_french_general(where) else return has_british_general(where) @@ -662,7 +676,7 @@ function has_enemy_general(where) { function count_friendly_generals(where) { let list - if (game.active === BRITISH) + if (game.active === P_BRITAIN) list = BRITISH_GENERALS else list = AMERICAN_GENERALS @@ -674,7 +688,7 @@ function count_friendly_generals(where) { } function has_general_on_map() { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return has_british_general_on_map() else return has_american_general_on_map() @@ -695,7 +709,7 @@ function has_american_general_on_map() { } function can_activate_general(c) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return can_activate_british_general(c) else return can_activate_american_general(c) @@ -749,7 +763,7 @@ function capture_american_or_french_general(where) { } function capture_enemy_general(where) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) capture_american_or_french_general(where) else capture_british_general(where) @@ -806,7 +820,7 @@ function place_british_reinforcements(who, count, where) { move_british_cu(BRITISH_REINFORCEMENTS, where, count) if (has_enemy_general(where)) capture_enemy_general(where) - if (game.active === BRITISH && game.congress === where) + if (game.active === P_BRITAIN && game.congress === where) disperse_continental_congress() } } @@ -893,7 +907,7 @@ function intercept_army(who, from, to) { function overrun(where) { logp("overran CU in " + where) - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { if (count_american_cu(where) > 0) remove_american_cu(where, 1) else @@ -1050,7 +1064,7 @@ function gen_place_american_pc_in(list_of_colonies) { function goto_committees_of_correspondence() { log(".h2.american Committes of Correspondence") logbr() - game.active = AMERICAN + game.active = P_AMERICA game.state = "committees_of_correspondence" game.coc = THE_13_COLONIES.slice() } @@ -1068,7 +1082,7 @@ states.committees_of_correspondence = { place_american_pc(space) { push_undo() let colony = SPACES[space].colony - array_remove_item(game.coc, colony) + set_delete(game.coc, colony) place_american_pc(space) }, pass() { @@ -1082,7 +1096,7 @@ function goto_for_the_king() { log(".h2.british For the King") logbr() delete game.coc - game.active = BRITISH + game.active = P_BRITAIN game.state = "for_the_king" game.count = 3 gen_british_pc_ops_start() @@ -1122,7 +1136,7 @@ function automatic_victory() { if (n_american === 0) { game.victory = "British Automatic Victory!" game.active = "None" - game.result = BRITISH + game.result = P_BRITAIN game.state = "game_over" log(game.victory) return true @@ -1130,7 +1144,7 @@ function automatic_victory() { if (n_british === 0) { game.victory = "American Automatic Victory!" game.active = "None" - game.result = AMERICAN + game.result = P_AMERICA game.state = "game_over" log(game.victory) return true @@ -1184,27 +1198,26 @@ function goto_start_year() { if (game.year === 1776) { game.deck.push(DECLARATION_OF_INDEPENDENCE) game.deck.push(BARON_VON_STEUBEN) + shuffle(game.deck) } if (game.reshuffle) reshuffle_deck() - game.a_hand = [] - game.b_hand = [] - for (let i = 0; i < 7; ++i) { - game.a_hand.push(deal_card()) - game.b_hand.push(deal_card()) - } - game.a_queue = 0 game.b_queue = 0 - game.did_discard_event = false + game.did_discard_event = 0 - // TODO: save the played card numbers instead (rule 6.1B clarification) - game.played_british_reinforcements = 0 - game.played_american_reinforcements = [] - game.active = BRITISH + game.reinforcements = [0,0,0] + game.active = P_BRITAIN game.state = "british_declare_first" + + game.a_hand = [] + game.b_hand = [] + for (let i = 0; i < 7; ++i) { + set_add(game.a_hand, deal_card()) + set_add(game.b_hand, deal_card()) + } } states.british_declare_first = { @@ -1220,14 +1233,14 @@ states.british_declare_first = { card_campaign(c) { delete game.congress_was_dispersed logp("went first by playing a campaign card") - game.active = BRITISH + game.active = P_BRITAIN goto_campaign(c) }, pass() { if (game.congress_was_dispersed) - game.active = BRITISH + game.active = P_BRITAIN else - game.active = AMERICAN + game.active = P_AMERICA game.state = "choose_first_player" delete game.congress_was_dispersed }, @@ -1236,16 +1249,16 @@ states.british_declare_first = { states.choose_first_player = { prompt() { view.prompt = "Choose who will play the first strategy card." - gen_action("american_first") - gen_action("british_first") + view.actions.america_first = 1 + view.actions.britain_first = 1 }, - american_first() { + america_first() { logp("went first") - goto_strategy_phase(AMERICAN) + goto_strategy_phase(P_AMERICA) }, - british_first() { + britain_first() { logp("went first") - goto_strategy_phase(BRITISH) + goto_strategy_phase(P_BRITAIN) }, } @@ -1255,7 +1268,7 @@ function goto_strategy_phase(new_active) { game.active = new_active game.state = "strategy_phase" logbr() - if (game.active === AMERICAN) + if (game.active === P_AMERICA) log(".h2.american American Turn") else log(".h2.british British Turn") @@ -1269,40 +1282,40 @@ states.strategy_phase = { gen_strategy_plays(active_hand()) }, card_campaign(c) { - game.did_discard_event = false + game.did_discard_event = 0 clear_queue() goto_campaign(c) }, card_play_event(c) { push_undo() - game.did_discard_event = false + game.did_discard_event = 0 clear_queue() do_event(c) }, card_discard_event(c) { push_undo() - game.did_discard_event = true + game.did_discard_event = 0 clear_queue() discard_card(c, "PC action") game.state = "discard_event_pc_action" }, card_ops_pc(c) { push_undo() - game.did_discard_event = false + game.did_discard_event = 0 clear_queue() play_card(c, "for PC") goto_ops_pc(CARDS[c].count) }, card_ops_reinforcements(c) { push_undo() - game.did_discard_event = false + game.did_discard_event = 0 clear_queue() goto_ops_reinforcements(c) }, card_ops_queue(c) { - game.did_discard_event = false + game.did_discard_event = 0 play_card(c, "to queue") - if (game.active === BRITISH) + if (game.active === P_BRITAIN) game.b_queue += CARDS[c].count else game.a_queue += CARDS[c].count @@ -1310,14 +1323,14 @@ states.strategy_phase = { }, card_ops_general(c) { push_undo() - game.did_discard_event = false + game.did_discard_event = 0 goto_ops_general(c) }, exchange_for_discard(c) { - game.did_discard_event = false - let d = game.discard.pop() + let d = game.did_discard_event = 0 + game.did_discard_event = 0 discard_card(c) - active_hand().push(d) + set_add(active_hand(), d) logp("picked up up #" + d) }, } @@ -1344,7 +1357,7 @@ function end_strategy_card() { game.french_alliance_triggered = true if (game.french_navy === -1) { game.save_active = game.active - game.active = AMERICAN + game.active = P_AMERICA game.state = "place_french_navy_trigger" return } @@ -1366,7 +1379,7 @@ function end_strategy_card() { } function clear_queue() { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) game.b_queue = 0 else game.a_queue = 0 @@ -1395,13 +1408,13 @@ function gen_strategy_plays(hand) { break case "british-event": case "british-event-or-battle": - if (game.active === BRITISH) + if (game.active === P_BRITAIN) if (can_play_event(c)) gen_action("card_play_event", c) gen_action("card_discard_event", c) break case "american-event": - if (game.active === AMERICAN) + if (game.active === P_AMERICA) if (can_play_event(c)) gen_action("card_play_event", c) gen_action("card_discard_event", c) @@ -1420,7 +1433,7 @@ states.discard_event_pc_action = { prompt() { view.prompt = "Place, flip, or remove PC marker." gen_pass() - if (game.active === BRITISH) + if (game.active === P_BRITAIN) gen_british_discard_event_pc_action() else gen_american_discard_event_pc_action() @@ -1479,7 +1492,7 @@ function gen_american_discard_event_pc_action() { function goto_ops_pc(count) { game.count = count game.state = "ops_pc" - if (game.active === BRITISH) + if (game.active === P_BRITAIN) gen_british_pc_ops_start() } @@ -1488,7 +1501,7 @@ states.ops_pc = { view.prompt = "Place or flip PC markers. " + game.count + " left." gen_pass() if (game.count > 0) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) gen_british_pc_ops() else gen_american_pc_ops() @@ -1510,7 +1523,7 @@ states.ops_pc = { --game.count }, pass() { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) gen_british_pc_ops_end() end_strategy_card() }, @@ -1521,7 +1534,7 @@ function gen_british_pc_ops_start() { for (let space of all_spaces) { if (has_no_pc(space) && has_no_american_unit(space)) { if (is_adjacent_to_british_pc(space)) - game.british_pc_space_list.push(space) + set_add(game.british_pc_space_list, space) } } } @@ -1559,12 +1572,15 @@ function gen_american_pc_ops() { function goto_ops_reinforcements(c) { let count = CARDS[c].count play_card(c, "for reinforcements") - if (game.active === BRITISH) { - game.played_british_reinforcements = count + if (game.active === P_BRITAIN) { + game.reinforcements[0] = c game.count = count_british_cu(BRITISH_REINFORCEMENTS) game.state = "ops_british_reinforcements_who" } else { - game.played_american_reinforcements.push(count) + if (game.reinforcements[1] === 0) + game.reinforcements[1] = c + else + game.reinforcements[2] = c game.count = count game.state = "ops_american_reinforcements_who" } @@ -1696,7 +1712,7 @@ function gen_american_reinforcements_where(general) { function goto_ops_general(c) { play_card(c, " to activate a general") - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { game.count = CARDS[c].count + game.b_queue game.b_queue = 0 } else { @@ -1752,7 +1768,7 @@ function gen_landing_party() { } function gen_activate_general() { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return gen_activate_british_general() else return gen_activate_american_general() @@ -1781,7 +1797,7 @@ states.remove_general = { gen_remove_general() }, select_general(g) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else move_general(g, AMERICAN_REINFORCEMENTS) @@ -1799,7 +1815,7 @@ states.remove_general_after_intercept = { gen_remove_general() }, select_general(g) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else move_general(g, AMERICAN_REINFORCEMENTS) @@ -1818,7 +1834,7 @@ states.remove_general_after_retreat = { gen_remove_general() }, select_general(g) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else move_general(g, AMERICAN_REINFORCEMENTS) @@ -1827,7 +1843,7 @@ states.remove_general_after_retreat = { } function gen_remove_general() { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) return gen_remove_british_general() else return gen_remove_american_general() @@ -1853,7 +1869,7 @@ function goto_ops_general_move(g, marblehead) { game.mobility = false game.count = 6 } else { - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { game.mobility = false game.count = 4 } else { @@ -1862,7 +1878,7 @@ function goto_ops_general_move(g, marblehead) { } } let where = location_of_general(g) - if (game.active === BRITISH) + if (game.active === P_BRITAIN) pickup_max_british_cu(where) else pickup_max_american_cu(where) @@ -1937,7 +1953,7 @@ states.ops_general_move = { let cu = game.carry_british + game.carry_american + game.carry_french let intercept = false - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { let is_sea_move = path_type(from, to) === "sea" if (has_american_pc(to) && cu > 0 && !is_sea_move && !has_british_cu(to)) intercept = can_intercept_to(to) @@ -1949,7 +1965,7 @@ states.ops_general_move = { if (has_enemy_general(to) && !has_enemy_cu(to)) { capture_enemy_general(to) } - if (game.active === BRITISH && game.congress === to && !has_enemy_cu(to)) { + if (game.active === P_BRITAIN && game.congress === to && !has_enemy_cu(to)) { disperse_continental_congress() } if (cu >= 4 && count_enemy_cu(to) === 1 && !has_enemy_general(to)) { @@ -2007,7 +2023,7 @@ function goto_intercept(from, where) { game.who = NOBODY game.from = from game.where = where - game.active = AMERICAN + game.active = P_AMERICA game.state = "intercept" } @@ -2051,7 +2067,7 @@ states.intercept = { } function end_intercept() { - game.active = BRITISH + game.active = P_BRITAIN game.state = "ops_general_move" game.who = game.save_who delete game.save_who @@ -2083,7 +2099,7 @@ function path_type(from, to) { function gen_carry_cu() { let where = location_of_general(game.who) - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { if (game.carry_british > 0) gen_action("drop_british_cu") if (game.carry_british < 5 && game.carry_british < count_unmoved_british_cu(where)) @@ -2144,7 +2160,7 @@ function gen_move_general() { gen_action("move", to) } } - if (game.active === BRITISH && game.count === 4) { + if (game.active === P_BRITAIN && game.count === 4) { if (is_non_blockaded_port(from)) { for (let to of all_spaces) { if (to !== from) { @@ -2169,7 +2185,7 @@ function goto_campaign(c) { play_card(c) game.state = "campaign" game.campaign = CARDS[c].count - game.landing_party = game.active === BRITISH ? 1 : 0 + game.landing_party = game.active === P_BRITAIN ? 1 : 0 game.count = 3 // can activate any general! game.state = "ops_general_who" } @@ -2180,10 +2196,8 @@ events.the_war_ends = function (c, card) { logp("played #" + c) log("The war will end in " + card.year) game.last_played = c - array_remove_item(active_hand(), c) - if (game.war_ends) - game.discard.push(WAR_ENDS_1779 + game.war_ends - 1779) - game.war_ends = card.year + set_delete(active_hand(), c) + game.war_ends = c end_strategy_card() } @@ -2578,7 +2592,7 @@ states.john_glovers_marblehead_regiment_who = { events.declaration_of_independence = function (c, card) { play_card(c) game.last_active = game.active - game.active = AMERICAN + game.active = P_AMERICA game.doi = THE_13_COLONIES.slice() game.state = "declaration_of_independence" } @@ -2592,7 +2606,7 @@ states.declaration_of_independence = { }, place_american_pc(space) { let colony = SPACES[space].colony - array_remove_item(game.doi, colony) + set_delete(game.doi, colony) place_american_pc(space) if (game.doi.length === 0) end_declaration_of_independence() @@ -2616,7 +2630,7 @@ function goto_george_washington_captured() { game.last_count = game.count game.state = "george_washington_captured" - game.active = BRITISH + game.active = P_BRITAIN game.count = 5 } @@ -2675,14 +2689,14 @@ function goto_start_battle(from, where) { game.where = where game.a_bonus = 0 game.b_bonus = 0 - if (game.active === BRITISH && can_retreat_before_battle(where)) + if (game.active === P_BRITAIN && can_retreat_before_battle(where)) goto_retreat_before_battle() else goto_play_attacker_battle_card() } function goto_retreat_before_battle() { - game.active = AMERICAN + game.active = P_AMERICA game.who = find_american_or_french_general(game.where) game.state = "retreat_before_battle" } @@ -2729,7 +2743,7 @@ states.remove_general_after_retreat_before_battle = { gen_remove_general() }, select_general(g) { - if (game.active === BRITISH) + if (game.active === P_BRITAIN) move_general(g, BRITISH_REINFORCEMENTS) else move_general(g, AMERICAN_REINFORCEMENTS) @@ -2777,7 +2791,7 @@ function gen_defender_retreat() { if (can_defender_retreat(to)) gen_action("move", to) } - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { let can_sea_retreat = false if (is_non_blockaded_port(from)) { if (is_fortified_port(from)) { @@ -2822,7 +2836,7 @@ states.play_attacker_battle_card = { }, card_battle_play(c) { play_card(c, "for +2 DRM") - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { if (CARDS[c].event === "remove_benedict_arnold") remove_benedict_arnold() game.b_draw_after_battle = true @@ -2835,7 +2849,7 @@ states.play_attacker_battle_card = { }, card_battle_discard(c) { discard_card(c, "for +1 DRM") - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { game.b_draw_after_battle = true game.b_bonus += 1 } else { @@ -2862,7 +2876,7 @@ states.play_defender_battle_card = { }, card_battle_play(c) { play_card(c, "for +2 DRM") - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { if (CARDS[c].event === "remove_benedict_arnold") remove_benedict_arnold() game.b_draw_after_battle = true @@ -2875,7 +2889,7 @@ states.play_defender_battle_card = { }, card_battle_discard(c) { discard_card(c, "for +1 DRM") - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { game.b_draw_after_battle = true game.b_bonus += 1 } else { @@ -2892,7 +2906,7 @@ states.play_defender_battle_card = { function gen_battle_card() { for (let c of active_hand()) { let card = CARDS[c] - if (game.active === BRITISH) { + if (game.active === P_BRITAIN) { switch (card.type) { case "british-battle": case "british-event-or-battle": @@ -3081,13 +3095,13 @@ function resolve_battle() { a_log.push("Battle Total: " + (a_roll + a_drm)) let victor - if (game.active === BRITISH) - victor = b_roll + b_drm >= a_roll + a_drm ? BRITISH : AMERICAN + if (game.active === P_BRITAIN) + victor = b_roll + b_drm >= a_roll + a_drm ? P_BRITAIN : P_AMERICA else - victor = b_roll + b_drm >= a_roll + a_drm ? BRITISH : AMERICAN + victor = b_roll + b_drm >= a_roll + a_drm ? P_BRITAIN : P_AMERICA let a_lost_cu, b_lost_cu - if (victor === BRITISH) { + if (victor === P_BRITAIN) { b_lost_cu = roll_winner_combat_losses(b_log, a_g) a_lost_cu = roll_loser_combat_losses(a_log) } else { @@ -3102,7 +3116,7 @@ function resolve_battle() { a_log.push("Losses: " + american_losses + " CU") // Special case: winning general with no CU on enemy PC is captured - if (victor === BRITISH) { + if (victor === P_BRITAIN) { if (b_g && count_british_cu(game.where) === 0 && has_american_pc(game.where)) capture_british_general(game.where) } else { @@ -3114,14 +3128,14 @@ function resolve_battle() { log("AMERICAN BATTLE REPORT:\n" + a_log.join("\n")) log(victor + " victory in " + game.where + "!") - if (victor === AMERICAN) + if (victor === P_AMERICA) advance_french_alliance(1) goto_retreat_after_battle(victor) } function goto_retreat_after_battle(victor) { - if (victor === BRITISH) { + if (victor === P_BRITAIN) { game.who = find_american_or_french_general(game.where) if (game.who === NOBODY && count_american_and_french_cu(game.where) === 0) return end_battle() @@ -3145,7 +3159,7 @@ states.retreat_after_battle = { }, move(to) { logp("retreated to " + to) - if (game.active === BRITISH) + if (game.active === P_BRITAIN) retreat_british_army(game.where, to) else retreat_american_army(game.where, to) @@ -3161,7 +3175,7 @@ states.retreat_after_battle = { end_battle() logp("surrendered") - if (active === BRITISH) + if (active === P_BRITAIN) surrender_british_army(where) else surrender_american_army(where) @@ -3171,7 +3185,7 @@ states.retreat_after_battle = { function end_battle() { game.active = game.attacker - if (game.active === BRITISH && game.congress === game.where) + if (game.active === P_BRITAIN && game.congress === game.where) disperse_continental_congress() if (game.british_losses >= 3) @@ -3179,9 +3193,9 @@ function end_battle() { // TODO: delay until end of campaign if (game.b_draw_after_battle) - game.b_hand.push(deal_card()) + set_add(game.b_hand, deal_card()) if (game.a_draw_after_battle) - game.a_hand.push(deal_card()) + set_add(game.a_hand, deal_card()) delete game.did_intercept delete game.b_bonus @@ -3271,7 +3285,7 @@ function goto_winter_attrition_phase() { function goto_french_naval_phase() { if (game.french_navy !== -1) { - game.active = AMERICAN + game.active = P_AMERICA game.state = "place_french_navy" } else { goto_political_control_phase() @@ -3436,7 +3450,7 @@ function gen_place_continental_congress() { function goto_political_control_phase() { if (game.congress === CONTINENTAL_CONGRESS_DISPERSED) { - game.active = AMERICAN + game.active = P_AMERICA game.state = "return_continental_congress" } else { goto_political_control_phase_2() @@ -3491,9 +3505,9 @@ function norths_government_falls() { ++n_american if (n_american >= 7) - game.result = AMERICAN + game.result = P_AMERICA else - game.result = BRITISH + game.result = P_BRITAIN game.victory = "North's Government Falls: " + game.result + " Victory!" game.active = "None" @@ -3506,13 +3520,13 @@ function goto_end_phase() { if (game.french_alliance_triggered && !game.european_war) { game.european_war = true game.count = 2 - game.active = AMERICAN + game.active = P_AMERICA game.state = "european_war" game.reshuffle = true return } - if ((game.war_ends && game.year >= game.war_ends) || game.year === 1783) + if ((game.war_ends && game.year >= CARDS[game.war_ends].year) || game.year === 1783) return norths_government_falls() delete game.pennsylvania_and_new_jersey_line_mutinies @@ -3563,8 +3577,7 @@ exports.view = function (state, current) { view = { year: state.year, war_ends: state.war_ends, - played_british_reinforcements: state.played_british_reinforcements, - played_american_reinforcements: state.played_american_reinforcements, + reinforcements: state.reinforcements, french_alliance: state.french_alliance, european_war: state.european_war, congress: state.congress, @@ -3587,9 +3600,9 @@ exports.view = function (state, current) { if (state.pennsylvania_and_new_jersey_line_mutinies) view.pennsylvania_and_new_jersey_line_mutinies = true - if (current === AMERICAN) + if (current === P_AMERICA) view.hand = state.a_hand - else if (current === BRITISH) + else if (current === P_BRITAIN) view.hand = state.b_hand else view.hand = [] @@ -3602,7 +3615,7 @@ exports.view = function (state, current) { let inactive = states[game.state].inactive if (typeof inactive !== "string") inactive = game.state - view.prompt = "Waiting for " + game.active + " player \u2014 " + inactive + "." + view.prompt = "Waiting for " + game.active + " to " + inactive + "." } return view |