From 11d051ae815f1716614e07cc23fc6d333494bbae Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 7 Aug 2022 02:36:43 +0200 Subject: Refix supply chain from highway bug. Revert "Fix bug in supply network calculations." This reverts commit a288c0dbed909597fe5c8f47cad86096f166d82e. --- rules.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 18 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index bfbcdeb..f8e1628 100644 --- a/rules.js +++ b/rules.js @@ -1129,7 +1129,7 @@ function ind(d, msg, here, ...extra) { var supply_defender, supply_defender_sides, supply_friendly, supply_enemy, supply_net, supply_line, supply_fortress_enemy var supply_visited = new Array(hexcount).fill(0) -var supply_src = 0 +var supply_src = new Array(hexcount).fill(0) var trace_total @@ -1162,12 +1162,6 @@ function trace_supply_highway(here, d) { trace_total++ ind(d, "> highway", here) - // TODO: hoist to call sites to avoid function call overhead - if (supply_src === here) { - ind(d, "! source highway", here) - return true - } - let has_supply = false supply_visited[here] = 1 @@ -1189,12 +1183,24 @@ function trace_supply_highway(here, d) { if (road === HIGHWAY) { if (supply_friendly[next] > 1) { ind(d, "? highway head", next) + if (supply_src[next]) { + ind(d, "!! source highway chain", next) + supply_line[side] = 1 + has_supply = true + } + else if (trace_supply_chain(next, d+1, 0, 3)) { ind(d, "< highway chain", here, next) supply_line[side] = 1 has_supply = true } } else { + if (supply_src[next]) { + ind(d, "!! source highway", next) + supply_line[side] = 1 + has_supply = true + } + else if (trace_supply_highway(next, d+1)) { ind(d, "< highway", here, next) supply_line[side] = 1 @@ -1206,8 +1212,11 @@ function trace_supply_highway(here, d) { supply_visited[here] = 0 - if (has_supply) + if (has_supply) { supply_net[here] = 1 + if (supply_enemy[here] <= 1) + supply_src[here] = 1 + } return has_supply } @@ -1216,11 +1225,6 @@ function trace_supply_chain(here, d, n, range) { trace_total++ ind(d, "> chain", here, n, range) - if (supply_src === here) { - ind(d, "! source chain", here) - return true - } - let has_supply = false supply_visited[here] = 1 @@ -1243,12 +1247,24 @@ function trace_supply_chain(here, d, n, range) { ind(d, "? chain highway", next) if (supply_friendly[next] > 1) { ind(d, "? chain highway head", next) + if (supply_src[next]) { + ind(d, "!! source highway chain head", next) + supply_line[side] = 1 + has_supply = true + } + else if (trace_supply_chain(next, d+1, 0, 3)) { ind(d, "< highway chain", here, next) supply_line[side] = 1 has_supply = true } } else { + if (supply_src[next]) { + ind(d, "!! source chain highway", next) + supply_line[side] = 1 + has_supply = true + } + else if (trace_supply_highway(next, d+1)) { ind(d, "< chain highway", here, next) supply_line[side] = 1 @@ -1260,12 +1276,24 @@ function trace_supply_chain(here, d, n, range) { if (n + 1 <= next_range) { if (supply_friendly[next] > 1) { ind(d, "? chain head", next) + if (supply_src[next]) { + ind(d, "!! source highway chain", next) + supply_line[side] = 1 + has_supply = true + } + else if (trace_supply_chain(next, d+1, 0, 3)) { ind(d, "< highway chain", here, next) supply_line[side] = 1 has_supply = true } } else { + if (supply_src[next]) { + ind(d, "!! source highway chain", next_range) + supply_line[side] = 1 + has_supply = true + } + else if (trace_supply_chain(next, d+1, n+1, next_range)) { ind(d, "< chain trail", here, next_range) supply_line[side] = 1 @@ -1278,23 +1306,28 @@ function trace_supply_chain(here, d, n, range) { supply_visited[here] = 0 - if (has_supply) + if (has_supply) { supply_net[here] = 1 + // undisrupted units can chain supply + if (supply_friendly[here] > 1 && supply_enemy[here] <= 1) + supply_src[here] = 1 + } return has_supply } function trace_supply_network(start, ss) { supply_visited.fill(0) + supply_src.fill(0) supply_net.fill(0) supply_line.fill(0) - supply_src = start + supply_src[start] = 1 supply_net[start] = 1 trace_total = 0 for (let x of all_hexes) - if (supply_friendly[x] > 0) + if (supply_friendly[x] > 0 && x !== start) trace_supply_chain(x, 0, 0, 3) console.log("SUPPLY VISITS", trace_total) @@ -1302,11 +1335,13 @@ function trace_supply_network(start, ss) { function trace_fortress_network(fortress, ss) { supply_visited.fill(0) + supply_src.fill(0) supply_net.fill(0) supply_line.fill(0) - supply_src = fortress + supply_src[fortress] = 1 supply_net[fortress] = 1 + supply_visited[fortress] = 1 trace_total = 0 for (let u = 0; u < unit_count; ++u) { @@ -1347,8 +1382,11 @@ function init_trace_supply_to_base_or_fortress() { } function can_trace_supply_to_base_or_fortress(base, from) { + if (from === base) + return true supply_visited.fill(0) - supply_src = base + supply_src.fill(0) + supply_src[base] = 1 return trace_supply_chain(from, 0, 0, 3) } -- cgit v1.2.3