summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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