From e81412d934d02edbe80f34e1b3613067f3478b91 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 17 Nov 2022 15:54:44 +0100 Subject: Fix pretender going home bug! --- rules.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index aa1e069..cf46587 100644 --- a/rules.js +++ b/rules.js @@ -359,7 +359,29 @@ function available_home(who) { return where } -function go_home_if_possible(who) { +function pretender_go_home_if_possible(who) { + if (!is_in_exile(who)) { + // pretender heirs must go home! + if (is_heir(who)) + return true + let n = count_available_homes(who) + if (n === 0) { + game.turn_log.push([block_name(who), "Pool"]) + disband(who) + } else if (n === 1) { + let home = available_home(who) + if (game.location[who] !== home) { + game.location[who] = home + game.turn_log.push([block_name(who), "#" + game.location[who]]) // TODO: "Home"? + } + } else { + return true + } + } + return false +} + +function king_go_home_if_possible(who) { if (!is_in_exile(who)) { let n = count_available_homes(who) if (n === 0) { @@ -3100,7 +3122,7 @@ function goto_pretender_goes_home() { let choices = false for (let b = 0; b < block_count; ++b) if (block_owner(b) === game.active && is_block_on_map(b)) - if (go_home_if_possible(b)) + if (pretender_go_home_if_possible(b)) choices = true if (!choices) { print_turn_log_no_count("Pretender went home:") @@ -3240,7 +3262,7 @@ function goto_king_goes_home() { let choices = false for (let b = 0; b < block_count; ++b) if (block_owner(b) === game.active && is_block_on_map(b)) - if (go_home_if_possible(b)) + if (king_go_home_if_possible(b)) choices = true if (!choices) { print_turn_log_no_count("King went home:") -- cgit v1.2.3