From 34609fc9d2c8eaa38ac250a5687a980878fe42ec Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 29 Aug 2019 16:55:47 +0300 Subject: [PATCH] Extract a common class/struct. This is Refactoring / code cleanup. See: * https://en.wikipedia.org/wiki/God_object * https://en.wikipedia.org/wiki/Extract_class * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well. --- pysollib/game/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 9f0e8c2b..e2f51afd 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -78,6 +78,7 @@ else: PLAY_TIME_TIMEOUT = 200 +S_PLAY = 0x40 # ************************************************************************ # * Base class for all solitaire games @@ -442,6 +443,14 @@ class GameWinAnimation(NewStruct): height = attr.ib(default=0) +@attr.s +class GameMoves(NewStruct): + current = attr.ib(factory=list) + history = attr.ib(factory=list) + index = attr.ib(default=0) + state = attr.ib(default=S_PLAY) + + class Game(object): # for self.gstats.updated U_PLAY = _GLOBAL_U_PLAY @@ -454,8 +463,8 @@ class Game(object): S_DEAL = 0x10 S_FILL = 0x20 S_RESTORE = 0x30 - S_PLAY = 0x40 S_UNDO = 0x50 + S_PLAY = S_PLAY S_REDO = 0x60 # for loading and saving - subclasses should override if @@ -2763,12 +2772,7 @@ class Game(object): # def startMoves(self): - self.moves = Struct( - state=self.S_PLAY, - history=[], # list of lists of atomic moves - index=0, - current=[], # atomic moves for the current move - ) + self.moves = GameMoves() self.stats._reset_statistics() def __storeMove(self, am):