summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-02-10 00:00:55 +0100
committerTor Andersson <tor@ccxvii.net>2025-02-10 00:00:55 +0100
commitc097a8b27c3861263950528ef8993cc3e97a622a (patch)
tree6667f37060e534b7360e060adb2b21b70ddd0556 /rules.js
parentb367009a36ea9797f0b614a1c03d004df1e08a30 (diff)
download1989-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.js11
1 files changed, 10 insertions, 1 deletions
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"