diff --git a/data/images/toolbar/bluecurve/large/shuffle.gif b/data/images/toolbar/bluecurve/large/shuffle.gif new file mode 100644 index 00000000..ad0e5e30 Binary files /dev/null and b/data/images/toolbar/bluecurve/large/shuffle.gif differ diff --git a/data/images/toolbar/bluecurve/small/shuffle.gif b/data/images/toolbar/bluecurve/small/shuffle.gif new file mode 100644 index 00000000..6e863e0f Binary files /dev/null and b/data/images/toolbar/bluecurve/small/shuffle.gif differ diff --git a/data/images/toolbar/crystal/large/shuffle.gif b/data/images/toolbar/crystal/large/shuffle.gif new file mode 100644 index 00000000..305acf80 Binary files /dev/null and b/data/images/toolbar/crystal/large/shuffle.gif differ diff --git a/data/images/toolbar/crystal/small/shuffle.gif b/data/images/toolbar/crystal/small/shuffle.gif new file mode 100644 index 00000000..245971af Binary files /dev/null and b/data/images/toolbar/crystal/small/shuffle.gif differ diff --git a/pysollib/app.py b/pysollib/app.py index cfd69187..02a3a214 100644 --- a/pysollib/app.py +++ b/pysollib/app.py @@ -801,6 +801,8 @@ class Application: del self.opt.recent_gameid[self.opt.num_recent_games:] self.menubar.updateRecentGamesMenu(self.opt.recent_gameid) self.menubar.updateFavoriteGamesMenu() + # hide/show "Shuffle" button + self.toolbar.config('shuffle', self.game.canShuffle()) # delete intro progress bar if self.intro.progress: self.intro.progress.destroy() diff --git a/pysollib/game.py b/pysollib/game.py index abaaaf78..0f8ffa77 100644 --- a/pysollib/game.py +++ b/pysollib/game.py @@ -361,6 +361,7 @@ class Game: autoplay_moves = 0, # number of moves quickplay_moves = 0, # number of quickplay moves goto_bookmark_moves = 0, # number of goto bookmark + shuffle_moves = 0, # number of shuffles (Mahjongg) demo_updated = 0, # did this game already update the demo stats ? update_time = time.time(), # for updateTime() elapsed_time = 0.0, @@ -1618,10 +1619,11 @@ class Game: # sorry, you lose return won, 0, self.U_LOST if (self.stats.undo_moves == 0 and - self.stats.goto_bookmark_moves == 0 and + self.stats.goto_bookmark_moves == 0 and ### self.stats.quickplay_moves == 0 and - self.stats.highlight_piles == 0 and - self.stats.highlight_cards == 0): + self.stats.highlight_piles == 0 and + self.stats.highlight_cards == 0 and + self.stats.shuffle_moves == 0): # perfect ! return won, 2, self.U_PERFECT return won, 1, self.U_WON diff --git a/pysollib/games/mahjongg/mahjongg.py b/pysollib/games/mahjongg/mahjongg.py index dabd9042..43685e15 100644 --- a/pysollib/games/mahjongg/mahjongg.py +++ b/pysollib/games/mahjongg/mahjongg.py @@ -43,7 +43,7 @@ from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint from pysollib.pysoltk import MfxCanvasText, MfxCanvasImage from pysollib.pysoltk import bind, EVENT_HANDLED, ANCHOR_NW from pysollib.pysoltk import MfxMessageDialog -from pysollib.settings import TOOLKIT +from pysollib.settings import TOOLKIT, DEBUG def factorial(x): @@ -557,6 +557,7 @@ class AbstractMahjonggGame(Game): def _shuffleHook1(self, cards): + # old version; it generate a very easy layouts old_cards = cards[:] rows = self.s.rows @@ -703,16 +704,16 @@ class AbstractMahjonggGame(Game): if time.time() - start_time > max_time: return None + # select two suitable stacks while True: - # create uniq pair + # create a uniq pair r1 = self.random.randrange(0, len(suitable_stacks)) - r2 = self.random.randrange(0, len(suitable_stacks)-1) - if r2 >= r1: - r2 += 1 + r2 = self.random.randrange(0, len(suitable_stacks)) + if r1 == r2: + continue if (r1, r2) not in old_pairs and (r2, r1) not in old_pairs: old_pairs.append((r1, r2)) break - # select two suitable stacks s1 = suitable_stacks[r1] s2 = suitable_stacks[r2] # check if s1 don't block s2 @@ -739,6 +740,8 @@ class AbstractMahjonggGame(Game): while True: ret = create_solvable(cards[:], new_cards) + if DEBUG: + print 'create_solvable time:', time.time() - start_time if ret: ret.reverse() return ret @@ -788,9 +791,13 @@ a solvable configuration.'''), bitmap='warning') self.leaveState(old_state) ##self.finishMove() - self.moves.current = [] # hack + # hack + am = self.moves.current[0] + am.undo(self) # restore random + self.moves.current = [] return + self.stats.shuffle_moves += 1 # move new_cards to talon for c in new_cards: for r in rows: