From c13f573762bf44d88d07281b713bab60a9c9a1ba Mon Sep 17 00:00:00 2001 From: iainp5 Date: Sat, 22 Feb 2025 09:03:13 +0000 Subject: Reshuffle deck if no cards remaining at end of draw cards --- rules.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/rules.js b/rules.js index f44c028..05e1589 100644 --- a/rules.js +++ b/rules.js @@ -3982,13 +3982,9 @@ function draw_deck() { function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_hand_limit) { let turn = "communist" while (democrat_hand.length < dem_hand_limit || communist_hand.length < com_hand_limit) { - if (deck.length === 0) { - log_h3("--- Reshuffle ---") - deck.push(...game.strategy_discard) - game.strategy_discard = [] - if (deck.length === 0) - throw "NO MORE CARDS" // abort! - } else if (turn === "communist" && communist_hand.length < com_hand_limit) { + if (deck.length === 0) + reshuffle(deck) + else if (turn === "communist" && communist_hand.length < com_hand_limit) { communist_hand.push(draw_card(deck)) turn = "democrat" } else if (turn === "communist" && communist_hand.length >= com_hand_limit) { @@ -4002,9 +3998,19 @@ function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_han throw new Error("Impossible state when drawing cards.") } } + if (deck.length === 0) + reshuffle(deck) clear_undo() } +function reshuffle(deck) { + log_h3("--- Reshuffle ---") + deck.push(...game.strategy_discard) + game.strategy_discard = [] + if (deck.length === 0) + throw "NO MORE CARDS" // abort! +} + function draw_card(deck) { if (deck.length === 0) { log_h3('--- Reshuffle ---') -- cgit v1.2.3