From b1a0780416e446d3823f713c7e7b21cac88d2c1d Mon Sep 17 00:00:00 2001 From: skomoroh Date: Wed, 22 Jul 2009 20:12:46 +0000 Subject: [PATCH] + added 'You Are Stuck' indicator * minor fixes git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@240 efabe8c0-fbe8-4139-b769-b5e6d273206e --- pysollib/game.py | 48 ++++++++++++++++++++++++++++++++++- pysollib/games/pyramid.py | 6 ++++- pysollib/games/siebenbisas.py | 10 ++++++++ pysollib/games/tournament.py | 20 ++++++++++----- pysollib/tile/statusbar.py | 2 ++ pysollib/tk/statusbar.py | 1 + 6 files changed, 78 insertions(+), 9 deletions(-) diff --git a/pysollib/game.py b/pysollib/game.py index 17907d4f..c22dfb8b 100644 --- a/pysollib/game.py +++ b/pysollib/game.py @@ -108,6 +108,7 @@ class Game: self.allstacks = [] self.sn_groups = [] # snapshot groups; list of list of similar stacks self.snapshots = [] + self.failed_snapshots = [] self.stackdesc_list = [] self.demo_logo = None self.pause_logo = None @@ -200,6 +201,9 @@ class Game: self.stats.update_time = time.time() self.busy = old_busy self.showHelp() # just in case + hint_class = self.getHintClass() + if hint_class is not None: + self.Stuck_Class = hint_class(self, 0) ##self.reallocateStacks() @@ -340,6 +344,7 @@ class Game: ncards = 0, ) self.snapshots = [] + self.failed_snapshots = [] # local statistics are reset on each game restart self.stats = Struct( hints = 0, # number of hints consumed @@ -436,7 +441,8 @@ class Game: self.updateStatus(player=self.app.opt.player, gamenumber=self.getGameNumber(format=1), moves=(0, 0), - stats=self.app.stats.getStats(self.app.opt.player, self.id)) + stats=self.app.stats.getStats(self.app.opt.player, self.id), + stuck='') reset_solver_dialog() # unhide toplevel when we use a progress bar if not self.preview: @@ -965,6 +971,9 @@ class Game: if isinstance(v, basestring): if sb: sb.updateText(time=v) continue + if k == 'stuck': + if sb: sb.updateText(stuck=v) + continue raise AttributeError(k) def _unmapHandler(self, event): @@ -1577,6 +1586,7 @@ class Game: # the actual hint class (or None) Hint_Class = DefaultHint Solver_Class = None + Stuck_Class = None def getHintClass(self): return self.Hint_Class @@ -2523,6 +2533,37 @@ Congratulations, you did it ! self.demo_logo = self.app.gimages.demo[int(n)] self.canvas.setTopImage(self.demo_logo) + # + # stuck + # + + def getStuck(self): + h = self.Stuck_Class.getHints(None) + if h: + self.failed_snapshots = [] + return True + if not self.canDealCards(): + return False + # can deal cards: do we have any hints in previous deals ? + sn = self.getSnapshot() + if sn in self.failed_snapshots: + return False + self.failed_snapshots.append(sn) + return True + + def updateStuck(self): + # stuck + if self.finished: + return + if self.Stuck_Class is None: + return + if self.getStuck(): + text = '' + else: + text = 'x' + #self.playSample("autopilotlost", priority=1000) + self.updateStatus(stuck=text) + # # Handle moves (with move history for undo/redo) @@ -2703,6 +2744,7 @@ Congratulations, you did it ! self.updateStatus(moves=(moves.index, self.stats.total_moves)) self.updateMenus() self.updatePlayTime(do_after=0) + self.updateStuck() reset_solver_dialog() return 1 @@ -2733,7 +2775,10 @@ Congratulations, you did it ! self.updateText() self.updateStatus(moves=(self.moves.index, self.stats.total_moves)) self.updateMenus() + self.updateStatus(stuck='') + self.failed_snapshots = [] reset_solver_dialog() + def redo(self): assert self.canRedo() @@ -2758,6 +2803,7 @@ Congratulations, you did it ! self.updateText() self.updateStatus(moves=(self.moves.index, self.stats.total_moves)) self.updateMenus() + self.updateStuck() reset_solver_dialog() diff --git a/pysollib/games/pyramid.py b/pysollib/games/pyramid.py index ccba850c..280d74e8 100644 --- a/pysollib/games/pyramid.py +++ b/pysollib/games/pyramid.py @@ -149,6 +149,10 @@ class Pyramid_RowStack(Pyramid_StackMethods, OpenStack): getBottomImage = Stack._getNoneBottomImage + def copyModel(self, clone): + OpenStack.copyModel(self, clone) + clone.blockmap = self.blockmap + # /*********************************************************************** # // Pyramid @@ -308,7 +312,7 @@ class Giza(Pyramid): for i in range(3): self.s.talon.dealRow(rows=self.s.reserves, frames=0) self.startDealSample() - self.s.talon.dealRow() + self.s.talon.dealRow(frames=4) # /*********************************************************************** diff --git a/pysollib/games/siebenbisas.py b/pysollib/games/siebenbisas.py index ecbbb5b0..cf5696a8 100644 --- a/pysollib/games/siebenbisas.py +++ b/pysollib/games/siebenbisas.py @@ -61,6 +61,16 @@ class SiebenBisAs_Hint(CautiousDefaultHint): score = 50000 self.addHint(score, 1, r, t) + def shallMovePile(self, from_stack, to_stack, pile, rpile): + if from_stack is to_stack or not to_stack.acceptsCards(from_stack, pile): + return 0 + # now check for loops + rr = self.ClonedStack(from_stack, stackcards=rpile) + if rr.acceptsCards(to_stack, pile): + # the pile we are going to move could be moved back - + # this is dangerous as we can create endless loops... + return 0 + return 1 # /*********************************************************************** # // Sieben bis As (Seven to Ace) diff --git a/pysollib/games/tournament.py b/pysollib/games/tournament.py index 8df400d6..bd72affc 100644 --- a/pysollib/games/tournament.py +++ b/pysollib/games/tournament.py @@ -221,6 +221,11 @@ class Saxony_Reserve(SS_RowStack): return _('Reserve. Build down by suit.') +class Saxony_Talon(DealRowTalonStack): + def dealCards(self, sound=False): + return self.dealRowAvail(rows=self.game.s.reserves[:8], sound=sound) + + class Saxony(Game): def createGame(self): @@ -230,31 +235,32 @@ class Saxony(Game): x, y, = l.XM+1.5*l.XS, l.YM for i in range(8): s.foundations.append(SS_FoundationStack(x, y, self, suit=i%4)) - x = x + l.XS + x += l.XS x, y = l.XM+1.5*l.XS, 2*l.YM+l.YS for i in range(8): - s.rows.append(BasicRowStack(x, y, self, max_move=1, max_accept=0)) - x = x + l.XS + s.reserves.append(BasicRowStack(x, y, self, max_move=1, max_accept=0)) + x += l.XS x, y = l.XM, 2*l.YM+l.YS for i in range(4): stack = Saxony_Reserve(x, y, self, max_move=1) - self.s.reserves.append(stack) + self.s.rows.append(stack) stack.CARD_YOFFSET = 0 y += l.YS x, y = self.width-l.XS, 2*l.YM+l.YS for i in range(4): self.s.reserves.append(ReserveStack(x, y, self)) y += l.YS - s.talon = DealRowTalonStack(l.XM, l.YM, self) + s.talon = Saxony_Talon(l.XM, l.YM, self) l.createText(s.talon, "ne") l.defaultStackGroups() def startGame(self): - self.s.talon.dealRow(rows=self.s.reserves, frames=0) + self.s.talon.dealRow(rows=self.s.reserves[8:], frames=0) + self.s.talon.dealRow(frames=0) self.startDealSample() - self.s.talon.dealRow() + self.s.talon.dealCards() # /*********************************************************************** diff --git a/pysollib/tile/statusbar.py b/pysollib/tile/statusbar.py index edb1f4a2..c19dadc5 100644 --- a/pysollib/tile/statusbar.py +++ b/pysollib/tile/statusbar.py @@ -149,6 +149,7 @@ class PysolStatusbar(MfxStatusbar): MfxStatusbar.__init__(self, top, row=4, column=0, columnspan=3) # for n, t, w in ( + ('stuck', _("'You Are Stuck' indicator"), 3), ('time', _('Playing time'), 10), ('moves', _('Moves/Total moves'), 10), ('gamenumber', _('Game number'), 26), @@ -156,6 +157,7 @@ class PysolStatusbar(MfxStatusbar): ): self._createLabel(n, tooltip=t, width=w) # + #self.configLabel("stuck", fg="red") l = self._createLabel('info', expand=True) l.config(padding=(8, 0)) self._createSizegrip() diff --git a/pysollib/tk/statusbar.py b/pysollib/tk/statusbar.py index 3458c636..fbb96dfd 100644 --- a/pysollib/tk/statusbar.py +++ b/pysollib/tk/statusbar.py @@ -147,6 +147,7 @@ class PysolStatusbar(MfxStatusbar): MfxStatusbar.__init__(self, top, row=3, column=0, columnspan=3) # for n, t, w in ( + ('stuck', _("'You Are Stuck' indicator"), 3), ('time', _('Playing time'), 10), ('moves', _('Moves/Total moves'), 10), ('gamenumber', _('Game number'), 26),