summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-03-05 23:24:23 +0100
committerTor Andersson <tor@ccxvii.net>2024-03-05 23:24:23 +0100
commit6156f457c10e988fafb0f6acb776ddc6dc21ed0d (patch)
treef50c13079fd61d4bfcb89ca1a3009af36c7dff5a
parentaf3416c206fd74f4138d83f36230f1f8e5c27a72 (diff)
downloadrommel-in-the-desert-6156f457c10e988fafb0f6acb776ddc6dc21ed0d.tar.gz
Prefer Rommel move when offensive moves overlap.
-rw-r--r--rules.js100
1 files changed, 67 insertions, 33 deletions
diff --git a/rules.js b/rules.js
index 98d54fe..8efe01b 100644
--- a/rules.js
+++ b/rules.js
@@ -3814,38 +3814,53 @@ function do_gen_move_to(from, to, speed) {
if (can_move_to(to, speed)) {
gen_action_hex(to)
} else if (can_move_to(to, speed + 1)) {
- gen_action_forced_march(to)
+ if (!view.actions.hex || !set_has(view.actions.hex, to))
+ gen_action_forced_march(to)
}
}
function gen_move() {
- let rommel1 = (game.rommel === 1) ? 1 : 0
- let rommel2 = (game.rommel === 2) ? 1 : 0
+ let rommel1 = game.rommel === 1 ? 1 : 0
+ let rommel2 = game.rommel === 2 ? 1 : 0
let speed = unit_speed[game.selected]
let from = unit_hex(game.selected)
// view.path = {}
- if (!game.to1 && game.from1 === from) {
- for (let to of all_hexes) {
- if (to != from)
- do_gen_move_to(from, to, speed + rommel1)
- }
+ if (rommel1) {
+ if (!game.to1 && game.from1 === from)
+ for (let to of all_hexes)
+ if (to != from)
+ do_gen_move_to(from, to, speed + 1)
+ if (game.to1 && is_hex_or_adjacent_to(from, game.from1))
+ do_gen_move_to(from, game.to1, speed + 1)
}
- if (!game.to2 && game.from2 === from) {
- for (let to of all_hexes) {
- if (to != from)
- do_gen_move_to(from, to, speed + rommel2)
- }
+ if (rommel2) {
+ if (!game.to2 && game.from2 === from)
+ for (let to of all_hexes)
+ if (to != from)
+ do_gen_move_to(from, to, speed + 1)
+ if (game.to2 && is_hex_or_adjacent_to(from, game.from2))
+ do_gen_move_to(from, game.to2, speed + 1)
}
- if (game.to1 && is_hex_or_adjacent_to(from, game.from1)) {
- do_gen_move_to(from, game.to1, speed + rommel1)
+ if (!rommel1) {
+ if (!game.to1 && game.from1 === from)
+ for (let to of all_hexes)
+ if (to != from)
+ do_gen_move_to(from, to, speed)
+ if (game.to1 && is_hex_or_adjacent_to(from, game.from1))
+ do_gen_move_to(from, game.to1, speed)
}
- if (game.to2 && is_hex_or_adjacent_to(from, game.from2)) {
- do_gen_move_to(from, game.to2, speed + rommel2)
+ if (!rommel2) {
+ if (!game.to2 && game.from2 === from)
+ for (let to of all_hexes)
+ if (to != from)
+ do_gen_move_to(from, to, speed)
+ if (game.to2 && is_hex_or_adjacent_to(from, game.from2))
+ do_gen_move_to(from, game.to2, speed)
}
}
@@ -3880,8 +3895,8 @@ function gen_withdraw() {
}
function apply_move(to, is_retreat) {
- let rommel1 = (game.rommel === 1) ? 1 : 0
- let rommel2 = (game.rommel === 2) ? 1 : 0
+ let rommel1 = game.rommel === 1 ? 1 : 0
+ let rommel2 = game.rommel === 2 ? 1 : 0
let who = pop_selected()
let from = unit_hex(who)
let speed = unit_speed[who]
@@ -3890,21 +3905,41 @@ function apply_move(to, is_retreat) {
search_current_move(who, is_retreat)
- if (!game.to1 && game.from1 === from)
- if (can_move_to(to, speed + 1 + rommel1))
- return move_unit(who, to, speed + 1 + rommel1, 1)
+ if (rommel1) {
+ if (!game.to1 && game.from1 === from)
+ if (can_move_to(to, speed + 2))
+ return move_unit(who, to, speed + 2, 1)
+ if (game.to1 === to && is_hex_or_adjacent_to(from, game.from1))
+ if (can_move_to(to, speed + 2))
+ return move_unit(who, to, speed + 2, 1)
+ }
- if (!game.to2 && game.from2 === from)
- if (can_move_to(to, speed + 1 + rommel2))
- return move_unit(who, to, speed + 1 + rommel2, 2)
+ if (rommel2) {
+ if (!game.to2 && game.from2 === from)
+ if (can_move_to(to, speed + 2))
+ return move_unit(who, to, speed + 2, 2)
+ if (game.to2 === to && is_hex_or_adjacent_to(from, game.from2))
+ if (can_move_to(to, speed + 2))
+ return move_unit(who, to, speed + 2, 2)
+ }
- if (game.to1 === to && is_hex_or_adjacent_to(from, game.from1))
- if (can_move_to(to, speed + 1 + rommel1))
- return move_unit(who, to, speed + 1 + rommel1, 1)
+ if (!rommel1) {
+ if (!game.to1 && game.from1 === from)
+ if (can_move_to(to, speed + 1))
+ return move_unit(who, to, speed + 1, 1)
+ if (game.to1 === to && is_hex_or_adjacent_to(from, game.from1))
+ if (can_move_to(to, speed + 1))
+ return move_unit(who, to, speed + 1, 1)
+ }
- if (game.to2 === to && is_hex_or_adjacent_to(from, game.from2))
- if (can_move_to(to, speed + 1 + rommel2))
- return move_unit(who, to, speed + 1 + rommel2, 2)
+ if (!rommel2) {
+ if (!game.to2 && game.from2 === from)
+ if (can_move_to(to, speed + 1))
+ return move_unit(who, to, speed + 1, 2)
+ if (game.to2 === to && is_hex_or_adjacent_to(from, game.from2))
+ if (can_move_to(to, speed + 1))
+ return move_unit(who, to, speed + 1, 2)
+ }
throw Error("bad move")
}
@@ -7707,8 +7742,7 @@ function gen_action(action, argument) {
if (!(action in view.actions)) {
view.actions[action] = [ argument ]
} else {
- if (!view.actions[action].includes(argument))
- view.actions[action].push(argument)
+ set_add(view.actions[action], argument)
}
} else {
view.actions[action] = 1