From 1d4b7179bc9baf13ef5bc7d39e6c86f6bfafe39c Mon Sep 17 00:00:00 2001 From: skomoroh Date: Sun, 3 Dec 2006 22:33:08 +0000 Subject: [PATCH] + 4 new games * misc. bugs fixes git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@102 39dd0a4e-7c14-0410-91b3-c4f2d318f732 --- pysollib/actions.py | 2 +- pysollib/games/acesup.py | 15 ++++++++- pysollib/games/fortythieves.py | 7 +++++ pysollib/games/grandfathersclock.py | 49 +++++++++++++++++++++++++++++ pysollib/games/numerica.py | 28 +++++++++++++++-- pysollib/games/pyramid.py | 35 +++++++++++++++++++++ pysollib/tile/menubar.py | 15 +++++---- pysollib/tile/selectcardset.py | 27 ++++++---------- pysollib/tile/selectgame.py | 36 ++++++++------------- pysollib/tile/soundoptionsdialog.py | 5 +-- pysollib/tile/tkwidget.py | 2 +- pysollib/tile/toolbar.py | 20 +----------- pysollib/tk/menubar.py | 2 +- 13 files changed, 164 insertions(+), 79 deletions(-) diff --git a/pysollib/actions.py b/pysollib/actions.py index 4aea1664..56335f13 100644 --- a/pysollib/actions.py +++ b/pysollib/actions.py @@ -623,7 +623,7 @@ class PysolMenubarActions: self.game.updateStatus(stats=self.app.stats.getStats(self.app.opt.player, self.game.id)) elif mode == 401: # start a new game with a gameid - if gameid: + if gameid and gameid != self.game.id: self.game.endGame() self.game.quitGame(gameid) elif mode == 402: diff --git a/pysollib/games/acesup.py b/pysollib/games/acesup.py index edcb199e..a7b859c2 100644 --- a/pysollib/games/acesup.py +++ b/pysollib/games/acesup.py @@ -269,12 +269,15 @@ class AcesUp5(AcesUp): # /*********************************************************************** # // Cover +# // Deck # ************************************************************************/ class Cover_RowStack(MonteCarlo_RowStack): def acceptsCards(self, from_stack, cards): if not OpenStack.acceptsCards(self, from_stack, cards): return False + if not self.cards: + return False return self.cards[-1].suit == cards[0].suit @@ -283,7 +286,7 @@ class Cover(AcesUp): Talon_Class = TalonStack RowStack_Class = StackWrapper(Cover_RowStack, max_accept=1) - FILL_STACKS_AFTER_DROP = 0 # for MonteCarlo_RowStack + FILL_STACKS_AFTER_DROP = 0 # for MonteCarlo_RowStack def fillStack(self, stack): if not self.s.talon.cards: @@ -297,9 +300,17 @@ class Cover(AcesUp): def isGameWon(self): + if self.s.talon.cards: + return False return len(self.s.foundations[0].cards) == 48 +class Deck(Cover): + Talon_Class = DealRowTalonStack + def fillStack(self, stack): + pass + + # /*********************************************************************** # // Firing Squad # ************************************************************************/ @@ -335,3 +346,5 @@ registerGame(GameInfo(552, Cover, "Cover", GI.GT_1DECK_TYPE, 1, 0, GI.SL_LUCK)) registerGame(GameInfo(583, FiringSquad, "Firing Squad", GI.GT_1DECK_TYPE, 1, 0, GI.SL_BALANCED)) +registerGame(GameInfo(684, Deck, "Deck", + GI.GT_1DECK_TYPE, 1, 0, GI.SL_LUCK)) diff --git a/pysollib/games/fortythieves.py b/pysollib/games/fortythieves.py index 83d2b928..70e9a648 100644 --- a/pysollib/games/fortythieves.py +++ b/pysollib/games/fortythieves.py @@ -167,6 +167,7 @@ class FortyThieves(Game): # // Marie Rose # // Big Courtyard # // San Juan Hill +# // Famous Fifty # // rows build down by suit # ************************************************************************/ @@ -269,6 +270,10 @@ class SanJuanHill(FortyThieves): FortyThieves.startGame(self) +class FamousFifty(FortyThieves): + DEAL = (0, 5) + + # /*********************************************************************** # // Deuces # ************************************************************************/ @@ -1239,4 +1244,6 @@ registerGame(GameInfo(632, Floradora, "Floradora", GI.GT_FORTY_THIEVES, 2, 0, GI.SL_MOSTLY_LUCK)) registerGame(GameInfo(679, TripleInterchange, "Triple Interchange", GI.GT_FORTY_THIEVES, 3, -1, GI.SL_MOSTLY_SKILL)) +registerGame(GameInfo(683, FamousFifty, "Famous Fifty", + GI.GT_FORTY_THIEVES, 2, 0, GI.SL_MOSTLY_SKILL)) diff --git a/pysollib/games/grandfathersclock.py b/pysollib/games/grandfathersclock.py index cf4acbf8..01296434 100644 --- a/pysollib/games/grandfathersclock.py +++ b/pysollib/games/grandfathersclock.py @@ -135,7 +135,56 @@ class GrandfathersClock(Game): return ((), (), ()) +# /*********************************************************************** +# // Dial +# ************************************************************************/ + +class Dial(Game): + + def createGame(self): + l, s = Layout(self), self.s + self.setSize(l.XM+8*l.XS, l.YM+4*l.YS) + + x0, y0 = l.XM+2*l.XS, l.YM + rank = 0 + for xx, yy in ((3.5, 0.15), + (4.5, 0.5), + (5, 1.5), + (4.5, 2.5), + (3.5, 2.85), + (2.5, 3), + (1.5, 2.85), + (0.5, 2.5), + (0, 1.5), + (0.5, 0.5), + (1.5, 0.15), + (2.5, 0), + (2.5, 1.5), + ): + x = int(x0 + xx*l.XS) + y = int(y0 + yy*l.YS) + s.foundations.append(AC_FoundationStack(x, y, self, suit=ANY_SUIT, + dir=0, max_cards=4, base_rank=rank, max_move=0)) + rank += 1 + + x, y = l.XM, l.YM + s.talon = WasteTalonStack(x, y, self, max_rounds=2) + l.createText(s.talon, 's') + x += l.XS + s.waste = WasteStack(x, y, self) + l.createText(s.waste, 's') + + l.defaultStackGroups() + + def startGame(self): + self.startDealSample() + self.s.talon.dealCards() # deal first card to WasteStack + + + # register the game registerGame(GameInfo(261, GrandfathersClock, "Grandfather's Clock", GI.GT_1DECK_TYPE | GI.GT_OPEN, 1, 0, GI.SL_BALANCED)) +registerGame(GameInfo(682, Dial, "Dial", + GI.GT_1DECK_TYPE, 1, 1, GI.SL_LUCK)) diff --git a/pysollib/games/numerica.py b/pysollib/games/numerica.py index e06a1edf..fde489bd 100644 --- a/pysollib/games/numerica.py +++ b/pysollib/games/numerica.py @@ -58,6 +58,10 @@ class Numerica_Hint(DefaultHint): def _getMoveWasteScore(self, score, color, r, t, pile, rpile): assert r in (self.game.s.waste, self.game.s.talon) and len(pile) == 1 + score = self._computeScore(r, t) + return score, color + + def _computeScore(self, r, t): score = 30000 if len(t.cards) == 0: score = score - (KING - r.cards[0].rank) * 1000 @@ -68,7 +72,7 @@ class Numerica_Hint(DefaultHint): score = 20000 else: score = score - (t.cards[-1].rank - r.cards[0].rank) * 1000 - return score, color + return score # /*********************************************************************** @@ -541,6 +545,24 @@ class Chamberlain(Gloaming): # // Toad # ************************************************************************/ +class Toad_Hint(Numerica_Hint): + def computeHints(self): + self.step010(self.game.s.rows, self.game.s.rows) + self.step060(self.game.sg.reservestacks, self.game.s.rows) + + # try if we should move a card from a ReserveStack to a RowStack + def step060(self, reservestacks, rows): + for r in reservestacks: + if not r.cards: + continue + for t in rows: + if t.cards: + score = self._computeScore(r, t) + self.addHint(score, 1, r, t) + else: + self.addHint(90000+r.cards[-1].rank, 1, r, t) + + class Toad_TalonStack(DealRowTalonStack): def canDealCards(self): if not DealRowTalonStack.canDealCards(self): @@ -554,7 +576,7 @@ class Toad_TalonStack(DealRowTalonStack): class Toad(Game): - #Hint_Class = Numerica_Hint + Hint_Class = Toad_Hint def createGame(self, reserves=3, rows=5): # create layout @@ -866,7 +888,7 @@ registerGame(GameInfo(378, Gloaming, "Gloaming", registerGame(GameInfo(379, Chamberlain, "Chamberlain", GI.GT_NUMERICA | GI.GT_OPEN | GI.GT_ORIGINAL, 1, 0, GI.SL_MOSTLY_SKILL)) registerGame(GameInfo(402, Toad, "Toad", - GI.GT_NUMERICA | GI.GT_ORIGINAL, 2, 0, GI.SL_BALANCED)) + GI.GT_NUMERICA, 2, 0, GI.SL_BALANCED)) registerGame(GameInfo(430, PussInTheCorner, "Puss in the Corner", GI.GT_NUMERICA, 1, 1, GI.SL_BALANCED)) registerGame(GameInfo(435, Shifting, "Shifting", diff --git a/pysollib/games/pyramid.py b/pysollib/games/pyramid.py index 7543b4ea..55d4e0c0 100644 --- a/pysollib/games/pyramid.py +++ b/pysollib/games/pyramid.py @@ -1080,6 +1080,39 @@ class TwoPyramids(Pyramid): self.sg.openstacks.append(s.waste) +# /*********************************************************************** +# // King Tut +# ************************************************************************/ + +class KingTut(RelaxedPyramid): + + def createGame(self): + l, s = Layout(self), self.s + + w = l.XM + max(7*l.XS, 2*l.XS+23*l.XOFFSET) + h = l.YM + 5.5*l.YS + self.setSize(w, h) + + x, y = l.XM+(w-7*l.XS)/2, l.YM + s.rows = self._createPyramid(l, x, y, 7) + + x, y = l.XM, self.height-l.YS + s.talon = WasteTalonStack(x, y, self, max_rounds=UNLIMITED_REDEALS, num_deal=3) + l.createText(s.talon, "n") + x += l.XS + s.waste = Pyramid_Waste(x, y, self, max_accept=1) + s.waste.CARD_XOFFSET = l.XOFFSET + l.createText(s.waste, "n") + + x, y = self.width - l.XS, l.YM + s.foundations.append(self.Foundation_Class(x, y, self, + suit=ANY_SUIT, dir=0, base_rank=ANY_RANK, + max_move=0, max_cards=52)) + + l.defaultStackGroups() + self.sg.openstacks.append(s.waste) + + # register the game registerGame(GameInfo(38, Pyramid, "Pyramid", @@ -1115,4 +1148,6 @@ registerGame(GameInfo(674, Exit, "Exit", GI.GT_PAIRING_TYPE, 1, 0, GI.SL_MOSTLY_SKILL)) registerGame(GameInfo(677, TwoPyramids, "Two Pyramids", GI.GT_PAIRING_TYPE | GI.GT_ORIGINAL, 2, 2, GI.SL_MOSTLY_LUCK)) +registerGame(GameInfo(681, KingTut, "King Tut", + GI.GT_PAIRING_TYPE, 1, -1, GI.SL_MOSTLY_LUCK)) diff --git a/pysollib/tile/menubar.py b/pysollib/tile/menubar.py index 48bca49c..c06e8cf8 100644 --- a/pysollib/tile/menubar.py +++ b/pysollib/tile/menubar.py @@ -39,7 +39,7 @@ __all__ = ['PysolMenubar'] # imports import math, os, re import Tile as Tkinter -import tkColorChooser, tkFileDialog +import tkFileDialog # PySol imports from pysollib.mfxutil import destruct, Struct, kwdefault @@ -92,12 +92,11 @@ def createToolbarMenu(menubar, menu): ## variable=menubar.tkopt.toolbar_relief, ## value=Tkinter.RAISED, ## command=menubar.mOptToolbarRelief) - if Tkinter.TkVersion >= 8.4: - submenu = MfxMenu(menu, label=n_('Compound'), tearoff=tearoff) - for comp, label in COMPOUNDS: - submenu.add_radiobutton( - label=label, variable=menubar.tkopt.toolbar_compound, - value=comp, command=menubar.mOptToolbarCompound) + submenu = MfxMenu(menu, label=n_('Compound'), tearoff=tearoff) + for comp, label in COMPOUNDS: + submenu.add_radiobutton( + label=label, variable=menubar.tkopt.toolbar_compound, + value=comp, command=menubar.mOptToolbarCompound) menu.add_separator() menu.add_radiobutton(label=n_("Hide"), variable=menubar.tkopt.toolbar, value=0, @@ -1176,7 +1175,7 @@ class PysolMenubar(PysolMenubarActions): title=_("Select table background"), manager=self.app.tabletile_manager, key=key) - if d.status == 0 and d.button in (0, 1): + if d.status == 0 and d.button == 0: if type(d.key) is str: tile = self.app.tabletile_manager.get(0) tile.color = d.key diff --git a/pysollib/tile/selectcardset.py b/pysollib/tile/selectcardset.py index ffeb3093..2402e954 100644 --- a/pysollib/tile/selectcardset.py +++ b/pysollib/tile/selectcardset.py @@ -200,18 +200,12 @@ class SelectCardsetDialogWithPreview(MfxDialog): w1, w2 = 216, 400 else: w1, w2 = 200, 300 - if Tkinter.TkVersion >= 8.4: - paned_window = Tkinter.PanedWindow(top_frame) - paned_window.pack(expand=1, fill='both') - left_frame = Tkinter.Frame(paned_window) - right_frame = Tkinter.Frame(paned_window) - paned_window.add(left_frame) - paned_window.add(right_frame) - else: - left_frame = Tkinter.Frame(top_frame) - right_frame = Tkinter.Frame(top_frame) - left_frame.pack(side='left', expand=0, fill='both') - right_frame.pack(side='right', expand=1, fill='both') + paned_window = Tkinter.PanedWindow(top_frame) + paned_window.pack(expand=1, fill='both') + left_frame = Tkinter.Frame(paned_window) + right_frame = Tkinter.Frame(paned_window) + paned_window.add(left_frame) + paned_window.add(right_frame) font = app.getFont("default") self.tree = self.Tree_Class(self, left_frame, key=key, default=kw.default, @@ -316,10 +310,7 @@ class CardsetInfoDialog(MfxDialog): frame.pack(fill="both", expand=True, padx=5, pady=10) # # - if Tkinter.TkVersion >= 8.4: - info_frame = Tkinter.LabelFrame(frame, text=_('About cardset')) - else: - info_frame = Tkinter.Frame(frame) + info_frame = Tkinter.LabelFrame(frame, text=_('About cardset')) info_frame.grid(row=0, column=0, columnspan=2, sticky='ew', padx=0, pady=5, ipadx=5, ipady=5) styles = nationalities = year = None @@ -343,10 +334,10 @@ class CardsetInfoDialog(MfxDialog): if not t is None: l = Tkinter.Label(info_frame, text=n, anchor='w', justify='left') - l.grid(row=row, column=0, sticky='nw') + l.grid(row=row, column=0, sticky='nw', padx=4) l = Tkinter.Label(info_frame, text=t, anchor='w', justify='left') - l.grid(row=row, column=1, sticky='nw') + l.grid(row=row, column=1, sticky='nw', padx=4) row += 1 if images: try: diff --git a/pysollib/tile/selectgame.py b/pysollib/tile/selectgame.py index c85d4ebd..86902c74 100644 --- a/pysollib/tile/selectgame.py +++ b/pysollib/tile/selectgame.py @@ -326,34 +326,24 @@ class SelectGameDialogWithPreview(SelectGameDialog): ##padx, pady = kw.padx, kw.pady padx, pady = kw.padx/2, kw.pady/2 # PanedWindow - if Tkinter.TkVersion >= 8.4: - paned_window = Tkinter.PanedWindow(top_frame) - paned_window.pack(expand=1, fill='both') - left_frame = Tkinter.Frame(paned_window) - right_frame = Tkinter.Frame(paned_window) - paned_window.add(left_frame) - paned_window.add(right_frame) - else: - left_frame = Tkinter.Frame(top_frame) - right_frame = Tkinter.Frame(top_frame) - left_frame.pack(side='left', expand=1, fill='both') - right_frame.pack(side='right', expand=1, fill='both') + paned_window = Tkinter.PanedWindow(top_frame) + paned_window.pack(expand=1, fill='both') + left_frame = Tkinter.Frame(paned_window) + right_frame = Tkinter.Frame(paned_window) + paned_window.add(left_frame) + paned_window.add(right_frame) # Tree font = app.getFont("default") self.tree = self.Tree_Class(self, left_frame, key=gameid, default=kw.default, font=font, width=w1) self.tree.frame.pack(padx=padx, pady=pady, expand=1, fill='both') # LabelFrame - if Tkinter.TkVersion >= 8.4: - info_frame = Tkinter.LabelFrame(right_frame, text=_('About game')) - stats_frame = Tkinter.LabelFrame(right_frame, text=_('Statistics')) - else: - info_frame = Tkinter.Frame(right_frame, bd=2, relief='groove') - stats_frame = Tkinter.Frame(right_frame, bd=2, relief='groove') + info_frame = Tkinter.LabelFrame(right_frame, text=_('About game')) info_frame.grid(row=0, column=0, padx=padx, pady=pady, - ipadx=padx, ipady=pady, sticky='nws') + ipadx=4, ipady=4, sticky='nws') + stats_frame = Tkinter.LabelFrame(right_frame, text=_('Statistics')) stats_frame.grid(row=0, column=1, padx=padx, pady=pady, - ipadx=padx, ipady=pady, sticky='nws') + ipadx=4, ipady=4, sticky='nws') # Info self.info_labels = {} i = 0 @@ -362,7 +352,7 @@ class SelectGameDialogWithPreview(SelectGameDialog): ('altnames', _('Alternate names:'), info_frame, 1), ('category', _('Category:'), info_frame, 2), ('type', _('Type:'), info_frame, 3), - ('skill_level', _('Skill level:'), info_frame, 4), + ('skill_level', _('Skill level:'), info_frame, 4), ('decks', _('Decks:'), info_frame, 5), ('redeals', _('Redeals:'), info_frame, 6), # @@ -374,9 +364,9 @@ class SelectGameDialogWithPreview(SelectGameDialog): ('percent', _('% won:'), stats_frame, 5), ): title_label = Tkinter.Label(f, text=t, justify='left', anchor='w') - title_label.grid(row=row, column=0, sticky='nw') + title_label.grid(row=row, column=0, sticky='nw', padx=4) text_label = Tkinter.Label(f, justify='left', anchor='w') - text_label.grid(row=row, column=1, sticky='nw') + text_label.grid(row=row, column=1, sticky='nw', padx=4) self.info_labels[n] = (title_label, text_label) ##info_frame.columnconfigure(1, weight=1) info_frame.rowconfigure(6, weight=1) diff --git a/pysollib/tile/soundoptionsdialog.py b/pysollib/tile/soundoptionsdialog.py index 411b1736..2d91ad46 100644 --- a/pysollib/tile/soundoptionsdialog.py +++ b/pysollib/tile/soundoptionsdialog.py @@ -142,10 +142,7 @@ class SoundOptionsDialog(MfxDialog): # remove "Apply" button kw.strings[1] = None # - if Tkinter.TkVersion >= 8.4: - frame = Tkinter.LabelFrame(top_frame, text=_('Enable samles')) - else: - frame = Tkinter.Frame(top_frame, bd=2, relief='groove') + frame = Tkinter.LabelFrame(top_frame, text=_('Enable samles')) frame.pack(expand=1, fill='both', padx=5, pady=5) frame.columnconfigure(0, weight=1) frame.columnconfigure(1, weight=1) diff --git a/pysollib/tile/tkwidget.py b/pysollib/tile/tkwidget.py index ef841aae..8f0816fb 100644 --- a/pysollib/tile/tkwidget.py +++ b/pysollib/tile/tkwidget.py @@ -232,7 +232,7 @@ class MfxDialog: # ex. _ToplevelDialog if column >= sep_column: widget.config(width=button_width) else: - widget.config(width=len(s)) + widget.config(width=max(button_width, len(s))) if accel_indx >= 0: # key accelerator widget.config(underline=accel_indx) diff --git a/pysollib/tile/toolbar.py b/pysollib/tile/toolbar.py index 50b930fe..b227520f 100644 --- a/pysollib/tile/toolbar.py +++ b/pysollib/tile/toolbar.py @@ -251,7 +251,6 @@ class PysolToolbar(PysolToolbarActions): ): if l is None: sep = self._createSeparator() - sep.bind("<1>", self.clickHandler) sep.bind("<3>", self.rightclickHandler) elif l == 'Pause': self._createButton(l, f, check=True, tooltip=t) @@ -259,8 +258,6 @@ class PysolToolbar(PysolToolbarActions): self._createButton(l, f, tooltip=t) #~sep = self._createFlatSeparator() - #~sep.bind("<1>", self.clickHandler) - #~sep.bind("<3>", self.rightclickHandler) position=len(self._widgets) self.frame.rowconfigure(position, weight=1) self.frame.columnconfigure(position, weight=1) @@ -269,9 +266,7 @@ class PysolToolbar(PysolToolbarActions): tooltip=_("Player options")) # self.player_label.bind("<1>",self.mOptPlayerOptions) - ##self.player_label.bind("<3>",self.mOptPlayerOptions) self.popup = None - self.frame.bind("<1>", self.clickHandler) self.frame.bind("<3>", self.rightclickHandler) # self.setCompound(compound, force=True) @@ -534,15 +529,12 @@ class PysolToolbar(PysolToolbarActions): w.config(relief=self.button_relief, bd=bd) elif isinstance(w, ToolbarCheckbutton): w.config(relief=self.button_relief, bd=bd) - if Tkinter.TkVersion >= 8.4: - w.config(offrelief=self.button_relief) + w.config(offrelief=self.button_relief) elif w.__class__ is ToolbarSeparator: # not ToolbarFlatSeparator w.config(relief=self.separator_relief) return True def setCompound(self, compound, force=False): - if Tkinter.TkVersion < 8.4: - return False if not force and self.compound == compound: return False for w in self._widgets: @@ -569,10 +561,6 @@ class PysolToolbar(PysolToolbarActions): # Mouse event handlers # - def clickHandler(self, event): - if self._busy(): return EVENT_HANDLED - return EVENT_HANDLED - def rightclickHandler(self, event): if self._busy(): return EVENT_HANDLED if self.popup: @@ -580,12 +568,6 @@ class PysolToolbar(PysolToolbarActions): self.popup.tk_popup(event.x_root, event.y_root) return EVENT_HANDLED - def middleclickHandler(self, event): - if self._busy(): return EVENT_HANDLED - if 1 <= self.side <= 2: - self.menubar.setToolbarSide(3 - self.side) - return EVENT_HANDLED - def getSize(self): if self.compound == 'text': return 0 diff --git a/pysollib/tk/menubar.py b/pysollib/tk/menubar.py index 87208604..6cf09b58 100644 --- a/pysollib/tk/menubar.py +++ b/pysollib/tk/menubar.py @@ -1179,7 +1179,7 @@ class PysolMenubar(PysolMenubarActions): title=_("Select table background"), manager=self.app.tabletile_manager, key=key) - if d.status == 0 and d.button in (0, 1): + if d.status == 0 and d.button == 0: if type(d.key) is str: tile = self.app.tabletile_manager.get(0) tile.color = d.key