summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js28
1 files changed, 12 insertions, 16 deletions
diff --git a/rules.js b/rules.js
index 4c68d1f..e39aadc 100644
--- a/rules.js
+++ b/rules.js
@@ -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) {