diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-05-12 11:38:01 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-05-12 11:38:01 +0200 |
commit | a77e31881609683c45ef8e010f8ecce63738d235 (patch) | |
tree | abcab4e514e333c8df44d4c5bb65160ddbf36dc9 /rules.js | |
parent | 76dc6e30cdae5bcf011cd414447dc683e5bc3c47 (diff) | |
download | washingtons-war-a77e31881609683c45ef8e010f8ecce63738d235.tar.gz |
stricteq
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 328 |
1 files changed, 164 insertions, 164 deletions
@@ -244,7 +244,7 @@ function create_deck() { let 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) + if (i === DECLARATION_OF_INDEPENDENCE || i === BARON_VON_STEUBEN) continue; deck.push(i); } @@ -263,7 +263,7 @@ function roll_d6() { } function deal_card() { - if (game.deck.length == 0) + if (game.deck.length === 0) reshuffle_deck(); let i = random(game.deck.length); let c = game.deck[i]; @@ -278,7 +278,7 @@ function last_discard() { } function active_hand() { - return (game.active == AMERICAN) ? game.a_hand : game.b_hand; + return (game.active === AMERICAN) ? game.a_hand : game.b_hand; } function play_card(c, reason) { @@ -286,7 +286,7 @@ function play_card(c, reason) { log(game.active[0] + " played #" + c + " " + reason); else log(game.active[0] + " played #" + c); - if (CARDS[c].reshuffle == 'if_played') + if (CARDS[c].reshuffle === 'if_played') game.reshuffle = true; remove_from_array(active_hand(), c); game.last_played = c; @@ -299,7 +299,7 @@ function play_card(c, reason) { function discard_card_from_hand(hand, c) { remove_from_array(hand, c); game.discard.push(c); - if (CARDS[c].reshuffle == 'if_discarded') + if (CARDS[c].reshuffle === 'if_discarded') game.reshuffle = true; logp("discarded #" + c); } @@ -315,7 +315,7 @@ function discard_card(c, reason) { function can_exchange_for_discard(c) { if (game.did_discard_event) { - if (game.active == BRITISH) + if (game.active === BRITISH) return true; return CARDS[c].count > 1; } @@ -336,17 +336,17 @@ function can_play_event(c) { } function can_play_reinforcements() { - if (game.active == BRITISH) { - if (game.played_british_reinforcements == 0) { + if (game.active === BRITISH) { + if (game.played_british_reinforcements === 0) { let n = count_british_cu(BRITISH_REINFORCEMENTS); for (let g of BRITISH_GENERALS) - if (game.generals[g].location == BRITISH_REINFORCEMENTS) + if (game.generals[g].location === BRITISH_REINFORCEMENTS) ++n; return n > 0; } return false; } - if (game.active == AMERICAN) + if (game.active === AMERICAN) return game.played_american_reinforcements.length < 2; return false; } @@ -356,25 +356,25 @@ function is_port(where) { } function is_non_blockaded_port(where) { - if (SPACES[where].port && BLOCKADE[where] != game.french_navy) + if (SPACES[where].port && BLOCKADE[where] !== game.french_navy) return true; return false; } function is_fortified_port(where) { - return SPACES[where].type == 'fortified-port'; + return SPACES[where].type === 'fortified-port'; } function is_continental_congress_dispersed() { - return game.congress == CONTINENTAL_CONGRESS_DISPERSED; + return game.congress === CONTINENTAL_CONGRESS_DISPERSED; } function is_winter_quarter_space(where) { let colony = SPACES[where].colony; - if (colony == 'GA' || colony == 'SC' || colony == 'NC') + if (colony === 'GA' || colony === 'SC' || colony === 'NC') return true; // south of winter attrition line let type = SPACES[where].type; - if (type == 'winter-quarters' || type == 'fortified-port') + if (type === 'winter-quarters' || type === 'fortified-port') return true; return false; } @@ -388,15 +388,15 @@ function allowed_to_place_american_pc() { } function is_british_militia(space) { - return game.control[SPACES[space].colony] == BRITISH; + return game.control[SPACES[space].colony] === BRITISH; } function is_american_militia(space) { - return game.control[SPACES[space].colony] == AMERICAN; + return game.control[SPACES[space].colony] === AMERICAN; } function is_american_winter_offensive() { - if (game.who == WASHINGTON && game.a_hand.length == 0) + if (game.who === WASHINGTON && game.a_hand.length === 0) return true; return false; } @@ -404,19 +404,19 @@ function is_american_winter_offensive() { /* PC */ function has_no_pc(space) { - return game.pc[space] != BRITISH && game.pc[space] != AMERICAN; + return game.pc[space] !== BRITISH && game.pc[space] !== AMERICAN; } function has_british_pc(space) { - return game.pc[space] == BRITISH; + return game.pc[space] === BRITISH; } function has_american_pc(space) { - return game.pc[space] == AMERICAN; + return game.pc[space] === AMERICAN; } function has_enemy_pc(space) { - if (game.active == BRITISH) + if (game.active === BRITISH) return has_american_pc(space); else return has_british_pc(space); @@ -456,7 +456,7 @@ function place_american_pc(space) { } function remove_pc(space) { - if (game.active == BRITISH) + if (game.active === BRITISH) logp("removed PC in " + space); else logp("removed PC in " + space); @@ -464,7 +464,7 @@ function remove_pc(space) { } function flip_pc(space) { - if (game.active == BRITISH) + if (game.active === BRITISH) logp("flipped PC in " + space); else logp("flipped PC in " + space); @@ -475,9 +475,9 @@ function update_colony_control() { for (let c in COLONIES) { let control = 0; for (let space of COLONIES[c]) { - if (game.pc[space] == BRITISH) + if (game.pc[space] === BRITISH) --control; - else if (game.pc[space] == AMERICAN) + else if (game.pc[space] === AMERICAN) ++control; } if (control < 0) @@ -494,7 +494,7 @@ function update_colony_control() { function find_cu(owner, space) { for (let i = 0; i < game.cu.length; ++i) { let cu = game.cu[i]; - if (cu.location == space && cu.owner == owner) + if (cu.location === space && cu.owner === owner) return cu; } return null; @@ -513,7 +513,7 @@ function find_french_cu(space) { } function has_british_cu(space) { - return find_british_cu(space) != null; + return find_british_cu(space) !== null; } function has_no_british_cu(space) { @@ -521,19 +521,19 @@ function has_no_british_cu(space) { } function has_american_or_french_cu(space) { - return find_american_cu(space) != null || find_french_cu(space) != null; + return find_american_cu(space) !== null || find_french_cu(space) !== null; } function has_american_cu(space) { - return find_american_cu(space) != null; + return find_american_cu(space) !== null; } function has_french_cu(space) { - return find_french_cu(space) != null; + return find_french_cu(space) !== null; } function has_enemy_cu(where) { - if (game.active == BRITISH) + if (game.active === BRITISH) return has_american_or_french_cu(where); else return has_british_cu(where); @@ -584,7 +584,7 @@ function count_american_and_french_cu(where) { } function count_enemy_cu(where) { - if (game.active == BRITISH) + if (game.active === BRITISH) return count_american_and_french_cu(where); else return count_british_cu(where); @@ -595,7 +595,7 @@ function spawn_cu(owner, where, count) { } function remove_cu(owner, where, count) { - if (count == 0) + if (count === 0) return; let cu = find_cu(owner, where); if (count >= cu.count) { @@ -627,7 +627,7 @@ function place_french_cu(where, count) { } function move_cu(owner, from, to, count) { - if (count == 0) + if (count === 0) return; let from_cu = find_cu(owner, from); if (count < from_cu.count) { @@ -664,28 +664,28 @@ function is_general_on_map(g) { function find_british_general(where) { for (let general of BRITISH_GENERALS) - if (game.generals[general].location == where) + if (game.generals[general].location === where) return general; return null; } function find_american_or_french_general(where) { for (let general of AMERICAN_GENERALS) - if (game.generals[general].location == where) + if (game.generals[general].location === where) return general; return null; } function has_british_general(where) { - return find_british_general(where) != null; + return find_british_general(where) !== null; } function has_american_or_french_general(where) { - return find_american_or_french_general(where) != null; + return find_american_or_french_general(where) !== null; } function has_enemy_general(where) { - if (game.active == BRITISH) + if (game.active === BRITISH) return has_american_or_french_general(where); else return has_british_general(where); @@ -693,19 +693,19 @@ function has_enemy_general(where) { function count_friendly_generals(where) { let list; - if (game.active == BRITISH) + if (game.active === BRITISH) list = BRITISH_GENERALS; else list = AMERICAN_GENERALS; let count = 0; for (let g of list) - if (location_of_general(g) == where) + if (location_of_general(g) === where) ++count; return count; } function has_general_on_map() { - if (game.active == BRITISH) + if (game.active === BRITISH) return has_british_general_on_map(); else return has_american_general_on_map(); @@ -726,7 +726,7 @@ function has_american_general_on_map() { } function can_activate_general(c) { - if (game.active == BRITISH) + if (game.active === BRITISH) return can_activate_british_general(c); else return can_activate_american_general(c); @@ -773,14 +773,14 @@ function capture_british_general(where) { function capture_american_or_french_general(where) { let g = find_american_or_french_general(where); log(g + " was captured!"); - if (g == WASHINGTON) + if (g === WASHINGTON) capture_washington(); else move_general(g, CAPTURED_GENERALS); } function capture_enemy_general(where) { - if (game.active == BRITISH) + if (game.active === BRITISH) capture_american_or_french_general(where); else capture_british_general(where); @@ -818,7 +818,7 @@ function has_no_american_unit(where) { return false; if (has_american_or_french_cu(where)) return false; - if (game.congress == where) + if (game.congress === where) return false; return true; } @@ -837,7 +837,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 === BRITISH && game.congress === where) disperse_continental_congress(where); } } @@ -846,7 +846,7 @@ function place_american_reinforcements(who, count, where) { let already_there = find_american_or_french_general(where); if (who && already_there) { // Never replace Washington - if (already_there == WASHINGTON) + if (already_there === WASHINGTON) who = null; else move_general(already_there, AMERICAN_REINFORCEMENTS); @@ -865,7 +865,7 @@ function place_french_reinforcements(who, where) { let already_there = find_american_or_french_general(where); if (who && already_there) { // Never replace Washington - if (already_there == WASHINGTON) + if (already_there === WASHINGTON) who = null; else move_general(already_there, AMERICAN_REINFORCEMENTS); @@ -929,7 +929,7 @@ function intercept_army(who, from, to) { function overrun(where) { logp("overran CU in " + where); let cu; - if (game.active == BRITISH) + if (game.active === BRITISH) cu = find_american_cu(where) || find_french_cu(where); else cu = find_british_cu(where); @@ -978,7 +978,7 @@ function disperse_continental_congress(where) { function gen_action(action, argument) { if (!view.actions) view.actions = {} - if (argument != undefined) { + if (argument !== undefined) { if (!(action in view.actions)) view.actions[action] = [ argument ]; else @@ -1148,10 +1148,10 @@ function automatic_victory() { let n_british = 0; for (let space in SPACES) { n_american += count_french_cu(space) + count_american_cu(space); - if (SPACES[space].colony != "CA") + if (SPACES[space].colony !== "CA") n_british += count_british_cu(space); } - if (n_american == 0) { + if (n_american === 0) { game.victory = "British Automatic Victory!"; game.active = "None"; game.result = BRITISH; @@ -1159,7 +1159,7 @@ function automatic_victory() { log(game.victory); return true; } - if (n_british == 0) { + if (n_british === 0) { game.victory = "American Automatic Victory!"; game.active = "None"; game.result = AMERICAN; @@ -1177,10 +1177,10 @@ function goto_start_year() { // Prisoner exchange for (let g of BRITISH_GENERALS) - if (game.generals[g].location == CAPTURED_GENERALS) + if (game.generals[g].location === CAPTURED_GENERALS) move_general(g, BRITISH_REINFORCEMENTS); for (let g of AMERICAN_GENERALS) - if (game.generals[g].location == CAPTURED_GENERALS) + if (game.generals[g].location === CAPTURED_GENERALS) move_general(g, AMERICAN_REINFORCEMENTS); switch (game.year) { @@ -1195,7 +1195,7 @@ function goto_start_year() { case 1783: place_british_cu(BRITISH_REINFORCEMENTS, 1); break; } - if (game.year == 1776) { + if (game.year === 1776) { game.deck.push(DECLARATION_OF_INDEPENDENCE); game.deck.push(BARON_VON_STEUBEN); } @@ -1316,7 +1316,7 @@ states.strategy_phase = { card_ops_queue: function (c) { game.did_discard_event = false; play_card(c, "to queue"); - if (game.active == BRITISH) + if (game.active === BRITISH) game.b_queue += CARDS[c].count; else game.a_queue += CARDS[c].count; @@ -1353,10 +1353,10 @@ function end_strategy_card() { } } - if (!game.french_alliance_triggered && game.french_alliance == 9) { + if (!game.french_alliance_triggered && game.french_alliance === 9) { log("The French signed an alliance with the Americans!"); game.french_alliance_triggered = true; - if (game.french_navy == FRENCH_REINFORCEMENTS) { + if (game.french_navy === FRENCH_REINFORCEMENTS) { game.save_active = game.active; game.active = AMERICAN; game.state = 'place_french_navy_trigger'; @@ -1371,16 +1371,16 @@ function end_strategy_card() { goto_strategy_phase(ENEMY[game.active]); let hand = active_hand(); - if (hand.length == 0) { + if (hand.length === 0) { game.active = ENEMY[game.active]; hand = active_hand(); - if (hand.length == 0) + if (hand.length === 0) return goto_winter_attrition_phase(); } } function clear_queue() { - if (game.active == BRITISH) + if (game.active === BRITISH) game.b_queue = 0; else game.a_queue = 0; @@ -1409,13 +1409,13 @@ function gen_strategy_plays(hand) { break; case 'british-event': case 'british-event-or-battle': - if (game.active == BRITISH) + if (game.active === BRITISH) 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 === AMERICAN) if (can_play_event(c)) gen_action('card_play_event', c); gen_action('card_discard_event', c); @@ -1434,7 +1434,7 @@ states.discard_event_pc_action = { prompt: function (current) { view.prompt = "Place, flip, or remove PC marker."; gen_pass(); - if (game.active == BRITISH) + if (game.active === BRITISH) gen_british_discard_event_pc_action(); else gen_american_discard_event_pc_action(); @@ -1495,7 +1495,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 === BRITISH) gen_british_pc_ops_start(); } @@ -1504,7 +1504,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 === BRITISH) gen_british_pc_ops(); else gen_american_pc_ops() @@ -1526,7 +1526,7 @@ states.ops_pc = { --game.count; }, pass: function () { - if (game.active == BRITISH) + if (game.active === BRITISH) gen_british_pc_ops_end(); end_strategy_card(); }, @@ -1576,7 +1576,7 @@ function gen_american_pc_ops() { function goto_ops_reinforcements(c) { let count = CARDS[c].count; play_card(c, "for reinforcements"); - if (game.active == BRITISH) { + if (game.active === BRITISH) { game.played_british_reinforcements = count; game.count = count_british_cu(BRITISH_REINFORCEMENTS); game.state = 'ops_british_reinforcements_who'; @@ -1655,7 +1655,7 @@ states.ops_american_reinforcements_where = { gen_american_reinforcements_where(game.who); }, place_reinforcements: function (space) { - if (game.who == ROCHAMBEAU) + if (game.who === ROCHAMBEAU) place_french_reinforcements(game.who, space); else place_american_reinforcements(game.who, game.count, space); @@ -1667,7 +1667,7 @@ states.ops_american_reinforcements_where = { function gen_british_reinforcements_who() { for (let g of BRITISH_GENERALS) { let general = game.generals[g]; - if (general.location == BRITISH_REINFORCEMENTS) { + if (general.location === BRITISH_REINFORCEMENTS) { gen_action('select_general', g); } } @@ -1692,7 +1692,7 @@ function gen_british_reinforcements_where() { function gen_american_reinforcements_who() { for (let g of AMERICAN_GENERALS) { let general = game.generals[g]; - if (general.location == AMERICAN_REINFORCEMENTS) { + if (general.location === AMERICAN_REINFORCEMENTS) { gen_action('select_general', g); } } @@ -1701,7 +1701,7 @@ function gen_american_reinforcements_who() { function gen_american_reinforcements_where(general) { for (let space in SPACES) { if (!has_british_cu(space) && !has_british_pc(space)) { - if (general == ROCHAMBEAU) { + if (general === ROCHAMBEAU) { if (SPACES[space].port) gen_action('place_reinforcements', space); } else { @@ -1715,7 +1715,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 === BRITISH) { game.count = CARDS[c].count + game.b_queue; game.b_queue = 0; } else { @@ -1771,7 +1771,7 @@ function gen_landing_party() { } function gen_activate_general() { - if (game.active == BRITISH) + if (game.active === BRITISH) return gen_activate_british_general(); else return gen_activate_american_general(); @@ -1800,7 +1800,7 @@ states.remove_general = { gen_remove_general(); }, select_general: function (g) { - if (game.active == BRITISH) + if (game.active === BRITISH) move_general(g, BRITISH_REINFORCEMENTS); else move_general(g, AMERICAN_REINFORCEMENTS); @@ -1818,7 +1818,7 @@ states.remove_general_after_intercept = { gen_remove_general(); }, select_general: function (g) { - if (game.active == BRITISH) + if (game.active === BRITISH) move_general(g, BRITISH_REINFORCEMENTS); else move_general(g, AMERICAN_REINFORCEMENTS); @@ -1837,7 +1837,7 @@ states.remove_general_after_retreat = { gen_remove_general(); }, select_general: function (g) { - if (game.active == BRITISH) + if (game.active === BRITISH) move_general(g, BRITISH_REINFORCEMENTS); else move_general(g, AMERICAN_REINFORCEMENTS); @@ -1846,7 +1846,7 @@ states.remove_general_after_retreat = { } function gen_remove_general() { - if (game.active == BRITISH) + if (game.active === BRITISH) return gen_remove_british_general(); else return gen_remove_american_general(); @@ -1854,14 +1854,14 @@ function gen_remove_general() { function gen_remove_british_general() { for (let g of BRITISH_GENERALS) - if (location_of_general(g) == game.where) + if (location_of_general(g) === game.where) gen_action('select_general', g); } function gen_remove_american_general() { for (let g of AMERICAN_GENERALS) - if (g != WASHINGTON) - if (location_of_general(g) == game.where) + if (g !== WASHINGTON) + if (location_of_general(g) === game.where) gen_action('select_general', g); } @@ -1872,7 +1872,7 @@ function goto_ops_general_move(g, marblehead) { game.mobility = false; game.count = 6; } else { - if (game.active == BRITISH) { + if (game.active === BRITISH) { game.mobility = false; game.count = 4; } else { @@ -1881,7 +1881,7 @@ function goto_ops_general_move(g, marblehead) { } } let where = location_of_general(g); - if (game.active == BRITISH) + if (game.active === BRITISH) pickup_max_british_cu(where); else pickup_max_american_cu(where); @@ -1906,7 +1906,7 @@ states.ops_general_move = { } else { view.prompt += game.carry_american + " no CU."; } - if (game.count == 1) + if (game.count === 1) view.prompt += " " + game.count + " move left."; else if (game.count > 1) view.prompt += " " + game.count + " moves left."; @@ -1950,8 +1950,8 @@ states.ops_general_move = { let cu = game.carry_british + game.carry_american + game.carry_french; let intercept = false; - if (game.active == BRITISH) { - let is_sea_move = (path_type(from, to) == undefined); + if (game.active === BRITISH) { + let is_sea_move = (path_type(from, to) === undefined); if (has_american_pc(to) && cu > 0 && !is_sea_move && !has_british_cu(to)) intercept = can_intercept_to(to); } @@ -1962,10 +1962,10 @@ 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 === BRITISH && game.congress === to && !has_enemy_cu(to)) { disperse_continental_congress(to); } - if (cu >= 4 && count_enemy_cu(to) == 1 && !has_enemy_general(to)) { + if (cu >= 4 && count_enemy_cu(to) === 1 && !has_enemy_general(to)) { overrun(to); } } @@ -2096,7 +2096,7 @@ function path_name(from, to) { function gen_carry_cu() { let where = location_of_general(game.who); - if (game.active == BRITISH) { + if (game.active === BRITISH) { if (game.carry_british > 0) gen_action('drop_british_cu'); if (game.carry_british < 5 && game.carry_british < count_unmoved_british_cu(where)) @@ -2124,12 +2124,12 @@ function movement_cost(from, to) { function gen_move_general() { let from = location_of_general(game.who); - let alone = (game.carry_british + game.carry_american + game.carry_french) == 0; + let alone = (game.carry_british + game.carry_american + game.carry_french) === 0; for (let to of SPACES[from].exits) { let mp = 1; - if (path_type(from, to) == 'wilderness') { - if (path_name(from, to) == FALMOUTH_QUEBEC) - if (game.who != ARNOLD) + if (path_type(from, to) === 'wilderness') { + if (path_name(from, to) === FALMOUTH_QUEBEC) + if (game.who !== ARNOLD) continue; mp = 3; } @@ -2140,7 +2140,7 @@ function gen_move_general() { if (has_enemy_pc(to)) continue; // TODO: more robust check for not stopping (or allow undo in case he gets stuck) - if (has_enemy_general(to) && game.count - mp == 0) + if (has_enemy_general(to) && game.count - mp === 0) continue; } @@ -2152,10 +2152,10 @@ function gen_move_general() { gen_action('move', to); } } - if (game.active == BRITISH && game.count == 4) { + if (game.active === BRITISH && game.count === 4) { if (is_non_blockaded_port(from)) { for (let to in SPACES) { - if (to != from) { + if (to !== from) { if (is_non_blockaded_port(to)) { if (!has_american_pc(to) && !has_american_or_french_cu(to)) { // don't leave alone @@ -2177,7 +2177,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 === BRITISH ? 1 : 0; game.count = 3; // can activate any general! game.state = 'ops_general_who'; } @@ -2212,7 +2212,7 @@ function remove_random_card(hand) { let i = random(hand.length); let c = hand[i]; discard_card_from_hand(hand, c); - if (CARDS[c].type == 'mandatory-event') + if (CARDS[c].type === 'mandatory-event') do_event(c); else end_strategy_card(); @@ -2274,7 +2274,7 @@ states.remove_british_pc_from = { }, remove_pc: function (where) { remove_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { delete game.where; end_strategy_card(); } @@ -2299,7 +2299,7 @@ states.remove_american_pc = { }, remove_pc: function (where) { remove_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { end_strategy_card(); } }, @@ -2323,7 +2323,7 @@ states.remove_american_pc_from = { }, remove_pc: function (where) { remove_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { delete game.where; end_strategy_card(); } @@ -2349,7 +2349,7 @@ states.remove_american_pc_from_non_port = { }, remove_pc: function (where) { remove_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { delete game.where; end_strategy_card(); } @@ -2374,7 +2374,7 @@ states.remove_american_pc_within_two_spaces_of_a_british_general = { }, remove_pc: function (where) { remove_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { delete game.where; end_strategy_card(); } @@ -2399,7 +2399,7 @@ states.place_american_pc = { }, place_american_pc: function (where) { place_american_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { end_strategy_card(); } }, @@ -2423,7 +2423,7 @@ states.place_american_pc_in = { }, place_american_pc: function (where) { place_american_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { delete game.where; end_strategy_card(); } @@ -2454,7 +2454,7 @@ states.lord_sandwich_coastal_raids = { remove_pc: function (where) { game.where = where; remove_pc(where); - if (--game.count == 0) + if (--game.count === 0) end_strategy_card(); }, pass: function () { @@ -2467,7 +2467,7 @@ function gen_lord_sandwich_coastal_raids(first_removed) { if (SPACES[space].port) if (has_american_pc(space) && has_no_american_unit(space)) gen_action('remove_pc', space); - if (space == first_removed) + if (space === first_removed) gen_action('place_british_pc', space); } } @@ -2548,7 +2548,7 @@ states.pennsylvania_and_new_jersey_line_mutinies = { let cu = find_american_cu(where) || find_french_cu(where); remove_cu(cu.owner, where, 1); game.where = where; - if (--game.count == 0) + if (--game.count === 0) end_strategy_card(); }, pass: function () { @@ -2559,7 +2559,7 @@ states.pennsylvania_and_new_jersey_line_mutinies = { function gen_pennsylvania_and_new_jersey_line_mutinies(first_removed) { for (let space in SPACES) { if (has_american_or_french_cu(space)) - if (space != first_removed) + if (space !== first_removed) gen_action('remove_cu', space); } } @@ -2599,7 +2599,7 @@ states.declaration_of_independence = { let colony = SPACES[space].colony; remove_from_array(game.doi, colony); place_american_pc(space); - if (game.doi.length == 0) + if (game.doi.length === 0) end_declaration_of_independence(); }, pass: function () { @@ -2633,7 +2633,7 @@ states.george_washington_captured = { }, remove_pc: function (where) { remove_pc(where); - if (--game.count == 0) { + if (--game.count === 0) { end_george_washington_captured(); } }, @@ -2680,7 +2680,7 @@ 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 === BRITISH && can_retreat_before_battle(where)) goto_retreat_before_battle(); else goto_play_attacker_battle_card(); @@ -2734,7 +2734,7 @@ states.remove_general_after_retreat_before_battle = { gen_remove_general(); }, select_general: function (g) { - if (game.active == BRITISH) + if (game.active === BRITISH) move_general(g, BRITISH_REINFORCEMENTS); else move_general(g, AMERICAN_REINFORCEMENTS); @@ -2748,9 +2748,9 @@ states.remove_general_after_retreat_before_battle = { function end_remove_general_after_retreat_before_battle() { let b_cu = count_british_cu(game.where); let a_cu = count_american_and_french_cu(game.where); - if (a_cu == 0) { + if (a_cu === 0) { end_battle(); - } else if (b_cu >= 4 && a_cu == 1) { + } else if (b_cu >= 4 && a_cu === 1) { overrun(game.where); end_battle(); } else { @@ -2759,7 +2759,7 @@ function end_remove_general_after_retreat_before_battle() { } function can_defender_retreat(to) { - if (to == game.attack_from) + if (to === game.attack_from) return false; if (has_enemy_pc(to)) return false; @@ -2783,7 +2783,7 @@ function gen_defender_retreat() { if (can_defender_retreat(to)) gen_action('move', to); } - if (game.active == BRITISH) { + if (game.active === BRITISH) { let can_sea_retreat = false; if (is_non_blockaded_port(from)) { if (is_fortified_port(from)) { @@ -2795,7 +2795,7 @@ function gen_defender_retreat() { } if (can_sea_retreat) { for (let to in SPACES) { - if (to != from && is_non_blockaded_port(to)) { + if (to !== from && is_non_blockaded_port(to)) { if (!has_american_pc(to) && !has_american_or_french_cu(to)) { gen_action('move', to); } @@ -2828,8 +2828,8 @@ states.play_attacker_battle_card = { }, card_battle_play: function (c) { play_card(c, "for +2 DRM"); - if (game.active == BRITISH) { - if (CARDS[c].event == 'remove_benedict_arnold') + if (game.active === BRITISH) { + if (CARDS[c].event === 'remove_benedict_arnold') remove_benedict_arnold(); game.b_draw_after_battle = true; game.b_bonus += 2; @@ -2841,7 +2841,7 @@ states.play_attacker_battle_card = { }, card_battle_discard: function (c) { discard_card(c, "for +1 DRM"); - if (game.active == BRITISH) { + if (game.active === BRITISH) { game.b_draw_after_battle = true; game.b_bonus += 1; } else { @@ -2868,8 +2868,8 @@ states.play_defender_battle_card = { }, card_battle_play: function (c) { play_card(c, "for +2 DRM"); - if (game.active == BRITISH) { - if (CARDS[c].event == 'remove_benedict_arnold') + if (game.active === BRITISH) { + if (CARDS[c].event === 'remove_benedict_arnold') remove_benedict_arnold(); game.b_draw_after_battle = true; game.b_bonus += 2; @@ -2881,7 +2881,7 @@ states.play_defender_battle_card = { }, card_battle_discard: function (c) { discard_card(c, "for +1 DRM"); - if (game.active == BRITISH) { + if (game.active === BRITISH) { game.b_draw_after_battle = true; game.b_bonus += 1; } else { @@ -2898,7 +2898,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 === BRITISH) { switch (card.type) { case 'british-battle': case 'british-event-or-battle': @@ -2945,7 +2945,7 @@ function roll_winner_combat_losses(log, losing_general) { log.push("Winner Combat Loss Roll: " + roll); let losses = 0; switch (agility) { - case 0: losses = (roll == 1) ? 1 : 0; break; + case 0: losses = (roll === 1) ? 1 : 0; break; case 1: losses = (roll <= 2) ? 1 : 0; break; case 2: losses = (roll <= 3) ? 1 : 0; break; case 3: losses = (roll <= 4) ? 1 : 0; break; @@ -3056,9 +3056,9 @@ function resolve_battle() { b_log.push("+1 Militia"); b_drm += 1; } - if (game.b_bonus == 2) + if (game.b_bonus === 2) b_log.push("+2 Battle Card"); - else if (game.b_bonus == 1) + else if (game.b_bonus === 1) b_log.push("+1 Discard of an Event Card"); let a_drm = a_cu + a_br + game.a_bonus; @@ -3070,9 +3070,9 @@ function resolve_battle() { a_log.push("+2 American Winter Offensive"); a_drm += 2; } - if (game.a_bonus == 2) + if (game.a_bonus === 2) a_log.push("+2 Battle Card"); - else if (game.a_bonus == 1) + else if (game.a_bonus === 1) a_log.push("+1 Discard of an Event Card"); if (game.did_intercept) { a_log.push("+1 Interception"); @@ -3088,13 +3088,13 @@ function resolve_battle() { a_log.push("Battle Total: " + (a_roll + a_drm)); let victor; - if (game.active == BRITISH) + if (game.active === BRITISH) victor = (b_roll + b_drm) >= (a_roll + a_drm) ? BRITISH : AMERICAN; else victor = (b_roll + b_drm) >= (a_roll + a_drm) ? BRITISH : AMERICAN; let a_lost_cu, b_lost_cu; - if (victor == BRITISH) { + if (victor === BRITISH) { b_lost_cu = roll_winner_combat_losses(b_log, a_g); a_lost_cu = roll_loser_combat_losses(a_log); } else { @@ -3109,11 +3109,11 @@ 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 (b_g && count_british_cu(game.where) == 0 && has_american_pc(game.where)) + if (victor === BRITISH) { + if (b_g && count_british_cu(game.where) === 0 && has_american_pc(game.where)) capture_british_general(game.where); } else { - if (a_g && count_american_and_french_cu(game.where) == 0 && has_british_pc(game.where)) + if (a_g && count_american_and_french_cu(game.where) === 0 && has_british_pc(game.where)) capture_american_or_french_general(game.where); } @@ -3121,20 +3121,20 @@ function resolve_battle() { log("AMERICAN BATTLE REPORT:\n" + a_log.join("\n")); log(victor + " victory in " + game.where + "!"); - if (victor == AMERICAN) + if (victor === AMERICAN) advance_french_alliance(1); goto_retreat_after_battle(victor); } function goto_retreat_after_battle(victor) { - if (victor == BRITISH) { + if (victor === BRITISH) { game.who = find_american_or_french_general(game.where); - if (game.who == null && count_american_and_french_cu(game.where) == 0) + if (game.who === null && count_american_and_french_cu(game.where) === 0) return end_battle(); } else { game.who = find_british_general(game.where); - if (game.who == null && count_british_cu(game.where) == 0) + if (game.who === null && count_british_cu(game.where) === 0) return end_battle(); } game.active = ENEMY[victor]; @@ -3145,14 +3145,14 @@ states.retreat_after_battle = { prompt: function (current) { view.prompt = "Retreat after battle."; gen_action('surrender'); - if (game.active == game.attacker) + if (game.active === game.attacker) gen_attacker_retreat(); else gen_defender_retreat(); }, move: function (to) { logp("retreated to " + to); - if (game.active == BRITISH) + if (game.active === BRITISH) retreat_british_army(game.where, to); else retreat_american_army(game.where, to); @@ -3168,7 +3168,7 @@ states.retreat_after_battle = { end_battle(); logp("surrendered"); - if (active == BRITISH) + if (active === BRITISH) surrender_british_army(where); else surrender_american_army(where); @@ -3178,7 +3178,7 @@ states.retreat_after_battle = { function end_battle() { game.active = game.attacker; - if (game.active == BRITISH && game.congress == game.where) + if (game.active === BRITISH && game.congress === game.where) disperse_continental_congress(game.where); if (game.british_losses >= 3) @@ -3229,21 +3229,21 @@ function goto_winter_attrition_phase() { let n_british = count_british_cu(space); let n_american = count_american_cu(space); let n_french = count_french_cu(space); - let has_washington = game.generals[WASHINGTON].location == space; + let has_washington = game.generals[WASHINGTON].location === space; - if (n_british == 1 && !wq) + if (n_british === 1 && !wq) apply_single_winter_attrition(BRITISH, space, has_british_general(space)); if (n_british > 1 && !wq) apply_winter_attrition(BRITISH, space, n_british); - if (n_american == 0 && n_french == 1 && !wq) + if (n_american === 0 && n_french === 1 && !wq) apply_single_winter_attrition(FRENCH, space, has_american_or_french_general(space)); - if (n_american == 0 && n_french > 1 && !wq) + if (n_american === 0 && n_french > 1 && !wq) apply_winter_attrition(FRENCH, space, n_french); - if (n_american == 1 && n_french == 0) + if (n_american === 1 && n_french === 0) apply_single_winter_attrition(AMERICAN, space, has_american_or_french_general(space)); - if (n_american > 1 && n_french == 0) { + if (n_american > 1 && n_french === 0) { let n = n_american; if (has_washington && wq) n = Math.max(0, n - 5); @@ -3277,7 +3277,7 @@ function goto_winter_attrition_phase() { } function goto_french_naval_phase() { - if (game.french_navy != FRENCH_REINFORCEMENTS) { + if (game.french_navy !== FRENCH_REINFORCEMENTS) { game.active = AMERICAN; game.state = 'place_french_navy'; } else { @@ -3341,7 +3341,7 @@ function place_pc_markers_segment() { function is_american_pc_root(space) { if (has_no_pc(space) && has_no_british_cu(space)) return true; - if (game.congress == space) + if (game.congress === space) return true; if (has_american_pc(space)) { if (has_american_or_french_cu(space)) @@ -3429,7 +3429,7 @@ function remove_isolated_british_pc_segment() { function gen_place_continental_congress() { let n = 0; for (let space in SPACES) { - if (SPACES[space].colony != 'CA') { + if (SPACES[space].colony !== 'CA') { if (has_american_pc(space) && has_no_british_playing_piece(space)) { gen_action('place_continental_congress', space); ++n; @@ -3440,7 +3440,7 @@ function gen_place_continental_congress() { } function goto_political_control_phase() { - if (game.congress == CONTINENTAL_CONGRESS_DISPERSED) { + if (game.congress === CONTINENTAL_CONGRESS_DISPERSED) { game.active = AMERICAN; game.state = 'return_continental_congress'; } else { @@ -3451,7 +3451,7 @@ function goto_political_control_phase() { states.return_continental_congress = { prompt: function () { view.prompt = "Return Continental Congress to a space in the 13 colonies."; - if (gen_place_continental_congress() == 0) + if (gen_place_continental_congress() === 0) gen_pass(); }, place_continental_congress: function (where) { @@ -3479,7 +3479,7 @@ states.european_war = { remove_cu: function (where) { let cu = find_british_cu(where); remove_cu(BRITISH, where, 1); - if (--game.count == 0) + if (--game.count === 0) goto_end_phase(); }, pass: function () { @@ -3492,7 +3492,7 @@ function norths_government_falls() { let n_american = 0; for (let c in COLONIES) - if (game.control[c] == AMERICAN) + if (game.control[c] === AMERICAN) ++n_american; if (n_american >= 7) @@ -3517,7 +3517,7 @@ function goto_end_phase() { return; } - if ((game.war_ends && game.year >= game.war_ends) || game.year == 1783) + if ((game.war_ends && game.year >= game.war_ends) || game.year === 1783) return norths_government_falls(); delete game.pennsylvania_and_new_jersey_line_mutinies; @@ -3542,7 +3542,7 @@ exports.setup = function (seed, scenario, options) { exports.action = function (state, current, action, arg) { game = state; // TODO: check against action list - if (current == game.active) { + if (current === game.active) { let S = states[game.state]; if (action in S) { S[action](arg); @@ -3594,14 +3594,14 @@ 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 === AMERICAN) view.hand = state.a_hand; - else if (current == BRITISH) + else if (current === BRITISH) view.hand = state.b_hand; else view.hand = []; - if (current == state.active) { + if (current === state.active) { list_actions(current); gen_action_undo(); } else { |