diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 36 |
1 files changed, 16 insertions, 20 deletions
@@ -1,7 +1,5 @@ "use strict" -// TODO: remove hussars when retreating across them - /* OPTIMIZE: fewer/smarter/smaller lists, smarter power control checks @@ -2899,6 +2897,15 @@ states.recruit = { }, } +function remove_hussars_at(s) { + for (let p of all_hussars) { + if (game.pos[p] === s) { + log("P" + p + " removed.") + game.pos[p] = ELIMINATED + } + } +} + function enter_piece_at(p, s) { if (is_general(p)) enter_general_at(p, s) @@ -2911,13 +2918,7 @@ function enter_general_at(p, s) { if (game.troops[p] < 1) game.troops[p] = 1 - // remove hussars - for (let p of all_hussars) { - if (game.pos[p] === s) { - log("P" + p + " removed.") - game.pos[p] = ELIMINATED - } - } + remove_hussars_at(s) // remove enemy supply trains for (let p of all_enemy_trains(game.power)) { @@ -2935,14 +2936,7 @@ function enter_general_at(p, s) { function enter_train_at(p, s) { game.pos[p] = s - - // remove hussars - for (let p of all_hussars) { - if (game.pos[p] === s) { - log("P" + p + " removed.") - game.pos[p] = ELIMINATED - } - } + remove_hussars_at(s) } states.re_enter_general_where = { @@ -3531,7 +3525,7 @@ function search_retreat_possible_dfs(result, seen, here, range) { if (is_illegal_cross_map_retreat(here, next)) continue if (range === 1) { - map_set(result, next, seen.slice()) + map_set(result, next, seen.slice(1)) } else { seen.push(next) search_retreat_possible_dfs(result, seen, next, range - 1) @@ -3579,8 +3573,10 @@ states.retreat = { log("Retreated to S" + to + ".") - console.log("RET", map_get(game.retreat, to, 0)) - // TODO: use path to stomp hussars + let path = map_get(game.retreat, to, 0) + for (let s of path) + remove_hussars_at(s) + remove_hussars_at(to) for (let p of game.selected) game.pos[p] = to |