From fb54e6b4b0df7b90ffd68124400fefda0af89d09 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 3 Jan 2024 18:06:07 +0100 Subject: Fix supply search optimization. --- rules.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rules.js b/rules.js index d6efbf3..88a977f 100644 --- a/rules.js +++ b/rules.js @@ -1361,9 +1361,18 @@ function trace_unit_supply_line(path, here, here_move, ssrc) { if (next_move === TRACE_ABORT) continue - // reached supply source, or reached supplied highway (that we searched before) - /* if (next === ssrc) -- fallback without short cut in case the optimization below is wrong... */ - if (next === ssrc || (hex_road[next] === HIGHWAY && supply_net[next] === 2)) { + let reached = (next === ssrc) + if (!reached) { + // Stop searching if we reach a supplied highway, + // but only if we can't continue by trail or track. + // Example: Tobruk - EL Adem - Sidi Rezegh - Ft. Capuzzo + if (hex_road[next] === HIGHWAY && supply_net[next] === 2) + if (next_move === BACK_HIGHWAY_3 || next_move === BACK_STOP) + reached = true + } + + // reached supply source + if (reached) { for (let x of path) supply_line[x] = 2 supply_line[side] = 2 -- cgit v1.2.3