summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.js39
1 files changed, 30 insertions, 9 deletions
diff --git a/play.js b/play.js
index 3d577c0..312dd0b 100644
--- a/play.js
+++ b/play.js
@@ -42,6 +42,7 @@ function set_has(set, item) {
/* DATA */
+const PC_NONE = 0
const PC_BRITISH = 1
const PC_AMERICAN = 2
@@ -52,6 +53,9 @@ const CU_BRITISH_MASK = 63 << CU_BRITISH_SHIFT
const CU_AMERICAN_MASK = 63 << CU_AMERICAN_SHIFT
const CU_FRENCH_MASK = 7 << CU_FRENCH_SHIFT
+const QUEBEC = data.space_index["Quebec"]
+const MONTREAL = data.space_index["Montreal"]
+
const CARDS = data.cards
const P_BRITAIN = "Britain"
@@ -523,6 +527,29 @@ function get_static_bcu(s) {
return cu
}
+function get_colony_control(c) {
+ let control = 0
+ if (c === 0) {
+ if (get_space_pc(QUEBEC) === PC_BRITISH && get_space_pc(MONTREAL) === PC_BRITISH)
+ return PC_BRITISH
+ if (get_space_pc(QUEBEC) === PC_AMERICAN && get_space_pc(MONTREAL) === PC_AMERICAN)
+ return PC_AMERICAN
+ return PC_NONE
+ }
+ for (let space of data.colonies[c]) {
+ let pc = get_space_pc(space)
+ if (pc === PC_BRITISH)
+ --control
+ else if (pc === PC_AMERICAN)
+ ++control
+ }
+ if (control < 0)
+ return PC_BRITISH
+ if (control > 0)
+ return PC_AMERICAN
+ return PC_NONE
+}
+
function layout_all_cu(an, fn, bn, ae, fe, be, pos) {
let [ x, y ] = pos
show_piece_with_number_at(ae, an, x, y)
@@ -706,15 +733,9 @@ function on_update() {
}
for (let i = 0; i < 14; ++i) {
- let control = 0
- for (let s of data.colonies[i]) {
- if (has_british_pc(s))
- --control
- else if (has_american_pc(s))
- ++control
- }
- toggle_marker(ui.b_colony[i], control < 0)
- toggle_marker(ui.a_colony[i], control > 0)
+ let control = get_colony_control(i)
+ toggle_marker(ui.b_colony[i], control === PC_BRITISH)
+ toggle_marker(ui.a_colony[i], control === PC_AMERICAN)
}
ui.reshuffle.classList.toggle("hide", !(view.flags & F_RESHUFFLE))