mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
+ 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
This commit is contained in:
parent
26f2fe277b
commit
b1a0780416
6 changed files with 78 additions and 9 deletions
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
# /***********************************************************************
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Reference in a new issue