From 9b0b8624062863d799c82e73e1dee366b74bb440 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 14 Aug 2019 18:25:34 +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 | 52 +++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 39db68b7..e256dc7e 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -367,6 +367,36 @@ class GameHints(NewStruct): level = attr.ib(default=-1) +@attr.s +class GameStatsStruct(NewStruct): + hints = attr.ib(default=0) # number of hints consumed + # number of highlight piles consumed + highlight_piles = attr.ib(default=0) + # number of highlight matching cards consumed + highlight_cards = attr.ib(default=0) + # number of highlight same rank consumed + highlight_samerank = attr.ib(default=0) + undo_moves = attr.ib(default=0) # number of undos + redo_moves = attr.ib(default=0) # number of redos + # number of total moves in this game + total_moves = attr.ib(default=0) + player_moves = attr.ib(default=0) # number of moves + # number of moves while in demo mode + demo_moves = attr.ib(default=0) + autoplay_moves = attr.ib(default=0) # number of moves + quickplay_moves = attr.ib(default=0) # number of quickplay moves + goto_bookmark_moves = attr.ib(default=0) # number of goto bookmark + shuffle_moves = attr.ib(default=0) # number of shuffles (Mahjongg) + # did this game already update the demo stats ? + demo_updated = attr.ib(default=0) + update_time = attr.ib() + @update_time.default + def _foofoo(self): + return time.time() # for updateTime() + elapsed_time = attr.ib(default=0.0) + pause_start_time = attr.ib(default=0.0) + + class Game(object): # for self.gstats.updated U_PLAY = 0 @@ -623,27 +653,7 @@ class Game(object): self.snapshots = [] self.failed_snapshots = [] # local statistics are reset on each game restart - self.stats = Struct( - hints=0, # number of hints consumed - highlight_piles=0, # number of highlight piles consumed - # number of highlight matching cards consumed - highlight_cards=0, - highlight_samerank=0, # number of highlight same rank consumed - undo_moves=0, # number of undos - redo_moves=0, # number of redos - total_moves=0, # number of total moves in this game - player_moves=0, # number of moves - demo_moves=0, # number of moves while in demo mode - autoplay_moves=0, # number of moves - quickplay_moves=0, # number of quickplay moves - goto_bookmark_moves=0, # number of goto bookmark - shuffle_moves=0, # number of shuffles (Mahjongg) - # did this game already update the demo stats ? - demo_updated=0, - update_time=time.time(), # for updateTime() - elapsed_time=0.0, - pause_start_time=0.0, - ) + self.stats = GameStatsStruct() self.startMoves() if restart: return