diff options
author | Tor Andersson <tor@ccxvii.net> | 2025-02-10 00:00:55 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2025-02-10 00:00:55 +0100 |
commit | c097a8b27c3861263950528ef8993cc3e97a622a (patch) | |
tree | 6667f37060e534b7360e060adb2b21b70ddd0556 /rules.js | |
parent | b367009a36ea9797f0b614a1c03d004df1e08a30 (diff) | |
download | 1989-dawn-of-freedom-c097a8b27c3861263950528ef8993cc3e97a622a.tar.gz |
Abort if deck runs out instead of getting stuck in a loop.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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" |