mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
+ `shuffle tiles' menu entry
* some bugs fixed git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@169 efabe8c0-fbe8-4139-b769-b5e6d273206e
This commit is contained in:
parent
82002d061f
commit
2cbb6a8210
6 changed files with 34 additions and 18 deletions
|
@ -212,6 +212,7 @@ class PysolMenubarActions:
|
|||
self.setMenuState(ms.undo, "edit.undo")
|
||||
self.setMenuState(ms.redo, "edit.redo")
|
||||
self.setMenuState(ms.redo, "edit.redoall")
|
||||
self.setMenuState(ms.shuffle, "edit.shuffletiles")
|
||||
self.updateBookmarkMenuState()
|
||||
self.setMenuState(ms.restart, "edit.restart")
|
||||
self.setMenuState(ms.custom_game, "edit.editcurrentgame")
|
||||
|
|
|
@ -634,8 +634,8 @@ class AbstractMahjonggGame(Game):
|
|||
start_time = time.time()
|
||||
iters = [0]
|
||||
# limitations
|
||||
max_time = 2.0 # seconds
|
||||
max_iters = len(cards)
|
||||
max_time = 5.0 # seconds
|
||||
max_iters = 2*len(cards)
|
||||
|
||||
def is_suitable(stack, cards):
|
||||
for s in stack.blockmap.below:
|
||||
|
@ -690,10 +690,12 @@ class AbstractMahjonggGame(Game):
|
|||
break
|
||||
|
||||
# find suitable stacks
|
||||
suitable_stacks = []
|
||||
for r in rows:
|
||||
if nc[r.id] is None and is_suitable(r, nc):
|
||||
suitable_stacks.append(r)
|
||||
## suitable_stacks = []
|
||||
## for r in rows:
|
||||
## if nc[r.id] is None and is_suitable(r, nc):
|
||||
## suitable_stacks.append(r)
|
||||
suitable_stacks = [r for r in rows
|
||||
if nc[r.id] is None and is_suitable(r, nc)]
|
||||
|
||||
old_pairs = []
|
||||
i = factorial(len(suitable_stacks))/2/factorial(len(suitable_stacks)-2)
|
||||
|
|
|
@ -380,7 +380,10 @@ class AbstractShisenGame(AbstractMahjonggGame):
|
|||
def updateText(self):
|
||||
if self.preview > 1 or self.texts.info is None:
|
||||
return
|
||||
|
||||
from gettext import ungettext
|
||||
game = self.app.game
|
||||
|
||||
if 0:
|
||||
# find matching tiles
|
||||
stacks = game.s.rows
|
||||
|
@ -395,18 +398,23 @@ class AbstractShisenGame(AbstractMahjonggGame):
|
|||
if r.acceptsCards(t, t.cards):
|
||||
f += 1
|
||||
if f == 0:
|
||||
f = self.text_free_matching_pairs_0
|
||||
elif f == 1:
|
||||
f = self.text_free_matching_pairs_1
|
||||
f = _('No Free\nMatching\nPairs')
|
||||
else:
|
||||
f = str(f) + self.text_free_matching_pairs_2
|
||||
f = ungettext('%d Free\nMatching\nPair',
|
||||
'%d Free\nMatching\nPairs',
|
||||
f) % f
|
||||
else:
|
||||
f = ''
|
||||
|
||||
t = len(self.s.foundations[0].cards)
|
||||
t = str(t) + self.text_tiles_removed \
|
||||
+ str(self.NCARDS - t) + self.text_tiles_remaining \
|
||||
+ f
|
||||
r1 = ungettext('%d\nTile\nRemoved\n\n',
|
||||
'%d\nTiles\nRemoved\n\n',
|
||||
t) % t
|
||||
r2 = ungettext('%d\nTile\nRemaining\n\n',
|
||||
'%d\nTiles\nRemaining\n\n',
|
||||
self.NCARDS - t) % (self.NCARDS - t)
|
||||
|
||||
t = r1 + r2 + f
|
||||
self.texts.info.config(text = t)
|
||||
|
||||
|
||||
|
|
|
@ -386,6 +386,7 @@ class PysolMenubar(PysolMenubarActions):
|
|||
menu.add_command(label=n_("&Undo"), command=self.mUndo, accelerator="Z")
|
||||
menu.add_command(label=n_("&Redo"), command=self.mRedo, accelerator="R")
|
||||
menu.add_command(label=n_("Redo &all"), command=self.mRedoAll)
|
||||
menu.add_command(label=n_("Shu&ffle tiles"), command=self.mShuffle, accelerator="F")
|
||||
|
||||
menu.add_separator()
|
||||
submenu = MfxMenu(menu, label=n_("&Set bookmark"))
|
||||
|
|
|
@ -447,8 +447,7 @@ class AllGamesFrame(Tkinter.Frame):
|
|||
self.dialog.heading_tkfont,
|
||||
self.CHAR_W, self.CHAR_H)
|
||||
self.createHeader(player)
|
||||
bind(self.tree, '<Map>',
|
||||
lambda e, player=player: self.fillTreeview(player))
|
||||
bind(self.tree, '<Map>', self.mapEvent)
|
||||
|
||||
def getSelectedGame(self):
|
||||
sel = self.tree.selection()
|
||||
|
@ -468,6 +467,10 @@ class AllGamesFrame(Tkinter.Frame):
|
|||
else:
|
||||
run_button.config(state='disabled')
|
||||
|
||||
def mapEvent(self, *args):
|
||||
if not self.tree_items:
|
||||
self.fillTreeview(self.player)
|
||||
|
||||
def headerClick(self, column):
|
||||
if column == '#0':
|
||||
sort_by = 'name'
|
||||
|
@ -483,9 +486,9 @@ class AllGamesFrame(Tkinter.Frame):
|
|||
|
||||
def fillTreeview(self, player):
|
||||
if self.tree_items:
|
||||
return
|
||||
#self.tree.delete(tuple(self.tree_items))
|
||||
#self.tree_items = []
|
||||
#return
|
||||
self.tree.delete(tuple(self.tree_items))
|
||||
self.tree_items = []
|
||||
self.formatter.writeStats(player, sort_by=self.sort_by)
|
||||
if self.dialog.buttons:
|
||||
run_button = self.dialog.buttons[0]
|
||||
|
|
|
@ -383,6 +383,7 @@ class PysolMenubar(PysolMenubarActions):
|
|||
menu.add_command(label=n_("&Undo"), command=self.mUndo, accelerator="Z")
|
||||
menu.add_command(label=n_("&Redo"), command=self.mRedo, accelerator="R")
|
||||
menu.add_command(label=n_("Redo &all"), command=self.mRedoAll)
|
||||
menu.add_command(label=n_("Shu&ffle tiles"), command=self.mShuffle, accelerator="F")
|
||||
|
||||
menu.add_separator()
|
||||
submenu = MfxMenu(menu, label=n_("&Set bookmark"))
|
||||
|
|
Loading…
Add table
Reference in a new issue