From 712fdea3e8e8694996db89eff462018a11b2a133 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 19 May 2023 16:58:43 +0200 Subject: Handle corner cases with Surrender and no available destinations. Allow Louisbourg as a last resort. Eliminate otherwise. --- rules.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/rules.js b/rules.js index 7f30a1b..6ddbb46 100644 --- a/rules.js +++ b/rules.js @@ -5950,10 +5950,14 @@ function goto_surrender_place() { set_active_enemy() if (has_friendly_units(game.siege_where)) { game.state = 'surrender' - if (game.siege_where === LOUISBOURG) + if (game.siege_where === LOUISBOURG) { game.surrender = find_closest_friendly_unbesieged_fortification(QUEBEC) - else + } else { game.surrender = find_closest_friendly_unbesieged_fortification(game.siege_where) + if (game.surrender.length === 0) + if (has_unbesieged_friendly_fortifications(LOUISBOURG)) + game.surrender.push(LOUISBOURG) + } } else { end_surrender() } @@ -5968,13 +5972,21 @@ states.surrender = { view.where = game.siege_where for (let i=0; i < game.surrender.length; ++i) gen_action_space(game.surrender[i]) + if (game.surrender.length === 0) + gen_action('eliminate') }, space(s) { for (let p = first_friendly_piece; p <= last_friendly_piece; ++p) if (piece_node(p) === game.siege_where) move_piece_to(p, s) end_surrender() - } + }, + eliminate() { + for (let p = first_friendly_piece; p <= last_friendly_piece; ++p) + if (piece_node(p) === game.siege_where) + eliminate_piece(p) + end_surrender() + }, } function end_surrender() { -- cgit v1.2.3