From c097a8b27c3861263950528ef8993cc3e97a622a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 10 Feb 2025 00:00:55 +0100 Subject: Abort if deck runs out instead of getting stuck in a loop. --- rules.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index f54eef8..bcbb45c 100644 --- a/rules.js +++ b/rules.js @@ -513,7 +513,14 @@ function gen_action_power_card(card) { exports.action = function (state, player, action, arg) { game = state if (states[game.state] && action in states[game.state]) { - states[game.state][action](arg, player) + 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 + } } else { if (action === "undo" && game.undo && game.undo.length > 0) pop_undo() @@ -3984,6 +3991,8 @@ function draw_cards(deck, democrat_hand, communist_hand, dem_hand_limit, com_han 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) { communist_hand.push(draw_card(deck)) turn = "democrat" -- cgit v1.2.3