From 3cd6b6ecb23bbbba170be5d0b930f5f75e46d76d Mon Sep 17 00:00:00 2001 From: Joe R Date: Thu, 6 Oct 2022 22:50:14 -0400 Subject: [PATCH] Fixed manual undo causing false stuck notifications. --- pysollib/game/__init__.py | 16 +++++++++++++++- pysollib/move.py | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 2c90ffd5..69a61578 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -3029,6 +3029,19 @@ class Game(object): break else: redo = 1 + # try to detect an undo move for stuck-checking + undo = 0 + if len(moves.history) > 0: + mylen, m = len(current), moves.history[moves.index - 1] + if mylen == len(m): + for i in range(mylen): + a1 = current[i] + a2 = m[i] + if a1.__class__ is not a2.__class__ or \ + a1.cmpForUndo(a2) != 0: + break + else: + undo = 1 # add current move to history (which is a list of lists) if redo: # print "detected redo:", current @@ -3049,7 +3062,8 @@ class Game(object): self.updateStatus(moves=(moves.index, self.stats.total_moves)) self.updateMenus() self.updatePlayTime(do_after=0) - self.updateStuck() + if not undo: + self.updateStuck() reset_solver_dialog() return 1 diff --git a/pysollib/move.py b/pysollib/move.py index 90129449..b585a836 100644 --- a/pysollib/move.py +++ b/pysollib/move.py @@ -58,6 +58,11 @@ class AtomicMove: def cmpForRedo(self, other): return -1 + # Custom comparison for detecting manual undoing. + # Override only for move types where this is possible. + def cmpForUndo(self, other): + return -1 + # ************************************************************************ # * Move the top N cards from a stack to another stack. @@ -107,6 +112,11 @@ class AMoveMove(AtomicMove): cmp(self.from_stack_id, other.from_stack_id) or cmp(self.to_stack_id, other.to_stack_id)) + def cmpForUndo(self, other): + return (cmp(self.ncards, other.ncards) or + cmp(self.from_stack_id, other.to_stack_id) or + cmp(self.to_stack_id, other.from_stack_id)) + # ************************************************************************ # * Flip the top card of a stack.