From 803a82364b56a60b3e8cd2cb5f84eb27eb290255 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 27 Jul 2022 16:42:56 +0200 Subject: Cleans. --- rules.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/rules.js b/rules.js index 20a1ce0..d397644 100644 --- a/rules.js +++ b/rules.js @@ -708,17 +708,11 @@ function for_each_undisrupted_and_unmoved_friendly_unit_in_hex(x, fn) { fn(u) } -function has_undisrupted_and_moved_friendly_unit_in_hex(x) { +function hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(here) { for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) - if (!is_unit_disrupted(u) && unit_hex(u) === x && is_unit_moved(u)) + if (!is_unit_disrupted(u) && !is_unit_moved(u) && is_hex_or_adjacent_to(unit_hex(u), here)) return true -} - - -function for_each_undisrupted_friendly_unit_in_hex_or_adjacent(x, fn) { - for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) - if (!is_unit_disrupted(u) && is_hex_or_adjacent_to(unit_hex(u), x)) - fn(u) + return false } function for_each_enemy_unit_in_hex(x, fn) { @@ -1335,16 +1329,6 @@ function pick_path(to, speed) { return next_road } -function adjacent_hex_has_undisrupted_friendly_unit(here) { - for (let s = 0; s < 6; ++s) { - let next = here + hexnext[s] - if (is_map_hex(next)) - if (has_undisrupted_friendly_unit(next)) - return true - } - return false -} - function max_speed_of_undisrupted_and_unmoved_friendly_unit_in_hex(from) { let max_speed = 0 for_each_undisrupted_and_unmoved_friendly_unit_in_hex(from, u => { @@ -1683,7 +1667,7 @@ states.regroup_move_command_point = { gen_rommel_move() for (let x = first_hex; x <= last_hex; ++x) { if (!is_enemy_hex(x)) { - if (has_undisrupted_friendly_unit(x) || adjacent_hex_has_undisrupted_friendly_unit(x)) + if (hex_or_adjacent_has_undisrupted_and_unmoved_friendly_unit(x)) gen_action_hex(x) } } -- cgit v1.2.3