def importFile(solver, fh, s_game, self): s_game.endGame() s_game.random = constructRandom('Custom') s_game.newGame(shuffle=True, random=constructRandom('Custom'), dealer=lambda: solver.importFileHelper(fh, s_game)) s_game.random = constructRandom('Custom')
def importFile(solver, fh, s_game, self): s_game.endGame() s_game.random = constructRandom('Custom') s_game.newGame( shuffle=True, random=constructRandom('Custom'), dealer=lambda: solver.importFileHelper(fh, s_game)) s_game.random = constructRandom('Custom')
def shlomif_main(args): plan(3) rand = constructRandom('24') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D ''', 'Deal 24', ); rand = constructRandom('ms123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''QD TC AS KC AH KH 6H 6D TD 8D TH 7C 2H 9C AC AD 5C 5H 8C 9H 9D JS 8S 4D 4C 2S 7D 3C 7H 7S 9S 2C JC 5S 5D 3S 3D 3H KD JH 6C QS 4S 2D KS TS JD QH 6S 4H QC 8H ''', 'Microsoft Deal 123456', ); rand = constructRandom('123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() ok (got_s == '''3D 6C AS TS QC 8D 4D 2D TC 4H JD TD 2H 5C 2C 8S AH KD KH 5S 7C 9C 8C QH 3C 5D 9S QD AC 9D 7H 6D KS JH 6H TH 8H QS 7D JC 4C 2S 3S 6S 5H 3H KC JS 9H 4S 7S AD ''', 'PySolFC deal No. 123456', );
def _mNewGameBySeed(self, seed, origin): try: random = constructRandom(seed) if random is None: return id = self.game.id if not self.app.getGameInfo(id): raise ValueError except (ValueError, TypeError), ex: d = MfxMessageDialog(self.top, title=_("Invalid game number"), text=_("Invalid game number\n") + str(seed), bitmap="error") return
def _mNewGameBySeed(self, seed, origin): try: random = constructRandom(seed) if random is None: return id = self.game.id if not self.app.getGameInfo(id): raise ValueError except (ValueError, TypeError): MfxMessageDialog(self.top, title=_("Invalid game number"), text=_("Invalid game number\n") + str(seed), bitmap="error") return f = self.game.nextGameFlags(id, random) if f & 17 == 0: return random.origin = origin if f & 15 == 0: self.game.endGame() self.game.newGame(random=random) else: self.game.endGame() self.game.quitGame(id, random=random)
def test_main(self): def test_24(blurb): game = Game("freecell", 24, RandomBase.DEALS_PYSOLFC) got_s = game.calc_layout_string(ren) self.assertEqual( got_s, '''4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D ''', blurb) # TEST test_24('Deal 24') game = Game("freecell", 123456, RandomBase.DEALS_MS) # TEST got_s = game.calc_layout_string(ren) self.assertEqual( got_s, '''QD TC AS KC AH KH 6H 6D TD 8D TH 7C 2H 9C AC AD 5C 5H 8C 9H 9D JS 8S 4D 4C 2S 7D 3C 7H 7S 9S 2C JC 5S 5D 3S 3D 3H KD JH 6C QS 4S 2D KS TS JD QH 6S 4H QC 8H ''', 'Microsoft Deal 123456') game = Game("freecell", 123456, True) # TEST self._cmp_board( game.calc_layout_string(ren), '''3D 6C AS TS QC 8D 4D 2D TC 4H JD TD 2H 5C 2C 8S AH KD KH 5S 7C 9C 8C QH 3C 5D 9S QD AC 9D 7H 6D KS JH 6H TH 8H QS 7D JC 4C 2S 3S 6S 5H 3H KC JS 9H 4S 7S AD ''', 'PySolFC deal No. 123456') rand = constructRandom('ms3000000000') self.assertEqual(rand.getSeedAsStr(), 'ms3000000000') game = Game("freecell", 3000000000, RandomBase.DEALS_MS) # TEST self._cmp_board( game.calc_layout_string(ren), '''8D TS JS TD JH JD JC 4D QS TH AD 4S TC 3C 9H KH QH 4C 5C KD AS 9D 5D 8S 4H KS 6S 9S 6H 2S 7H 3D KC 2C 9C 7C QC 7S QD 7D 6C 3H 8H AC 6D 3S 8C AH 2H 5H 2D 5S ''', 'Microsoft Deal #3E9 - long seed.') rand = constructRandom('ms6000000000') game = Game("freecell", 6000000000, RandomBase.DEALS_MS) # TEST got_s = game.calc_layout_string(ren) self.assertEqual( got_s, '''2D 2C QS 8D KD 8C 4C 3D AH 2H 4H TS 6H QD 4D JS AD 6S JH JC JD KH 3H KS AS TC 5D AC TD 7C 9C 7H 3C 3S QH 9H 9D 5S 7S 6C 5C 5H 2S KC 9S 4S 6D QC 8S TH 7D 8H ''', 'Microsoft Deal #6E9 - extra long seed.') inp = 'ms12345678' got = random__int2str(random__str2int(inp)) # TEST self.assertEqual(got, inp, 'long2str ms roundtrip.') inp = '246007891097' got = random__int2str(random__str2int(inp)) # TEST self.assertEqual(got, inp, 'long2str PySolFC roundtrip.') proto_inp = '246007891097' inp = random__str2int(proto_inp) got = random__str2int(random__int2str(inp)) # TEST self.assertEqual(got, inp, 'str2long PySolFC roundtrip.') rand = constructRandom('ms100000') seed = rand.increaseSeed(rand.initial_seed) seed = rand.str(seed) # TEST self.assertEqual(seed, 'ms100001', 'increaseSeed for ms deals') rand = constructRandom(seed) game = Game("freecell", int(seed[2:]), RandomBase.DEALS_MS) # TEST self._cmp_board( game.calc_layout_string(ren), '''5S AH 4H TD 4S JD JS 3C 8C 4C AC JC AS QS 7C QH 2D QD 8S 9D AD KS 7S 5H 3H TS 3S 5D 9S 7H KC TH 8D 6S 5C KD 9H 2H 2S 6D 9C JH 8H 3D 4D QC KH 6H 6C TC 2C 7D ''', 'ms100001') seed = 24000024 rand = constructRandom(str(seed)) expected0 = rand.randint(0, 100) expected1 = rand.randint(0, 100) rand.reset() got0 = rand.randint(0, 100) got1 = rand.randint(0, 100) # TEST self.assertEqual( [ got0, got1, ], [ expected0, expected1, ], "same results after reset()", )
def test_main(self): rand = constructRandom('24') def test_24(blurb): game = Game("freecell", rand, True) got_s = game.print_layout() self.assertEqual(got_s, '''4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D ''', blurb) # TEST test_24('Deal 24') rand.reset() # TEST test_24('MS deal after reset.') rand = constructRandom('ms123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() self.assertEqual(got_s, '''QD TC AS KC AH KH 6H 6D TD 8D TH 7C 2H 9C AC AD 5C 5H 8C 9H 9D JS 8S 4D 4C 2S 7D 3C 7H 7S 9S 2C JC 5S 5D 3S 3D 3H KD JH 6C QS 4S 2D KS TS JD QH 6S 4H QC 8H ''', 'Microsoft Deal 123456') rand = constructRandom('123456') game = Game("freecell", rand, True) # TEST self._cmp_board(game.print_layout(), '''3D 6C AS TS QC 8D 4D 2D TC 4H JD TD 2H 5C 2C 8S AH KD KH 5S 7C 9C 8C QH 3C 5D 9S QD AC 9D 7H 6D KS JH 6H TH 8H QS 7D JC 4C 2S 3S 6S 5H 3H KC JS 9H 4S 7S AD ''', 'PySolFC deal No. 123456') rand = constructRandom('ms3000000000') game = Game("freecell", rand, True) # TEST self._cmp_board(game.print_layout(), '''8D TS JS TD JH JD JC 4D QS TH AD 4S TC 3C 9H KH QH 4C 5C KD AS 9D 5D 8S 4H KS 6S 9S 6H 2S 7H 3D KC 2C 9C 7C QC 7S QD 7D 6C 3H 8H AC 6D 3S 8C AH 2H 5H 2D 5S ''', 'Microsoft Deal #3E9 - long seed.') rand = constructRandom('ms6000000000') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() self.assertEqual(got_s, '''2D 2C QS 8D KD 8C 4C 3D AH 2H 4H TS 6H QD 4D JS AD 6S JH JC JD KH 3H KS AS TC 5D AC TD 7C 9C 7H 3C 3S QH 9H 9D 5S 7S 6C 5C 5H 2S KC 9S 4S 6D QC 8S TH 7D 8H ''', 'Microsoft Deal #6E9 - extra long seed.') inp = 'ms12345678' got = random__long2str(random__str2long(inp)) # TEST self.assertEqual(got, inp, 'long2str ms roundtrip.') inp = '246007891097' got = random__long2str(random__str2long(inp)) # TEST self.assertEqual(got, inp, 'long2str PySolFC roundtrip.') proto_inp = '246007891097' inp = random__str2long(proto_inp) got = random__str2long(random__long2str(inp)) # TEST self.assertEqual(got, inp, 'str2long PySolFC roundtrip.')
def test_main(self): rand = constructRandom('24') def test_24(blurb): game = Game("freecell", rand, True) got_s = game.print_layout() self.assertEqual( got_s, '''4C 2C 9C 8C QS 4S 2H 5H QH 3C AC 3H 4H QD QC 9S 6H 9H 3S KS 3D 5D 2S JC 5C JH 6D AS 2D KD TH TC TD 8D 7H JS KH TS KC 7C AH 5S 6S AD 8H JD 7S 6C 7D 4D 8S 9D ''', blurb) # TEST test_24('Deal 24') rand.reset() # TEST test_24('MS deal after reset.') rand = constructRandom('ms123456') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() self.assertEqual( got_s, '''QD TC AS KC AH KH 6H 6D TD 8D TH 7C 2H 9C AC AD 5C 5H 8C 9H 9D JS 8S 4D 4C 2S 7D 3C 7H 7S 9S 2C JC 5S 5D 3S 3D 3H KD JH 6C QS 4S 2D KS TS JD QH 6S 4H QC 8H ''', 'Microsoft Deal 123456') rand = constructRandom('123456') game = Game("freecell", rand, True) # TEST self._cmp_board( game.print_layout(), '''3D 6C AS TS QC 8D 4D 2D TC 4H JD TD 2H 5C 2C 8S AH KD KH 5S 7C 9C 8C QH 3C 5D 9S QD AC 9D 7H 6D KS JH 6H TH 8H QS 7D JC 4C 2S 3S 6S 5H 3H KC JS 9H 4S 7S AD ''', 'PySolFC deal No. 123456') rand = constructRandom('ms3000000000') game = Game("freecell", rand, True) # TEST self._cmp_board( game.print_layout(), '''8D TS JS TD JH JD JC 4D QS TH AD 4S TC 3C 9H KH QH 4C 5C KD AS 9D 5D 8S 4H KS 6S 9S 6H 2S 7H 3D KC 2C 9C 7C QC 7S QD 7D 6C 3H 8H AC 6D 3S 8C AH 2H 5H 2D 5S ''', 'Microsoft Deal #3E9 - long seed.') rand = constructRandom('ms6000000000') game = Game("freecell", rand, True) # TEST got_s = game.print_layout() self.assertEqual( got_s, '''2D 2C QS 8D KD 8C 4C 3D AH 2H 4H TS 6H QD 4D JS AD 6S JH JC JD KH 3H KS AS TC 5D AC TD 7C 9C 7H 3C 3S QH 9H 9D 5S 7S 6C 5C 5H 2S KC 9S 4S 6D QC 8S TH 7D 8H ''', 'Microsoft Deal #6E9 - extra long seed.') inp = 'ms12345678' got = random__long2str(random__str2long(inp)) # TEST self.assertEqual(got, inp, 'long2str ms roundtrip.') inp = '246007891097' got = random__long2str(random__str2long(inp)) # TEST self.assertEqual(got, inp, 'long2str PySolFC roundtrip.') proto_inp = '246007891097' inp = random__str2long(proto_inp) got = random__str2long(random__long2str(inp)) # TEST self.assertEqual(got, inp, 'str2long PySolFC roundtrip.')
def mainproc(self): # copy startup options self.startup_opt = self.opt.copy() # try to load statistics try: self.loadStatistics() except Exception: traceback.print_exc() pass # startup information if self.getGameClass(self.opt.last_gameid): self.nextgame.id = self.opt.last_gameid # load a holded or saved game tmpgame = self.constructGame(self.gdb.getGamesIdSortedByName()[0]) self._load_held_or_saved_game(tmpgame) if not self.nextgame.loadedgame: if self.commandline.loadgame: try: self.nextgame.loadedgame = tmpgame._loadGame( self.commandline.loadgame, self) self.nextgame.loadedgame.gstats.holded = 0 except Exception: traceback.print_exc() self.nextgame.loadedgame = None elif self.commandline.game is not None: gameid = self.gdb.getGameByName(self.commandline.game) if gameid is None: print_err( _("can't find game: %(game)s") % {'game': self.commandline.game}) sys.exit(-1) else: self.nextgame.id = gameid deal = self.commandline.deal self.nextgame.random = \ None if deal is None else constructRandom(deal) elif self.commandline.gameid is not None: self.nextgame.id, self.nextgame.random = \ self.commandline.gameid, None self.opt.game_holded = 0 tmpgame.destruct() destruct(tmpgame) tmpgame = None # # widgets # # create the menubar if self.intro.progress: self.intro.progress.update(step=1) self.menubar = PysolMenubar(self, self.top, progress=self.intro.progress) # create the statusbar(s) self.statusbar = PysolStatusbar(self.top) self.statusbar.show(self.opt.statusbar) self.statusbar.config('gamenumber', self.opt.statusbar_game_number) self.statusbar.config('stuck', self.opt.statusbar_stuck) self.helpbar = HelpStatusbar(self.top) self.helpbar.show(self.opt.helpbar) # create the canvas self.scrolled_canvas = MfxScrolledCanvas(self.top, propagate=True) self.canvas = self.scrolled_canvas.canvas padx, pady = TkSettings.canvas_padding self.scrolled_canvas.grid(row=1, column=1, sticky='nsew', padx=padx, pady=pady) self.top.grid_columnconfigure(1, weight=1) self.top.grid_rowconfigure(1, weight=1) self.setTile(self.tabletile_index, force=True) # create the toolbar dirname = self.getToolbarImagesDir() self.toolbar = PysolToolbar(self.top, self.menubar, dir=dirname, size=self.opt.toolbar_size, relief=self.opt.toolbar_relief, compound=self.opt.toolbar_compound) self.toolbar.show(self.opt.toolbar) if TOOLKIT == 'tk': for w, v in self.opt.toolbar_vars.items(): self.toolbar.config(w, v) # if self.intro.progress: self.intro.progress.update(step=1) # if TOOLKIT == 'kivy': self.gproc = self.gameproc() self.gproc.send(None) return self._main_loop()
def mainproc(self): # copy startup options self.startup_opt = self.opt.copy() # try to load statistics try: self.loadStatistics() except Exception: traceback.print_exc() pass # startup information if self.getGameClass(self.opt.last_gameid): self.nextgame.id = self.opt.last_gameid # load a holded or saved game id = self.gdb.getGamesIdSortedByName()[0] tmpgame = self.constructGame(id) if self.opt.game_holded > 0 and not self.nextgame.loadedgame: game = None try: game = tmpgame._loadGame(self.fn.holdgame, self) except Exception: traceback.print_exc() game = None if game: if game.id == self.opt.game_holded and game.gstats.holded: game.gstats.loaded = game.gstats.loaded - 1 game.gstats.holded = 0 self.nextgame.loadedgame = game else: # not a holded game game.destruct() destruct(game) game = None if not self.nextgame.loadedgame: if self.commandline.loadgame: try: self.nextgame.loadedgame = tmpgame._loadGame( self.commandline.loadgame, self) self.nextgame.loadedgame.gstats.holded = 0 except Exception: traceback.print_exc() self.nextgame.loadedgame = None elif self.commandline.game is not None: gameid = self.gdb.getGameByName(self.commandline.game) if gameid is None: print_err(_("can't find game: ") + self.commandline.game) sys.exit(-1) else: self.nextgame.id = gameid deal = self.commandline.deal self.nextgame.random = \ None if deal is None else constructRandom(deal) elif self.commandline.gameid is not None: self.nextgame.id, self.nextgame.random = \ self.commandline.gameid, None self.opt.game_holded = 0 tmpgame.destruct() destruct(tmpgame) tmpgame = None # # widgets # # create the menubar if self.intro.progress: self.intro.progress.update(step=1) self.menubar = PysolMenubar(self, self.top, progress=self.intro.progress) # create the statusbar(s) self.statusbar = PysolStatusbar(self.top) self.statusbar.show(self.opt.statusbar) self.statusbar.config('gamenumber', self.opt.statusbar_game_number) self.statusbar.config('stuck', self.opt.statusbar_stuck) self.helpbar = HelpStatusbar(self.top) self.helpbar.show(self.opt.helpbar) # create the canvas self.scrolled_canvas = MfxScrolledCanvas(self.top, propagate=True) self.canvas = self.scrolled_canvas.canvas padx, pady = TkSettings.canvas_padding self.scrolled_canvas.grid(row=1, column=1, sticky='nsew', padx=padx, pady=pady) self.top.grid_columnconfigure(1, weight=1) self.top.grid_rowconfigure(1, weight=1) self.setTile(self.tabletile_index, force=True) # create the toolbar dir = self.getToolbarImagesDir() self.toolbar = PysolToolbar(self.top, self.menubar, dir=dir, size=self.opt.toolbar_size, relief=self.opt.toolbar_relief, compound=self.opt.toolbar_compound) self.toolbar.show(self.opt.toolbar) if TOOLKIT == 'tk': for w, v in self.opt.toolbar_vars.items(): self.toolbar.config(w, v) # if self.intro.progress: self.intro.progress.update(step=1) # if TOOLKIT == 'kivy': self.gproc = self.gameproc() self.gproc.send(None) try: # this is the mainloop while 1: assert self.cardset is not None id_, random = self.nextgame.id, self.nextgame.random self.nextgame.id, self.nextgame.random = 0, None try: if TOOLKIT == 'kivy': self.gproc.send((id_, random)) logging.info('App: sent for game to start') yield logging.info('App: game proc stopped') else: self.runGame(id_, random) except Exception: # try Klondike if current game fails if id_ == 2: raise # internal error? if DEBUG: raise traceback.print_exc() self.nextgame.id = 2 self.freeGame() continue if self.nextgame.holdgame: assert self.nextgame.id <= 0 try: self.game.gstats.holded = 1 self.game._saveGame(self.fn.holdgame) self.opt.game_holded = self.game.id except Exception: traceback.print_exc() pass self.wm_save_state() # save game geometry geom = (self.canvas.winfo_width(), self.canvas.winfo_height()) if self.opt.save_games_geometry and not self.opt.wm_maximized: self.opt.games_geometry[self.game.id] = geom self.opt.game_geometry = geom self.freeGame() # if self.nextgame.id <= 0: break # load new cardset if self.nextgame.cardset is not self.cardset: self.loadCardset(self.nextgame.cardset, id=self.nextgame.id, update=7 + 256) else: self.requestCompatibleCardsetType(self.nextgame.id) except Exception: traceback.print_exc() pass finally: # hide main window self.wm_withdraw() # destroy_help_html() destroy_find_card_dialog() destroy_solver_dialog() # update options self.opt.last_gameid = id_ # save options try: self.saveOptions() except Exception: traceback.print_exc() pass # save statistics try: self.saveStatistics() except Exception: traceback.print_exc() pass # shut down audio try: self.audio.destroy() except Exception: traceback.print_exc() pass if TOOLKIT == 'kivy': self.top.quit() while True: logging.info('App: mainloop end position') yield