diff options
author | Tor Andersson <tor@ccxvii.net> | 2025-02-25 11:17:08 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2025-02-25 11:17:08 +0100 |
commit | f21b97d24b6ffffbc3a8c32ccdf418f3a81c9ed4 (patch) | |
tree | 20a1043e708cd723d47291b96325d802cf616ce8 | |
parent | 36f549c6bf4768caaf42656f280faf015c6fba24 (diff) | |
download | 1989-dawn-of-freedom-f21b97d24b6ffffbc3a8c32ccdf418f3a81c9ed4.tar.gz |
Don't hard fail if the deck runs out.
-rw-r--r-- | rules.js | 28 |
1 files changed, 12 insertions, 16 deletions
@@ -511,14 +511,7 @@ function gen_action_power_card(card) { exports.action = function (state, player, action, arg) { game = state if (states[game.state] && action in states[game.state]) { - try { - states[game.state][action](arg, player) - } catch (err) { - if (err === "NO MORE CARDS") - goto_game_over("Draw", "Deck ran out of cards.") - else - throw err - } + states[game.state][action](arg, player) } else { if (action === "undo" && game.undo && game.undo.length > 0) pop_undo() @@ -3982,11 +3975,14 @@ function draw_deck() { } function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_hand_limit) { + clear_undo() let turn = "communist" + let did_reshuffle = false while (democrat_hand.length < dem_hand_limit || communist_hand.length < com_hand_limit) { - if (deck.length === 0) + if (deck.length === 0) { + did_reshuffle = true reshuffle(deck) - else if (turn === "communist" && communist_hand.length < com_hand_limit) { + } 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) { @@ -3997,20 +3993,20 @@ function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_han } else if (turn === "democrat" && democrat_hand.length >= dem_hand_limit) { turn = "communist" } else { - throw new Error("Impossible state when drawing cards.") + break } } - if (deck.length === 0) - reshuffle(deck) - clear_undo() + if (deck.length === 0) { + log("Deck is empty.") + if (!did_reshuffle) + reshuffle(deck) + } } 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) { |