Skip to content

Commit

Permalink
Extract a function or class to step away from God Object.
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomif committed Jun 4, 2019
1 parent c12be2e commit d8e7a3e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pysollib/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ def _updateStatus_process_key_val(tb, sb, k, v):
raise AttributeError(k)


def _stats__is_perfect(stats):
"""docstring for _stats__is_perfect"""
return (stats.undo_moves == 0 and
stats.goto_bookmark_moves == 0 and
# stats.quickplay_moves == 0 and
stats.highlight_piles == 0 and
stats.highlight_cards == 0 and
stats.shuffle_moves == 0)


class Game(object):
# for self.gstats.updated
U_PLAY = 0
Expand Down Expand Up @@ -1813,7 +1823,7 @@ def canShuffle(self):
#

# game changed - i.e. should we ask the player to discard the game
def changed(self, restart=0):
def changed(self, restart=False):
if self.gstats.updated < 0:
return 0 # already won or lost
if self.gstats.loaded > 0:
Expand All @@ -1832,13 +1842,7 @@ def getWinStatus(self):
if not won or self.stats.hints > 0 or self.stats.demo_moves > 0:
# sorry, you lose
return won, 0, self.U_LOST
if (self.stats.undo_moves == 0 and
self.stats.goto_bookmark_moves == 0 and
# self.stats.quickplay_moves == 0 and
self.stats.highlight_piles == 0 and
self.stats.highlight_cards == 0 and
self.stats.shuffle_moves == 0):
# perfect !
if _stats__is_perfect(self.stats):
return won, 2, self.U_PERFECT
return won, 1, self.U_WON

Expand Down

0 comments on commit d8e7a3e

Please sign in to comment.