diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-01-25 13:29:38 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-01-25 13:30:14 +0100 |
commit | 8f88d543d79421f29c2f67d44006290a24e98d7c (patch) | |
tree | a0321187135df23b2d63d36612e16133c183d647 | |
parent | 4ff58fadf5b6158dfb5f89f2545f21131661bb3d (diff) | |
download | rommel-in-the-desert-8f88d543d79421f29c2f67d44006290a24e98d7c.tar.gz |
Optimize search: generate list of hexes to search for pass 2 in pass 1.
Start pass 2 at the fringes to repeat as little work as possible during
recursion.
-rw-r--r-- | rules.js | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -1215,6 +1215,8 @@ function forward_supply_next_move_type(here_move, road) { function trace_supply_network_1(start) { + let search_order = [] + supply_net[start] = 1 supply_visited.fill(8) @@ -1226,6 +1228,9 @@ function trace_supply_network_1(start) let here = item >> 3 let here_move = item & 7 + if (supply_friendly[here] > 0) + search_order.unshift(here) + for (let s = 0; s < 6; ++s) { let next = here + hexnext[s] @@ -1259,6 +1264,8 @@ function trace_supply_network_1(start) queue.push((next << 3) | next_move) } } + + return search_order } // PASS 2: Filter net to only include supply lines used by units. @@ -1452,20 +1459,15 @@ function all_hexes_sorted_by_distance_to_base(x) { }) } -const all_hexes_for_axis_supply = all_hexes_sorted_by_distance_to_base(EL_AGHEILA) -const all_hexes_for_allied_supply = all_hexes_sorted_by_distance_to_base(ALEXANDRIA) - function trace_supply_network(start) { check_timeout() - let search_order = (start === EL_AGHEILA ? all_hexes_for_axis_supply : all_hexes_for_allied_supply) - supply_net.fill(0) supply_line.fill(0) // Pass 1: Find hexes that are in supply range. - trace_supply_network_1(start) + let search_order = trace_supply_network_1(start) // Pass 2: Filter hexes that have actual supply lines from units. supply_visited.fill(0) |