From c825c3c6dfc3a36e0872021df194cc1ea320b229 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 13 Mar 2018 10:28:12 +0200 Subject: [PATCH] Refactoring. --- pysollib/hint.py | 6 +++--- pysollib/pysolgtk/menubar.py | 10 ++++------ pysollib/stack.py | 9 ++++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pysollib/hint.py b/pysollib/hint.py index c683cba9..90aaf1b1 100644 --- a/pysollib/hint.py +++ b/pysollib/hint.py @@ -419,7 +419,7 @@ class DefaultHint(AbstractHint): else: d = (c.rank - t.cap.base_rank) % t.cap.mod if d > t.cap.mod // 2: - d = d - t.cap.mod + d -= t.cap.mod if abs(d) <= 1: # drop Ace and 2 immediately score = 92000 @@ -551,7 +551,7 @@ class DefaultHint(AbstractHint): if stack and stack is not r: assert ncards == 1 drop_info.append((c, stack, ncards, i)) - i = i + 1 + i += 1 # now try to make a move so that the drop-card will get free for di in drop_info: c = di[0] @@ -565,7 +565,7 @@ class DefaultHint(AbstractHint): continue # print "drop move", r, t, sub_pile score = 40000 - score = score + 1000 + (self.K - r.getCard().rank) + score += 1000 + (self.K - r.getCard().rank) # force the drop (to avoid loops) force = (999999, 0, di[2], r, di[1], self.BLUE, None) self.addHint( diff --git a/pysollib/pysolgtk/menubar.py b/pysollib/pysolgtk/menubar.py index 52191d7a..bb483d74 100644 --- a/pysollib/pysolgtk/menubar.py +++ b/pysollib/pysolgtk/menubar.py @@ -609,13 +609,11 @@ class PysolMenubarTk: filename = self.game.filename if not filename: filename = self.app.getGameSaveName(self.game.id) - if os.name == 'posix': - filename = filename + '-' + self.game.getGameNumber(format=0) - elif os.path.supports_unicode_filenames: # new in python 2.3 - filename = filename + '-' + self.game.getGameNumber(format=0) + if os.name == 'posix' or os.path.supports_unicode_filenames: + filename += '-' + self.game.getGameNumber(format=0) else: - filename = filename + '-01' - filename = filename + '.pso' + filename += '-01' + filename += '.pso' idir, ifile = os.path.split(os.path.normpath(filename)) if not idir: idir = self.app.dn.savegames diff --git a/pysollib/stack.py b/pysollib/stack.py index 599ab1fc..0bc8de99 100644 --- a/pysollib/stack.py +++ b/pysollib/stack.py @@ -1681,7 +1681,7 @@ class DealRow_StackMethods: for r in stacks: assert r is not self while self.cards: - n = n + 1 + n += 1 if flip: self.game.flipMove(self) if flip and self.cards[-1].rank == rank: @@ -1728,7 +1728,7 @@ class DealBaseCard_StackMethods: if not c.face_up: self.game.flipMove(self) self.game.moveMove(1, self, s, frames=frames) - ncards = ncards - 1 + ncards -= 1 class RedealCards_StackMethods: @@ -2781,9 +2781,8 @@ class SuperMoveStack_StackMethods: return max_move n = getNumberOfFreeStacks(self.game.s.rows) if to_stack_ncards == 0: - n = n - 1 - max_move = max_move * (2 ** n) - return max_move + n -= 1 + return max_move << max(n, 0) def _getNumSSSeq(self, cards): # num of same-suit sequences (for SuperMoveSpider_RowStack)