diff options
-rw-r--r-- | rules.js | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -11,6 +11,10 @@ const max = Math.max const min = Math.min const abs = Math.abs +const TIMEOUT = 500 + +var timeout = 0 + var states = {} var game = null var view = null @@ -1165,10 +1169,17 @@ function is_supply_line_blocked(here, next, side) { return false } +function check_timeout() { + if (Date.now() > timeout) + throw new Error("timeout (supply lines are too complicated)") +} + function trace_supply_highway(here, v) { if (supply_src[here]) return true + check_timeout() + let has_supply = false let save_v = supply_visited[here] @@ -1216,6 +1227,8 @@ function trace_supply_chain(here, n, range, v) { if (supply_src[here]) return true + check_timeout() + let has_supply = false let save_v = supply_visited[here] @@ -7376,6 +7389,7 @@ exports.setup = function (seed, scenario, options) { } exports.view = function(state, current) { + timeout = Date.now() + TIMEOUT // don't think too long! load_state(state) let scenario = current_scenario() @@ -7439,6 +7453,7 @@ exports.view = function(state, current) { } exports.query = function (state, current, q) { + timeout = Date.now() + TIMEOUT // don't think too long! if (q === 'supply') { load_state(state) if (game.buildup) { @@ -7561,6 +7576,7 @@ exports.resign = function (state, current) { } exports.action = function (state, current, action, arg) { + timeout = Date.now() + TIMEOUT // don't think too long! load_state(state) // Object.seal(game) // XXX: don't allow adding properties let S = states[game.state] |