diff options
-rw-r--r-- | rules.js | 45 |
1 files changed, 24 insertions, 21 deletions
@@ -2854,8 +2854,6 @@ function observer_hand() { return hand } -exports.is_checkpoint = (a, b) => a.turn !== b.turn - exports.view = function(state, current) { game = state @@ -3012,30 +3010,35 @@ function object_copy(original) { } function clear_undo() { - if (game.undo.length > 0) - game.undo = [] + if (game.undo) { + game.undo.length = 0 + } } function push_undo() { - let copy = {} - for (let k in game) { - let v = game[k] - if (k === "undo") - continue - else if (k === "log") - v = v.length - else if (typeof v === "object" && v !== null) - v = object_copy(v) - copy[k] = v + if (game.undo) { + let copy = {} + for (let k in game) { + let v = game[k] + if (k === "undo") + continue + else if (k === "log") + v = v.length + else if (typeof v === "object" && v !== null) + v = object_copy(v) + copy[k] = v + } + game.undo.push(copy) } - game.undo.push(copy) } function pop_undo() { - let save_log = game.log - let save_undo = game.undo - game = save_undo.pop() - save_log.length = game.log - game.log = save_log - game.undo = save_undo + if (game.undo) { + let save_log = game.log + let save_undo = game.undo + game = save_undo.pop() + save_log.length = game.log + game.log = save_log + game.undo = save_undo + } } |