From 0f662fdb120824a7d0b96154bb641be27437289b Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 29 Dec 2019 11:08:33 +0200 Subject: [PATCH] Extract a function or class to step away from God Object. See: * https://en.wikipedia.org/wiki/God_object * https://www.c-sharpcorner.com/article/god-object-a-code-smell/ . This is Refactoring / code cleanup. See: * https://refactoring.com/catalog/extractMethod.html * 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 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 129b81d5..1296efae 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -450,6 +450,13 @@ class GameMoves(NewStruct): index = attr.ib(default=0) state = attr.ib(default=S_PLAY) +# used when loading a game +@attr.s +class GameLoadInfo(NewStruct): + ncards = attr.ib(default=0) + stacks = attr.ib(factory=list) + talon_round = attr.ib(default=1) + class Game(object): # for self.gstats.updated @@ -699,11 +706,7 @@ class Game(object): self.saveinfo = Struct( # needed for saving a game stack_caps=[], ) - self.loadinfo = Struct( # used when loading a game - stacks=None, - talon_round=1, - ncards=0, - ) + self.loadinfo = GameLoadInfo() self.snapshots = [] self.failed_snapshots = [] # local statistics are reset on each game restart