def launchPlayNowApp(self, action): self.playNowApp = PlayNowApp() self.pokerTable = PokerTable() if (action=="open") : self.playNowApp.open() self.msg.text += "Play now app opened" elif action=="playNowLogin": self.playNowApp.login() self.msg.text += "Logged into PlayNow app" elif action=="texasHoldem": self.playNowApp.go_to_texas_holdem() elif action=="practiceTable": self.playNowApp.go_to_practice_tables() self.minimizeFrame(False) elif action=="joinTable": self.pokerTable.join_table() elif action=="highlightObservations": self.pokerTable.highlight_regions_all() elif action=="leaveTable": self.pokerTable.leave_table() elif action=="playNowClose": self.playNowApp.close() else: self.minimizeFrame(True) self.playNowApp.open() self.msg.text += "Play now app opened" self.playNowApp.login() self.msg.text += "Logged into PlayNow app" self.playNowApp.go_to_texas_holdem() self.playNowApp.go_to_practice_tables() self.minimizeFrame(False) self.pokerTable.join_table()
def __init__( self, table=None, # Table shuff=True, deck=None, gameName=None, nplay=None, # Default from game minBet=None, pot=None, direction=None, # Direction: 1 - high, 2 - low, 3 - high-low lowFlushStrait=None): ''' Constructor Deal ''' """ The game "rules the show" and can specify almost all the playing conditions """ if gameName == None: gameName = table.game.name self.gameName = gameName game = self.game = Games[gameName] game.setPokerSettings() # Setup basic settings """ deal the deck """ if deck == None: deck = PokerDeck() self.deck = deck if table is None: table = PokerTable(deck=deck) self.table = table if direction == None: direction = game.direction self.direction = direction if lowFlushStrait == None: lowFlushStrait = game.direction self.lowFlushStrait = lowFlushStrait if nplay == None: nplay = len(game.plays) self.nPlay = nplay self.playNum = 0 if minBet == None: minBet = 1 if pot == None: pot = 0 self.pot = pot self.players = [] # Players participating # Join each player to deal for player in table.players: self.joinDeal(player) """ place the board cards """ self.board = PokerBoard(self, self.deck, gameName=self.gameName) """ Deal out cards, one to player, until per-player number is reached """ for i in range(self.game.nPlayerCards): pos = i + 1 for player in table.players: cards = self.deck.draw(1) if len(cards) == 1: card = cards[0] if tR("deal"): print("draw:{}".format(card)) if card is not None: player.addCard(card) else: print("draw:{} None".format(card)) raise ValueError("drawing None is not expected") else: print("draw:{} of {} cards".format(card, len(cards))) raise ValueError("len(cards) is not 1:{}".format( len(cards)))
""" Stanalone test / exercise: """ if __name__ == "__main__": from PyTrace import PyTrace from PokerTable import PokerTable trace_str = "" ###trace_str = "prob" PyTrace(flagStr=trace_str) testgame = "44" testgame = "toy" if testgame == "toy": deal = PokerDeal(gameName=testgame) elif testgame == "toy2": testgame = "toy" table = PokerTable(nPlayer=2) deal = PokerDeal(table, gameName=testgame) else: deckMain = PokerDeck() # SHORT to reduce complexity table = PokerTable(deck=deckMain) deal = PokerDeal(table, gameName=testgame) poker_hands_high = PokerHands(deal, direction=HIGH) poker_hands_low = PokerHands(deal, direction=LOW, lowFlushStrait=True) player = deal.getPlayer(1) while deal.hasMorePlays(): deal.play() poker_hands_high.displaySimpleHands(player=player, short=False, full=True, nHand=1)
class PokerApp: def __init__(self): self._frame = JFrame("PokerApp", size=(600,400), defaultCloseOperation=JFrame.EXIT_ON_CLOSE) def minimizeFrame(self, true_false): if true_false == True: self._frame.state = JFrame.ICONIFIED else: self._frame.MAXIMIZED_BOTH # self._frame.state = JFrame.NORMAL def launchPlayNowApp(self, action): self.playNowApp = PlayNowApp() self.pokerTable = PokerTable() if (action=="open") : self.playNowApp.open() self.msg.text += "Play now app opened" elif action=="playNowLogin": self.playNowApp.login() self.msg.text += "Logged into PlayNow app" elif action=="texasHoldem": self.playNowApp.go_to_texas_holdem() elif action=="practiceTable": self.playNowApp.go_to_practice_tables() self.minimizeFrame(False) elif action=="joinTable": self.pokerTable.join_table() elif action=="highlightObservations": self.pokerTable.highlight_regions_all() elif action=="leaveTable": self.pokerTable.leave_table() elif action=="playNowClose": self.playNowApp.close() else: self.minimizeFrame(True) self.playNowApp.open() self.msg.text += "Play now app opened" self.playNowApp.login() self.msg.text += "Logged into PlayNow app" self.playNowApp.go_to_texas_holdem() self.playNowApp.go_to_practice_tables() self.minimizeFrame(False) self.pokerTable.join_table() def getScreenSize(self): return Toolkit.getDefaultToolkit().getScreenSize() def setFrameLocation(self, side): screenSize = self.getScreenSize() if side == 'Right': self._frame.setSize( int(screenSize.width * 0.31), int(screenSize.height * 0.95) ) self._frame.setLocation( int(screenSize.width * 0.69), 0 ) def playNowApp_startThread(self, action): self.setFrameLocation("Right") Thread(name="AppLaunch", target=self.launchPlayNowApp, args=(action,) ).start() def setMenuBar(self): menuBar = JMenuBar() menuApp = JMenu("Apps") menuApp.setMnemonic('A') menuSettings = JMenu("Settings") menuSettings.setMnemonic('S') #set submenus menuPlayNow = JMenu("PlayNow" ) menuPlayNowOpen = JMenuItem("Open", actionPerformed = (lambda x, param="open": self.playNowApp_startThread(param)) ) menuPlayNow.add(menuPlayNowOpen) menuPlayNowLogin = JMenuItem("Login", actionPerformed = lambda x, action="playNowLogin": self.playNowApp_startThread(action) ) menuPlayNow.add(menuPlayNowLogin) menuPlayNowClose = JMenuItem("Close", actionPerformed = lambda x, action="playNowClose": self.playNowApp_startThread(action) ) menuPlayNow.add(menuPlayNowClose) menuPokerTable = JMenu("PokerTable") menuPokerTableJoin = JMenuItem("Find Practice Table", actionPerformed = lambda x, action="practiceTable": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableJoin) menuPokerTableJoin = JMenuItem("Join Table", actionPerformed = lambda x, action="joinTable": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableJoin) menuPokerTableAddChips = JMenuItem("Add Chips", actionPerformed = lambda x, action="addChips": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableAddChips) menuPokerTableSitOut = JMenuItem("Sit Out", actionPerformed = lambda x, action="sitOut": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableSitOut) menuPokerTableLeaveTable = JMenuItem("Leave Table", actionPerformed = lambda x, action="leaveTable": self.playNowApp_startThread(action) ) menuPokerTable.add(menuPokerTableLeaveTable) menuPokerAppExit = JMenuItem("Exit") menuApp.add(menuPlayNow) menuApp.add(menuPokerTable) menuApp.addSeparator() menuApp.add(menuPokerAppExit) menuBar.add(menuApp) menuBar.add(menuSettings) self._frame.setJMenuBar(menuBar) def startGui(self): # self.gridPanel = JPanel(GridLayout(self.numRows, self.numCols)) # self.cellButtons = self._doForAllCells(self._createCellButton) # self.grid = self._doForAllCells(lambda r,c: False) # frame.add(self.gridPanel) # buttonPanel = JPanel(FlowLayout()) # stepButton = JButton("Step", actionPerformed=self._step) # runButton = JToggleButton("Run", actionPerformed=self._run) # buttonPanel.add(stepButton) # buttonPanel.add(runButton) # frame.add(buttonPanel, SOUTH) # frame.pack() # frame.locationRelativeTo = None self.setMenuBar() image_path = "D:\\wamp\\www\\holdem\\src\\poker\\th\\images\\As.png" myPicture = ImageIcon(image_path) myPictureLabel = JLabel("Pocket: ", myPicture, JLabel.LEFT) cardPanel = JPanel() cardPanel.setLayout(None) cardPanel.add(myPictureLabel) myPictureLabel.setBounds(10,10,36,52); self._frame.getContentPane().add(cardPanel) self.msg=JLabel("Hello") self._frame.add(self.msg, NORTH) self._frame.locationRelativeTo = None self._frame.visible = True