summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-05-12 11:39:23 +0200
committerTor Andersson <tor@ccxvii.net>2024-05-12 11:39:23 +0200
commit6d7f13ac520fb1a99e0288ee0f297f78af276e9b (patch)
treeccc03c16fa4f42027066aab534cefcc9c63a5fd4 /rules.js
parentc284d3174cb8a0d3f4875b42f959294e7361fe9d (diff)
downloadwashingtons-war-6d7f13ac520fb1a99e0288ee0f297f78af276e9b.tar.gz
double quoted strings
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js565
1 files changed, 306 insertions, 259 deletions
diff --git a/rules.js b/rules.js
index 130adaf..c3f2642 100644
--- a/rules.js
+++ b/rules.js
@@ -3,17 +3,12 @@
// TODO: campaign messed up who is who after battle
// TODO: retreat with 0 CU after battle
-exports.scenarios = [
- "Historical"
-]
+exports.scenarios = [ "Historical" ]
-exports.roles = [
- "American",
- "British",
-]
+exports.roles = [ "American", "British" ]
-const CARDS = require('./cards')
-const DATA = require('./data')
+const CARDS = require("./cards")
+const DATA = require("./data")
const SPACES = DATA.SPACES
const COLONIES = DATA.COLONIES
const GENERALS = DATA.GENERALS
@@ -22,9 +17,9 @@ const PATH_INDEX = DATA.PATH_INDEX
const PATH_NAME = DATA.PATH_NAME
const PATH_TYPE = DATA.PATH_TYPE
-const BRITISH = 'British'
-const AMERICAN = 'American'
-const FRENCH = 'French'
+const BRITISH = "British"
+const AMERICAN = "American"
+const FRENCH = "French"
const BRITISH_GENERALS = [ "Burgoyne", "Carleton", "Clinton", "Cornwallis", "Howe" ]
const AMERICAN_GENERALS = [ "Arnold", "Gates", "Greene", "Lafayette", "Lee", "Lincoln", "Washington", "Rochambeau" ]
@@ -51,8 +46,8 @@ const TURN_TRACK = {
const FALMOUTH_QUEBEC = "Falmouth/Quebec"
-const THE_13_COLONIES = [ 'NH', 'NY', 'MA', 'CT', 'RI', 'PA', 'NJ', 'MD', 'DE', 'VA', 'NC', 'SC', 'GA' ]
-const SOUTH_OF_WINTER_ATTRITION_LINE = [ 'NC', 'SC', 'GA' ]
+const THE_13_COLONIES = [ "NH", "NY", "MA", "CT", "RI", "PA", "NJ", "MD", "DE", "VA", "NC", "SC", "GA" ]
+const SOUTH_OF_WINTER_ATTRITION_LINE = [ "NC", "SC", "GA" ]
const CAMPAIGN_CARDS = [ 67, 68, 69, 70 ]
const DECLARATION_OF_INDEPENDENCE = 99
@@ -60,7 +55,7 @@ const BARON_VON_STEUBEN = 86
const WAR_ENDS_1779 = 71
const BENJAMIN_FRANKLIN = 101
-const ENEMY = { "American": BRITISH, "British": AMERICAN }
+const ENEMY = { American: BRITISH, British: AMERICAN }
const default_options = {}
@@ -71,11 +66,11 @@ let game
let view
function random(n) {
- return (game.seed = game.seed * 200105 % 34359738337) % n
+ return (game.seed = (game.seed * 200105) % 34359738337) % n
}
function logbr() {
- if (game.log.length > 0 && game.log[game.log.length-1] !== "")
+ if (game.log.length > 0 && game.log[game.log.length - 1] !== "")
game.log.push("")
}
@@ -205,9 +200,15 @@ function setup_game(seed) {
}
}
- function british(place, pc, cu, ld) { spawn_unit(BRITISH, place, pc, cu, ld); }
- function american(place, pc, cu, ld) { spawn_unit(AMERICAN, place, pc, cu, ld); }
- function french(place, pc, cu, ld) { spawn_unit(FRENCH, place, pc, cu, ld); }
+ function british(place, pc, cu, ld) {
+ spawn_unit(BRITISH, place, pc, cu, ld)
+ }
+ function american(place, pc, cu, ld) {
+ spawn_unit(AMERICAN, place, pc, cu, ld)
+ }
+ function french(place, pc, cu, ld) {
+ spawn_unit(FRENCH, place, pc, cu, ld)
+ }
british("Quebec", true, 2, "Carleton")
british("Montreal", true)
@@ -273,12 +274,12 @@ function deal_card() {
function last_discard() {
if (game.discard.length > 0)
- return game.discard[game.discard.length-1]
+ return game.discard[game.discard.length - 1]
return null
}
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 +287,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 +300,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)
}
@@ -325,12 +326,16 @@ function can_exchange_for_discard(c) {
function can_play_event(c) {
let card = CARDS[c]
switch (card.when) {
- case 'before_french_alliance': return !game.french_alliance_triggered
- case 'after_french_alliance': return game.french_alliance_triggered
- case 'european_war_in_effect': return game.european_war
+ case "before_french_alliance":
+ return !game.french_alliance_triggered
+ case "after_french_alliance":
+ return game.french_alliance_triggered
+ case "european_war_in_effect":
+ return game.european_war
}
switch (card.event) {
- case 'john_glovers_marblehead_regiment': return has_general_on_map()
+ case "john_glovers_marblehead_regiment":
+ return has_general_on_map()
}
return true
}
@@ -362,7 +367,7 @@ function is_non_blockaded_port(where) {
}
function is_fortified_port(where) {
- return SPACES[where].type === 'fortified-port'
+ return SPACES[where].type === "fortified-port"
}
function is_continental_congress_dispersed() {
@@ -371,10 +376,10 @@ function is_continental_congress_dispersed() {
function is_winter_quarter_space(where) {
let colony = SPACES[where].colony
- if (colony === 'GA' || colony === 'SC' || colony === 'NC')
- return true; // south of winter attrition line
+ 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
}
@@ -591,7 +596,7 @@ function count_enemy_cu(where) {
}
function spawn_cu(owner, where, count) {
- game.cu.push({owner:owner, location:where, count:count, moved:0})
+ game.cu.push({ owner: owner, location: where, count: count, moved: 0 })
}
function remove_cu(owner, where, count) {
@@ -652,12 +657,12 @@ function move_british_cu(from, to, count) {
function is_general_on_map(g) {
switch (game.generals[g].location) {
- case null: /* killed */
- case CAPTURED_GENERALS:
- case BRITISH_REINFORCEMENTS:
- case AMERICAN_REINFORCEMENTS:
- case FRENCH_REINFORCEMENTS:
- return false
+ case null: /* killed */
+ case CAPTURED_GENERALS:
+ case BRITISH_REINFORCEMENTS:
+ case AMERICAN_REINFORCEMENTS:
+ case FRENCH_REINFORCEMENTS:
+ return false
}
return true
}
@@ -998,14 +1003,14 @@ function gen_action_undo() {
}
function gen_pass() {
- gen_action('pass')
+ gen_action("pass")
}
function gen_remove_british_pc_from(list_of_colonies) {
for (let colony of list_of_colonies) {
for (let space of COLONIES[colony]) {
if (has_british_pc(space) && has_no_british_cu(space)) {
- gen_action('remove_pc', space)
+ gen_action("remove_pc", space)
}
}
}
@@ -1014,7 +1019,7 @@ function gen_remove_british_pc_from(list_of_colonies) {
function gen_remove_american_pc() {
for (let space in SPACES) {
if (has_american_pc(space) && has_no_american_unit(space)) {
- gen_action('remove_pc', space)
+ gen_action("remove_pc", space)
}
}
}
@@ -1023,7 +1028,7 @@ function gen_remove_american_pc_from(list_of_colonies) {
for (let colony of list_of_colonies) {
for (let space of COLONIES[colony]) {
if (has_american_pc(space) && has_no_american_unit(space)) {
- gen_action('remove_pc', space)
+ gen_action("remove_pc", space)
}
}
}
@@ -1034,7 +1039,7 @@ function gen_remove_american_pc_from_non_port(list_of_colonies) {
for (let space of COLONIES[colony]) {
if (!SPACES[space].port) {
if (has_american_pc(space) && has_no_american_unit(space)) {
- gen_action('remove_pc', space)
+ gen_action("remove_pc", space)
}
}
}
@@ -1057,13 +1062,13 @@ function gen_remove_american_pc_within_two_spaces_of_a_british_general() {
}
for (let space in candidates)
if (has_american_pc(space) && has_no_american_unit(space))
- gen_action('remove_pc', space)
+ gen_action("remove_pc", space)
}
function gen_place_american_pc() {
for (let space in SPACES) {
if (has_no_pc(space) && has_no_british_playing_piece(space)) {
- gen_action('place_american_pc', space)
+ gen_action("place_american_pc", space)
}
}
}
@@ -1072,7 +1077,7 @@ function gen_place_american_pc_in(list_of_colonies) {
for (let colony of list_of_colonies) {
for (let space of COLONIES[colony]) {
if (has_no_pc(space) && has_no_british_playing_piece(space)) {
- gen_action('place_american_pc', space)
+ gen_action("place_american_pc", space)
}
}
}
@@ -1084,14 +1089,15 @@ function goto_committees_of_correspondence() {
log(".h2.american Committes of Correspondence")
logbr()
game.active = AMERICAN
- game.state = 'committees_of_correspondence'
+ game.state = "committees_of_correspondence"
game.coc = THE_13_COLONIES.slice()
}
states.committees_of_correspondence = {
inactive: "Committees of Correspondence",
prompt: function (current) {
- view.prompt = "Committees of Correspondence: Place 1 PC marker in each of the 13 colonies. " + game.coc.length + " left."
+ view.prompt =
+ "Committees of Correspondence: Place 1 PC marker in each of the 13 colonies. " + game.coc.length + " left."
if (game.coc.length > 0)
gen_place_american_pc_in(game.coc)
else
@@ -1106,7 +1112,7 @@ states.committees_of_correspondence = {
pass: function () {
clear_undo()
goto_for_the_king()
- }
+ },
}
function goto_for_the_king() {
@@ -1115,7 +1121,7 @@ function goto_for_the_king() {
logbr()
delete game.coc
game.active = BRITISH
- game.state = 'for_the_king'
+ game.state = "for_the_king"
game.count = 3
gen_british_pc_ops_start()
}
@@ -1138,7 +1144,7 @@ states.for_the_king = {
clear_undo()
gen_british_pc_ops_end()
goto_start_year()
- }
+ },
}
/* REINFORCEMENTS AND START OF STRATEGY PHASE */
@@ -1155,7 +1161,7 @@ function automatic_victory() {
game.victory = "British Automatic Victory!"
game.active = "None"
game.result = BRITISH
- game.state = 'game_over'
+ game.state = "game_over"
log(game.victory)
return true
}
@@ -1163,7 +1169,7 @@ function automatic_victory() {
game.victory = "American Automatic Victory!"
game.active = "None"
game.result = AMERICAN
- game.state = 'game_over'
+ game.state = "game_over"
log(game.victory)
return true
}
@@ -1184,15 +1190,33 @@ function goto_start_year() {
move_general(g, AMERICAN_REINFORCEMENTS)
switch (game.year) {
- case 1775: place_british_cu(BRITISH_REINFORCEMENTS, 3); break
- case 1776: place_british_cu(BRITISH_REINFORCEMENTS, 8); break
- case 1777: place_british_cu(BRITISH_REINFORCEMENTS, 1); break
- case 1778: place_british_cu(BRITISH_REINFORCEMENTS, 8); break
- case 1779: place_british_cu(BRITISH_REINFORCEMENTS, 1); break
- case 1780: place_british_cu(BRITISH_REINFORCEMENTS, 5); break
- case 1781: place_british_cu(BRITISH_REINFORCEMENTS, 1); break
- case 1782: place_british_cu(BRITISH_REINFORCEMENTS, 1); break
- case 1783: place_british_cu(BRITISH_REINFORCEMENTS, 1); break
+ case 1775:
+ place_british_cu(BRITISH_REINFORCEMENTS, 3)
+ break
+ case 1776:
+ place_british_cu(BRITISH_REINFORCEMENTS, 8)
+ break
+ case 1777:
+ place_british_cu(BRITISH_REINFORCEMENTS, 1)
+ break
+ case 1778:
+ place_british_cu(BRITISH_REINFORCEMENTS, 8)
+ break
+ case 1779:
+ place_british_cu(BRITISH_REINFORCEMENTS, 1)
+ break
+ case 1780:
+ place_british_cu(BRITISH_REINFORCEMENTS, 5)
+ break
+ case 1781:
+ place_british_cu(BRITISH_REINFORCEMENTS, 1)
+ break
+ case 1782:
+ place_british_cu(BRITISH_REINFORCEMENTS, 1)
+ break
+ case 1783:
+ place_british_cu(BRITISH_REINFORCEMENTS, 1)
+ break
}
if (game.year === 1776) {
@@ -1218,7 +1242,7 @@ function goto_start_year() {
game.played_british_reinforcements = 0
game.played_american_reinforcements = []
game.active = BRITISH
- game.state = 'british_declare_first'
+ game.state = "british_declare_first"
}
states.british_declare_first = {
@@ -1227,7 +1251,7 @@ states.british_declare_first = {
gen_pass()
for (let c of CAMPAIGN_CARDS) {
if (game.b_hand.includes(c)) {
- gen_action('card_campaign', c)
+ gen_action("card_campaign", c)
}
}
},
@@ -1242,7 +1266,7 @@ states.british_declare_first = {
game.active = BRITISH
else
game.active = AMERICAN
- game.state = 'choose_first_player'
+ game.state = "choose_first_player"
delete game.congress_was_dispersed
},
}
@@ -1250,8 +1274,8 @@ states.british_declare_first = {
states.choose_first_player = {
prompt: function (current) {
view.prompt = "Choose who will play the first strategy card."
- gen_action('american_first')
- gen_action('british_first')
+ gen_action("american_first")
+ gen_action("british_first")
},
american_first: function (c) {
logp("went first")
@@ -1267,7 +1291,7 @@ states.choose_first_player = {
function goto_strategy_phase(new_active) {
game.active = new_active
- game.state = 'strategy_phase'
+ game.state = "strategy_phase"
logbr()
if (game.active === AMERICAN)
log(".h2.american American Turn")
@@ -1298,7 +1322,7 @@ states.strategy_phase = {
game.did_discard_event = true
clear_queue()
discard_card(c, "PC action")
- game.state = 'discard_event_pc_action'
+ game.state = "discard_event_pc_action"
},
card_ops_pc: function (c) {
push_undo()
@@ -1344,8 +1368,8 @@ function end_strategy_card() {
if (game.campaign) {
if (--game.campaign > 0) {
- game.count = 3; // can activate any general!
- game.state = 'ops_general_who'
+ game.count = 3 // can activate any general!
+ game.state = "ops_general_who"
return
} else {
delete game.landing_party
@@ -1359,7 +1383,7 @@ function end_strategy_card() {
if (game.french_navy === FRENCH_REINFORCEMENTS) {
game.save_active = game.active
game.active = AMERICAN
- game.state = 'place_french_navy_trigger'
+ game.state = "place_french_navy_trigger"
return
}
}
@@ -1390,40 +1414,40 @@ function gen_strategy_plays(hand) {
for (let c of hand) {
let card = CARDS[c]
switch (card.type) {
- case 'mandatory-event':
- gen_action('card_play_event', c)
- break
- case 'campaign':
- gen_action('card_campaign', c)
- break
- case 'ops':
- if (can_exchange_for_discard(c))
- gen_action('exchange_for_discard', c)
- if (can_activate_general(c))
- gen_action('card_ops_general', c)
- gen_action('card_ops_pc', c)
- if (can_play_reinforcements())
- gen_action('card_ops_reinforcements', c)
- if (card.count < 3)
- gen_action('card_ops_queue', c)
- break
- case 'british-event':
- case 'british-event-or-battle':
- 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 (can_play_event(c))
- gen_action('card_play_event', c)
- gen_action('card_discard_event', c)
- break
- case 'british-battle':
- case 'american-battle':
- gen_action('card_discard_event', c)
- break
+ case "mandatory-event":
+ gen_action("card_play_event", c)
+ break
+ case "campaign":
+ gen_action("card_campaign", c)
+ break
+ case "ops":
+ if (can_exchange_for_discard(c))
+ gen_action("exchange_for_discard", c)
+ if (can_activate_general(c))
+ gen_action("card_ops_general", c)
+ gen_action("card_ops_pc", c)
+ if (can_play_reinforcements())
+ gen_action("card_ops_reinforcements", c)
+ if (card.count < 3)
+ gen_action("card_ops_queue", c)
+ break
+ case "british-event":
+ case "british-event-or-battle":
+ 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 (can_play_event(c))
+ gen_action("card_play_event", c)
+ gen_action("card_discard_event", c)
+ break
+ case "british-battle":
+ case "american-battle":
+ gen_action("card_discard_event", c)
+ break
}
}
}
@@ -1464,11 +1488,11 @@ function gen_british_discard_event_pc_action() {
for (let space in SPACES) {
if (is_adjacent_to_british_pc(space)) {
if (has_no_pc(space) && has_no_american_unit(space))
- gen_action('place_british_pc', space)
+ gen_action("place_british_pc", space)
else if (has_american_pc(space) && has_british_army(space))
- gen_action('flip_pc', space)
+ gen_action("flip_pc", space)
else if (has_american_pc(space) && has_no_american_unit(space))
- gen_action('remove_pc', space)
+ gen_action("remove_pc", space)
}
}
}
@@ -1478,13 +1502,11 @@ function gen_american_discard_event_pc_action() {
if (is_adjacent_to_american_pc(space)) {
if (has_no_pc(space) && has_no_british_cu(space)) {
if (allowed_to_place_american_pc())
- gen_action('place_american_pc', space)
- }
- else if (has_british_pc(space) && has_american_or_french_general(space)) {
- gen_action('flip_pc', space)
- }
- else if (has_british_pc(space) && has_no_british_cu(space)) {
- gen_action('remove_pc', space)
+ gen_action("place_american_pc", space)
+ } else if (has_british_pc(space) && has_american_or_french_general(space)) {
+ gen_action("flip_pc", space)
+ } else if (has_british_pc(space) && has_no_british_cu(space)) {
+ gen_action("remove_pc", space)
}
}
}
@@ -1494,7 +1516,7 @@ function gen_american_discard_event_pc_action() {
function goto_ops_pc(count) {
game.count = count
- game.state = 'ops_pc'
+ game.state = "ops_pc"
if (game.active === BRITISH)
gen_british_pc_ops_start()
}
@@ -1544,13 +1566,13 @@ function gen_british_pc_ops_start() {
function gen_british_pc_ops() {
for (let space of game.british_pc_space_list)
- gen_action('place_british_pc', space)
+ gen_action("place_british_pc", space)
for (let space in SPACES) {
if (has_british_army(space)) {
if (has_no_pc(space))
- gen_action('place_british_pc', space)
+ gen_action("place_british_pc", space)
else if (has_american_pc(space))
- gen_action('flip_pc', space)
+ gen_action("flip_pc", space)
}
}
}
@@ -1563,10 +1585,9 @@ function gen_american_pc_ops() {
for (let space in SPACES) {
if (has_no_pc(space) && has_no_british_cu(space)) {
if (allowed_to_place_american_pc())
- gen_action('place_american_pc', space)
- }
- else if (has_british_pc(space) && has_american_or_french_general(space)) {
- gen_action('flip_pc', space)
+ gen_action("place_american_pc", space)
+ } else if (has_british_pc(space) && has_american_or_french_general(space)) {
+ gen_action("flip_pc", space)
}
}
}
@@ -1579,11 +1600,11 @@ function goto_ops_reinforcements(c) {
if (game.active === BRITISH) {
game.played_british_reinforcements = count
game.count = count_british_cu(BRITISH_REINFORCEMENTS)
- game.state = 'ops_british_reinforcements_who'
+ game.state = "ops_british_reinforcements_who"
} else {
game.played_american_reinforcements.push(count)
game.count = count
- game.state = 'ops_american_reinforcements_who'
+ game.state = "ops_american_reinforcements_who"
}
}
@@ -1602,12 +1623,12 @@ states.ops_british_reinforcements_who = {
},
select_general: function (g) {
push_undo()
- game.state = 'ops_british_reinforcements_where'
+ game.state = "ops_british_reinforcements_where"
game.who = g
},
pass: function () {
push_undo()
- game.state = 'ops_british_reinforcements_where'
+ game.state = "ops_british_reinforcements_where"
game.who = null
},
}
@@ -1639,12 +1660,12 @@ states.ops_american_reinforcements_who = {
},
select_general: function (g) {
push_undo()
- game.state = 'ops_american_reinforcements_where'
+ game.state = "ops_american_reinforcements_where"
game.who = g
},
pass: function () {
push_undo()
- game.state = 'ops_american_reinforcements_where'
+ game.state = "ops_american_reinforcements_where"
game.who = null
},
}
@@ -1668,32 +1689,32 @@ function gen_british_reinforcements_who() {
for (let g of BRITISH_GENERALS) {
let general = game.generals[g]
if (general.location === BRITISH_REINFORCEMENTS) {
- gen_action('select_general', g)
+ gen_action("select_general", g)
}
}
if (game.count > 0)
- gen_action('drop_british_cu')
+ gen_action("drop_british_cu")
if (game.count < count_british_cu(BRITISH_REINFORCEMENTS))
- gen_action('pickup_british_cu')
+ gen_action("pickup_british_cu")
}
function gen_british_reinforcements_where() {
for (let space in SPACES) {
if (is_non_blockaded_port(space))
if (!has_american_or_french_cu(space) && !has_american_pc(space))
- gen_action('place_reinforcements', space)
+ gen_action("place_reinforcements", space)
}
if (game.count > 0)
- gen_action('drop_british_cu')
+ gen_action("drop_british_cu")
if (game.count < count_british_cu(BRITISH_REINFORCEMENTS))
- gen_action('pickup_british_cu')
+ gen_action("pickup_british_cu")
}
function gen_american_reinforcements_who() {
for (let g of AMERICAN_GENERALS) {
let general = game.generals[g]
if (general.location === AMERICAN_REINFORCEMENTS) {
- gen_action('select_general', g)
+ gen_action("select_general", g)
}
}
}
@@ -1703,9 +1724,9 @@ function gen_american_reinforcements_where(general) {
if (!has_british_cu(space) && !has_british_pc(space)) {
if (general === ROCHAMBEAU) {
if (SPACES[space].port)
- gen_action('place_reinforcements', space)
+ gen_action("place_reinforcements", space)
} else {
- gen_action('place_reinforcements', space)
+ gen_action("place_reinforcements", space)
}
}
}
@@ -1722,7 +1743,7 @@ function goto_ops_general(c) {
game.count = CARDS[c].count + game.a_queue
game.a_queue = 0
}
- game.state = 'ops_general_who'
+ game.state = "ops_general_who"
}
states.ops_general_who = {
@@ -1756,16 +1777,16 @@ states.ops_general_who = {
if (game.campaign > 0)
game.campaign = 0
end_strategy_card()
- }
+ },
}
function gen_landing_party() {
for (let space in SPACES) {
if (!is_fortified_port(space) && is_non_blockaded_port(space)) {
if (has_american_pc(space) && has_no_american_unit(space))
- gen_action('flip_pc', space)
+ gen_action("flip_pc", space)
if (has_no_pc(space) && has_no_american_unit(space) && has_no_british_playing_piece(space))
- gen_action('place_british_pc', space)
+ gen_action("place_british_pc", space)
}
}
}
@@ -1780,17 +1801,17 @@ function gen_activate_general() {
function gen_activate_british_general() {
for (let g of BRITISH_GENERALS)
if (is_general_on_map(g) && GENERALS[g].strategy <= game.count && !game.moved[g])
- gen_action('select_general', g)
+ gen_action("select_general", g)
}
function gen_activate_american_general() {
for (let g of AMERICAN_GENERALS)
if (is_general_on_map(g) && GENERALS[g].strategy <= game.count && !game.moved[g])
- gen_action('select_general', g)
+ gen_action("select_general", g)
}
function goto_remove_general(where) {
- game.state = 'remove_general'
+ game.state = "remove_general"
game.where = where
}
@@ -1809,7 +1830,7 @@ states.remove_general = {
}
function goto_remove_general_after_intercept() {
- game.state = 'remove_general_after_intercept'
+ game.state = "remove_general_after_intercept"
}
states.remove_general_after_intercept = {
@@ -1827,7 +1848,7 @@ states.remove_general_after_intercept = {
}
function goto_remove_general_after_retreat(where) {
- game.state = 'remove_general_after_retreat'
+ game.state = "remove_general_after_retreat"
game.where = where
}
@@ -1855,18 +1876,18 @@ function gen_remove_general() {
function gen_remove_british_general() {
for (let g of BRITISH_GENERALS)
if (location_of_general(g) === game.where)
- gen_action('select_general', g)
+ 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)
- gen_action('select_general', g)
+ gen_action("select_general", g)
}
function goto_ops_general_move(g, marblehead) {
- game.state = 'ops_general_move'
+ game.state = "ops_general_move"
game.who = g
if (marblehead) {
game.mobility = false
@@ -1919,9 +1940,15 @@ states.ops_general_move = {
gen_move_general()
},
- pickup_british_cu: function () { ++game.carry_british; },
- pickup_american_cu: function () { ++game.carry_american; },
- pickup_french_cu: function () { ++game.carry_french; },
+ pickup_british_cu: function () {
+ ++game.carry_british
+ },
+ pickup_american_cu: function () {
+ ++game.carry_american
+ },
+ pickup_french_cu: function () {
+ ++game.carry_french
+ },
drop_british_cu: function () {
push_undo()
@@ -1951,7 +1978,7 @@ states.ops_general_move = {
let intercept = false
if (game.active === BRITISH) {
- let is_sea_move = (path_type(from, to) === undefined)
+ 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)
}
@@ -2009,7 +2036,7 @@ function gen_intercept() {
if (has_american_army(space)) {
let g = find_american_or_french_general(space)
if (g && !game.moved[g])
- gen_action('select_general', g)
+ gen_action("select_general", g)
}
}
}
@@ -2021,7 +2048,7 @@ function goto_intercept(from, where) {
game.from = from
game.where = where
game.active = AMERICAN
- game.state = 'intercept'
+ game.state = "intercept"
}
states.intercept = {
@@ -2065,7 +2092,7 @@ states.intercept = {
function end_intercept() {
game.active = BRITISH
- game.state = 'ops_general_move'
+ game.state = "ops_general_move"
game.who = game.save_who
delete game.save_who
resume_moving(game.from, game.where)
@@ -2098,36 +2125,39 @@ function gen_carry_cu() {
let where = location_of_general(game.who)
if (game.active === BRITISH) {
if (game.carry_british > 0)
- gen_action('drop_british_cu')
+ gen_action("drop_british_cu")
if (game.carry_british < 5 && game.carry_british < count_unmoved_british_cu(where))
- gen_action('pickup_british_cu')
+ gen_action("pickup_british_cu")
} else {
let carry_total = game.carry_french + game.carry_american
if (game.carry_french > 0)
- gen_action('drop_french_cu')
+ gen_action("drop_french_cu")
if (game.carry_american > 0)
- gen_action('drop_american_cu')
+ gen_action("drop_american_cu")
if (carry_total < 5 && game.carry_french < count_unmoved_french_cu(where))
- gen_action('pickup_french_cu')
+ gen_action("pickup_french_cu")
if (carry_total < 5 && game.carry_american < count_unmoved_american_cu(where))
- gen_action('pickup_american_cu')
+ gen_action("pickup_american_cu")
}
}
function movement_cost(from, to) {
switch (path_type(from, to)) {
- case undefined: return 4; /* must be a sea connection if no direct path */
- case 'wilderness': return 3
- default: return 1
+ case undefined:
+ return 4 /* must be a sea connection if no direct path */
+ case "wilderness":
+ return 3
+ default:
+ return 1
}
}
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_type(from, to) === "wilderness") {
if (path_name(from, to) === FALMOUTH_QUEBEC)
if (game.who !== ARNOLD)
continue
@@ -2146,10 +2176,10 @@ function gen_move_general() {
if (game.mobility && has_enemy_cu(to)) {
if (game.count - mp >= 1)
- gen_action('move', to)
+ gen_action("move", to)
} else {
if (game.count - mp >= 0)
- gen_action('move', to)
+ gen_action("move", to)
}
}
if (game.active === BRITISH && game.count === 4) {
@@ -2162,7 +2192,7 @@ function gen_move_general() {
if (alone && has_enemy_general(to))
continue
// TODO: duplicate action if can move by normal road
- gen_action('move', to)
+ gen_action("move", to)
}
}
}
@@ -2175,11 +2205,11 @@ function gen_move_general() {
function goto_campaign(c) {
play_card(c)
- game.state = 'campaign'
+ game.state = "campaign"
game.campaign = CARDS[c].count
game.landing_party = game.active === BRITISH ? 1 : 0
- game.count = 3; // can activate any general!
- game.state = 'ops_general_who'
+ game.count = 3 // can activate any general!
+ game.state = "ops_general_who"
}
/* EVENTS */
@@ -2212,7 +2242,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()
@@ -2255,7 +2285,7 @@ events.advance_french_alliance = function (c, card) {
events.remove_french_navy = function (c, card) {
play_card(c)
- game.french_navy = TURN_TRACK[game.year+1]
+ game.french_navy = TURN_TRACK[game.year + 1]
end_strategy_card()
}
@@ -2263,7 +2293,7 @@ events.remove_british_pc_from = function (c, card) {
play_card(c)
game.count = card.count
game.where = card.where
- game.state = 'remove_british_pc_from'
+ game.state = "remove_british_pc_from"
}
states.remove_british_pc_from = {
@@ -2288,7 +2318,7 @@ states.remove_british_pc_from = {
events.remove_american_pc = function (c, card) {
play_card(c)
game.count = card.count
- game.state = 'remove_american_pc'
+ game.state = "remove_american_pc"
}
states.remove_american_pc = {
@@ -2312,7 +2342,7 @@ events.remove_american_pc_from = function (c, card) {
play_card(c)
game.count = card.count
game.where = card.where
- game.state = 'remove_american_pc_from'
+ game.state = "remove_american_pc_from"
}
states.remove_american_pc_from = {
@@ -2338,12 +2368,13 @@ events.remove_american_pc_from_non_port = function (c, card) {
play_card(c)
game.count = card.count
game.where = card.where
- game.state = 'remove_american_pc_from_non_port'
+ game.state = "remove_american_pc_from_non_port"
}
states.remove_american_pc_from_non_port = {
prompt: function (current) {
- view.prompt = "Remove American PC markers from non-Port space in " + game.where.join(", ") + ". " + game.count + " left."
+ view.prompt =
+ "Remove American PC markers from non-Port space in " + game.where.join(", ") + ". " + game.count + " left."
gen_pass()
gen_remove_american_pc_from_non_port(game.where)
},
@@ -2363,7 +2394,7 @@ states.remove_american_pc_from_non_port = {
events.remove_american_pc_within_two_spaces_of_a_british_general = function (c, card) {
play_card(c)
game.count = card.count
- game.state = 'remove_american_pc_within_two_spaces_of_a_british_general'
+ game.state = "remove_american_pc_within_two_spaces_of_a_british_general"
}
states.remove_american_pc_within_two_spaces_of_a_british_general = {
@@ -2388,7 +2419,7 @@ states.remove_american_pc_within_two_spaces_of_a_british_general = {
events.place_american_pc = function (c, card) {
play_card(c)
game.count = card.count
- game.state = 'place_american_pc'
+ game.state = "place_american_pc"
}
states.place_american_pc = {
@@ -2412,7 +2443,7 @@ events.place_american_pc_in = function (c, card) {
play_card(c)
game.count = card.count
game.where = card.where
- game.state = 'place_american_pc_in'
+ game.state = "place_american_pc_in"
}
states.place_american_pc_in = {
@@ -2436,7 +2467,7 @@ states.place_american_pc_in = {
events.lord_sandwich_coastal_raids = function (c, card) {
play_card(c)
- game.state = 'lord_sandwich_coastal_raids'
+ game.state = "lord_sandwich_coastal_raids"
game.count = 2
game.where = null
}
@@ -2466,15 +2497,15 @@ function gen_lord_sandwich_coastal_raids(first_removed) {
for (let space in SPACES) {
if (SPACES[space].port)
if (has_american_pc(space) && has_no_american_unit(space))
- gen_action('remove_pc', space)
+ gen_action("remove_pc", space)
if (space === first_removed)
- gen_action('place_british_pc', space)
+ gen_action("place_british_pc", space)
}
}
events.remove_american_cu = function (c, card) {
play_card(c)
- game.state = 'remove_american_cu'
+ game.state = "remove_american_cu"
}
states.remove_american_cu = {
@@ -2496,13 +2527,13 @@ states.remove_american_cu = {
function gen_remove_american_cu() {
for (let space in SPACES) {
if (has_american_or_french_cu(space))
- gen_action('remove_cu', space)
+ gen_action("remove_cu", space)
}
}
events.remove_british_cu = function (c, card) {
play_card(c)
- game.state = 'remove_british_cu'
+ game.state = "remove_british_cu"
game.count = card.count
}
@@ -2526,14 +2557,14 @@ states.remove_british_cu = {
function gen_remove_british_cu() {
for (let space in SPACES) {
if (has_british_cu(space))
- gen_action('remove_cu', space)
+ gen_action("remove_cu", space)
}
}
events.pennsylvania_and_new_jersey_line_mutinies = function (c, card) {
play_card(c)
game.pennsylvania_and_new_jersey_line_mutinies = true
- game.state = 'pennsylvania_and_new_jersey_line_mutinies'
+ game.state = "pennsylvania_and_new_jersey_line_mutinies"
game.count = 2
game.where = null
}
@@ -2560,14 +2591,14 @@ 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)
- gen_action('remove_cu', space)
+ gen_action("remove_cu", space)
}
}
events.john_glovers_marblehead_regiment = function (c, card) {
play_card(c)
- game.state = 'john_glovers_marblehead_regiment_who'
- game.count = 3; // strategy rating for gen_activate_general
+ game.state = "john_glovers_marblehead_regiment_who"
+ game.count = 3 // strategy rating for gen_activate_general
}
states.john_glovers_marblehead_regiment_who = {
@@ -2585,7 +2616,7 @@ events.declaration_of_independence = function (c, card) {
game.last_active = game.active
game.active = AMERICAN
game.doi = THE_13_COLONIES.slice()
- game.state = 'declaration_of_independence'
+ game.state = "declaration_of_independence"
}
states.declaration_of_independence = {
@@ -2604,7 +2635,7 @@ states.declaration_of_independence = {
},
pass: function () {
end_declaration_of_independence()
- }
+ },
}
function end_declaration_of_independence() {
@@ -2620,7 +2651,7 @@ function goto_george_washington_captured() {
game.last_active = game.active
game.last_count = game.count
- game.state = 'george_washington_captured'
+ game.state = "george_washington_captured"
game.active = BRITISH
game.count = 5
}
@@ -2689,7 +2720,7 @@ function goto_start_battle(from, where) {
function goto_retreat_before_battle() {
game.active = AMERICAN
game.who = find_american_or_french_general(game.where)
- game.state = 'retreat_before_battle'
+ game.state = "retreat_before_battle"
}
states.retreat_before_battle = {
@@ -2720,7 +2751,7 @@ states.retreat_before_battle = {
function goto_remove_general_after_retreat_before_battle(to) {
if (count_friendly_generals(to) > 1) {
- game.state = 'remove_general_after_retreat_before_battle'
+ game.state = "remove_general_after_retreat_before_battle"
game.save_where = game.where
game.where = to
} else {
@@ -2744,7 +2775,6 @@ 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)
@@ -2781,7 +2811,7 @@ function gen_defender_retreat() {
let from = game.where
for (let to of SPACES[from].exits) {
if (can_defender_retreat(to))
- gen_action('move', to)
+ gen_action("move", to)
}
if (game.active === BRITISH) {
let can_sea_retreat = false
@@ -2797,7 +2827,7 @@ function gen_defender_retreat() {
for (let to in SPACES) {
if (to !== from && is_non_blockaded_port(to)) {
if (!has_american_pc(to) && !has_american_or_french_cu(to)) {
- gen_action('move', to)
+ gen_action("move", to)
}
}
}
@@ -2807,7 +2837,7 @@ function gen_defender_retreat() {
function gen_attacker_retreat() {
if (can_attacker_retreat())
- gen_action('move', game.attack_from)
+ gen_action("move", game.attack_from)
}
function end_retreat_before_battle() {
@@ -2817,7 +2847,7 @@ function end_retreat_before_battle() {
function goto_play_attacker_battle_card() {
game.active = game.attacker
- game.state = 'play_attacker_battle_card'
+ game.state = "play_attacker_battle_card"
}
states.play_attacker_battle_card = {
@@ -2829,7 +2859,7 @@ 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 (CARDS[c].event === "remove_benedict_arnold")
remove_benedict_arnold()
game.b_draw_after_battle = true
game.b_bonus += 2
@@ -2856,7 +2886,7 @@ states.play_attacker_battle_card = {
}
function goto_play_defender_battle_card() {
- game.state = 'play_defender_battle_card'
+ game.state = "play_defender_battle_card"
game.active = ENEMY[game.attacker]
}
@@ -2869,7 +2899,7 @@ 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 (CARDS[c].event === "remove_benedict_arnold")
remove_benedict_arnold()
game.b_draw_after_battle = true
game.b_bonus += 2
@@ -2900,27 +2930,27 @@ function gen_battle_card() {
let card = CARDS[c]
if (game.active === BRITISH) {
switch (card.type) {
- case 'british-battle':
- case 'british-event-or-battle':
- gen_action('card_battle_play', c)
- break
- case 'british-event':
- case 'american-event':
- case 'american-battle':
- gen_action('card_battle_discard', c)
- break
+ case "british-battle":
+ case "british-event-or-battle":
+ gen_action("card_battle_play", c)
+ break
+ case "british-event":
+ case "american-event":
+ case "american-battle":
+ gen_action("card_battle_discard", c)
+ break
}
} else {
switch (card.type) {
- case 'british-battle':
- case 'british-event-or-battle':
- case 'british-event':
- case 'american-event':
- gen_action('card_battle_discard', c)
- break
- case 'american-battle':
- gen_action('card_battle_play', c)
- break
+ case "british-battle":
+ case "british-event-or-battle":
+ case "british-event":
+ case "american-event":
+ gen_action("card_battle_discard", c)
+ break
+ case "american-battle":
+ gen_action("card_battle_play", c)
+ break
}
}
}
@@ -2931,9 +2961,18 @@ function roll_loser_combat_losses(log) {
let losses = 0
log.push("Loser Combat Loss Roll: " + roll)
switch (roll) {
- case 1: case 2: case 3: losses = 1; break
- case 4: case 5: losses = 2; break
- case 6: losses = 3; break
+ case 1:
+ case 2:
+ case 3:
+ losses = 1
+ break
+ case 4:
+ case 5:
+ losses = 2
+ break
+ case 6:
+ losses = 3
+ break
}
return losses
}
@@ -2941,14 +2980,22 @@ function roll_loser_combat_losses(log) {
function roll_winner_combat_losses(log, losing_general) {
let agility = losing_general ? GENERALS[losing_general].agility : 0
let roll = roll_d6()
- log.push("Enemy Agility Rating: " + agility)
+ log.push("Enemy Agility Rating: " + agility)
log.push("Winner Combat Loss Roll: " + roll)
let losses = 0
switch (agility) {
- 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
+ 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
}
return losses
}
@@ -3089,9 +3136,9 @@ function resolve_battle() {
let victor
if (game.active === BRITISH)
- victor = (b_roll + b_drm) >= (a_roll + a_drm) ? BRITISH : AMERICAN
+ victor = b_roll + b_drm >= a_roll + a_drm ? BRITISH : AMERICAN
else
- victor = (b_roll + b_drm) >= (a_roll + a_drm) ? BRITISH : AMERICAN
+ victor = b_roll + b_drm >= a_roll + a_drm ? BRITISH : AMERICAN
let a_lost_cu, b_lost_cu
if (victor === BRITISH) {
@@ -3138,13 +3185,13 @@ function goto_retreat_after_battle(victor) {
return end_battle()
}
game.active = ENEMY[victor]
- game.state = 'retreat_after_battle'
+ game.state = "retreat_after_battle"
}
states.retreat_after_battle = {
prompt: function (current) {
view.prompt = "Retreat after battle."
- gen_action('surrender')
+ gen_action("surrender")
if (game.active === game.attacker)
gen_attacker_retreat()
else
@@ -3279,20 +3326,20 @@ function goto_winter_attrition_phase() {
function goto_french_naval_phase() {
if (game.french_navy !== FRENCH_REINFORCEMENTS) {
game.active = AMERICAN
- game.state = 'place_french_navy'
+ game.state = "place_french_navy"
} else {
goto_political_control_phase()
}
}
function gen_place_french_navy() {
- gen_action('place_navy', "Sea1")
- gen_action('place_navy', "Sea2")
- gen_action('place_navy', "Sea3")
- gen_action('place_navy', "Sea4")
- gen_action('place_navy', "Sea5")
- gen_action('place_navy', "Sea6")
- gen_action('place_navy', "Sea7")
+ gen_action("place_navy", "Sea1")
+ gen_action("place_navy", "Sea2")
+ gen_action("place_navy", "Sea3")
+ gen_action("place_navy", "Sea4")
+ gen_action("place_navy", "Sea5")
+ gen_action("place_navy", "Sea6")
+ gen_action("place_navy", "Sea7")
}
states.place_french_navy_trigger = {
@@ -3429,9 +3476,9 @@ 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)
+ gen_action("place_continental_congress", space)
++n
}
}
@@ -3442,7 +3489,7 @@ function gen_place_continental_congress() {
function goto_political_control_phase() {
if (game.congress === CONTINENTAL_CONGRESS_DISPERSED) {
game.active = AMERICAN
- game.state = 'return_continental_congress'
+ game.state = "return_continental_congress"
} else {
goto_political_control_phase_2()
}
@@ -3460,7 +3507,7 @@ states.return_continental_congress = {
},
pass: function () {
goto_political_control_phase_2()
- }
+ },
}
function goto_political_control_phase_2() {
@@ -3484,7 +3531,7 @@ states.european_war = {
},
pass: function () {
goto_end_phase()
- }
+ },
}
function norths_government_falls() {
@@ -3502,7 +3549,7 @@ function norths_government_falls() {
game.victory = "North's Government Falls: " + game.result + " Victory!"
game.active = "None"
- game.state = 'game_over'
+ game.state = "game_over"
log(game.victory)
}
@@ -3512,7 +3559,7 @@ function goto_end_phase() {
game.european_war = true
game.count = 2
game.active = AMERICAN
- game.state = 'european_war'
+ game.state = "european_war"
game.reshuffle = true
return
}
@@ -3529,7 +3576,7 @@ function goto_end_phase() {
states.game_over = {
prompt: function () {
view.prompt = game.victory
- }
+ },
}
/* CLIENT/SERVER COMMS */
@@ -3547,7 +3594,7 @@ exports.action = function (state, current, action, arg) {
if (action in S) {
S[action](arg)
} else {
- if (action === 'undo' && game.undo && game.undo.length > 0)
+ if (action === "undo" && game.undo && game.undo.length > 0)
pop_undo()
else
throw new Error("Invalid action: " + action)
@@ -3564,7 +3611,7 @@ function list_actions(current) {
states[game.state].prompt(current)
}
-exports.view = function(state, current) {
+exports.view = function (state, current) {
game = state
view = {
@@ -3606,7 +3653,7 @@ exports.view = function(state, current) {
gen_action_undo()
} else {
let inactive = states[game.state].inactive
- if (typeof inactive !== 'string')
+ if (typeof inactive !== "string")
inactive = game.state
view.prompt = "Waiting for " + game.active + " player \u2014 " + inactive + "."
}