diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -1,5 +1,21 @@ "use strict" +function set_has(set, item) { + let a = 0 + let b = set.length - 1 + while (a <= b) { + let m = (a + b) >> 1 + let x = set[m] + if (item < x) + b = m - 1 + else if (item > x) + a = m + 1 + else + return true + } + return false +} + const CLEOPATRA = "Cleopatra" const DEAD = "Dead" const LEVY = "Levy" @@ -123,12 +139,16 @@ function block_description(b) { return block_owner(b) } -function block_owner(who) { - if (who in view.owner) - return view.owner[who] +function block_original_owner(who) { return BLOCKS[who].owner } +function block_owner(who) { + if (set_has(view.traitor, who)) + return enemy(block_original_owner(who)) + return block_original_owner(who) +} + function block_name(b) { return BLOCKS[b].name } @@ -471,7 +491,7 @@ function update_map() { let image = " block_" + info.label let known = " known" let jupiter = "" - if (block_owner(b) !== BLOCKS[b].owner && view.game_over) + if (set_has(view.traitor, b) && view.game_over) jupiter = " jupiter" element.classList = info.color + known + " block" + image + moved + jupiter update_steps(b, element, true) @@ -479,7 +499,7 @@ function update_map() { let jupiter = "" let mars = "" let neptune = "" - if (block_owner(b) !== BLOCKS[b].owner) + if (set_has(view.traitor, b)) jupiter = " jupiter" if (block_owner(b) === view.mars && space === view.surprise) mars = " mars" |