diff options
-rw-r--r-- | rules.js | 50 |
1 files changed, 29 insertions, 21 deletions
@@ -2035,32 +2035,45 @@ function update_vp(name, s) { // SUPPLY LINES +function is_cultivated_or_fortification_or_amphib(space) { + return is_cultivated(space) || has_friendly_fortifications(space) || has_friendly_amphib(space) +} + function search_supply_spaces_imp(queue) { + let visited = new Array(spaces.length).fill(0) // console.log("======") let reached = [] - for (let s of queue) + for (let s of queue) { set_add(reached, s) + visited[s] = 1 + } while (queue.length > 0) { - let current = queue.shift() - // If we must have come here by water way: - let cultivated = is_cultivated(current) || has_friendly_fortifications(current) || has_friendly_amphib(current) - // console.log("SUPPLY", space_name(current), cultivated) - for_each_exit_with_type(current, (next, type) => { - if (set_has(reached, next)) - return // continue + let here = queue.shift() + // console.log("SUPPLY", space_name(here)) + for_each_exit_with_type(here, (next, type) => { + if (visited[next]) + return if (has_unbesieged_enemy_units(next) || has_unbesieged_enemy_fortifications(next)) return // continue - if (!cultivated) { - // came from wilderness by water, must continue by water - if (type !== 'land') { - // console.log(" ", space_name(next), "(adjacent-water)") + if (is_cultivated_or_fortification_or_amphib(here)) { + // came from cultivated/fortification, + // may continue by water or another fortification + // may stop at anything + if (type !== 'land' || is_cultivated_or_fortification_or_amphib(next)) { + // console.log(" ", space_name(next), "(from cultivated, continue)") set_add(reached, next) + visited[next] = 1 queue.push(next) + } else { + // console.log(" ", space_name(next), "(from cultivated, stop)") + // allow re-visits in case we come by water a longer way + set_add(reached, next) } } else { - // came from cultivated by any path, may continue to cultivated or by water - if (is_cultivated(next) || has_friendly_fortifications(next) || has_friendly_amphib(next) || type !== 'land') { - // console.log(" ", space_name(next), "(from land)") + // in wilderness, arrived by water, must continue by water + if (type !== 'land') { + // console.log(" ", space_name(next), "(from river)") + visited[next] = 1 set_add(reached, next) queue.push(next) } @@ -2091,12 +2104,7 @@ function is_in_supply(from) { search_supply_spaces() if (set_has(supply_cache, from)) return true - let x = false - for_each_exit(from, next => { - if (set_has(supply_cache, next)) - x = true - }) - return x + return false } function query_supply() { |