diff options
author | iainp5 <iain.pearce.ip@gmail.com> | 2025-02-22 09:03:13 +0000 |
---|---|---|
committer | iainp5 <iain.pearce.ip@gmail.com> | 2025-02-22 09:03:13 +0000 |
commit | c13f573762bf44d88d07281b713bab60a9c9a1ba (patch) | |
tree | 2e43fd29ead4455d24dd8d3a1b1d58804edfa6c0 | |
parent | 70102356a743f0474f01a3a0147a8915d8f04f5c (diff) | |
download | 1989-dawn-of-freedom-c13f573762bf44d88d07281b713bab60a9c9a1ba.tar.gz |
Reshuffle deck if no cards remaining at end of draw cards
-rw-r--r-- | rules.js | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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 ---') |