def raiseTo(gameId, playerTuple, raiseToChips): _, _, _, _, _, pot, betToMatch, handLog, _, _, _ = db.getGame(gameId) _, playerId, address, name, stack, _, _, _, _, amountPutInPot, _, amountPutInPotThisRound = playerTuple if betToMatch > raiseToChips: return False elif betToMatch == raiseToChips: call(gameId, playerTuple) return True else: chipsToPutIn = raiseToChips - amountPutInPotThisRound logStatement = handLog + "\r\n" + addToPot(gameId, playerId, chipsToPutIn, "raise") numberOfPlayers = db.numberOfPlayersInGame(gameId) for i in range(numberOfPlayers): _, _, _, _, _, _, isAllIn, folded, eliminated, _, isChecked, _ = db.getPlayer( gameId, i) if not bool(folded) and not bool(eliminated) and not bool(isAllIn): db.updatePlayer(gameId, i, "isChecked = 0") # Raiser is checked db.updatePlayer(gameId, playerId, "isChecked = 1") db.updateGame(gameId, "handLog = \"" + logStatement + "\"") return True
def fold(gameId, playerTuple): _, _, _, _, _, pot, betToMatch, handLog, _, _, _ = db.getGame(gameId) _, playerId, address, name, stack, _, _, _, _, amountPutInPot, _, amountPutInPotThisRound = playerTuple db.updatePlayer(gameId, playerId, "folded = 1") db.updateGame( gameId, "handLog = \"" + handLog + "\r\nPlayer " + name + " folds.\"")
def startHand(gameId): numberOfPlayers = db.numberOfPlayersInGame(gameId) _, _, _, dealer, _, _, _, _, handNo, smallBlind, blindIncrement = db.getGame( gameId) blindsIncreased = False if blindIncrement != 0: if (handNo + 1) % blindIncrement == 0: smallBlind *= 2 blindsIncreased = True handNo += 1 db.updateGame( gameId, "handNo = " + str(handNo) + ", smallBlind = " + str(smallBlind)) smallBlind = smallBlind bigBlind = smallBlind * 2 deck = pd.Deck() deck.shuffle() # Deal cards and set playes to not be folded for i in range(numberOfPlayers): _, _, _, _, _, _, _, _, eliminated, _, _, _ = db.getPlayer(gameId, i) if eliminated == 0: # not eliminated hand = deck.deal(2) db.updatePlayer( gameId, i, "folded = 0, isChecked = 0, cards = \"" + str(hand[0]) + ":" + str(hand[1]) + "\", amountPutInPot = 0, amountPutInPotThisRound = 0") #dealer moves to left dealerPos, smallBlindPos, bigBlindPos, UTG = getNextStartingPlayers(gameId) handLog = "<b>Hand number " + str( handNo) + "</b>\r\n--------------------------------------\r\n" if blindsIncreased: handLog += "Blinds have increased to " + str( smallBlind) + " and " + str(bigBlind) + " chips.\r\n" handLog += "Dealer: " + db.getPlayer(gameId, dealerPos)[3] + "\r\n" #UpdateGame db.updateGame( gameId, "currentPlayer = " + str(UTG) + ", dealer = " + str(dealerPos) + ", board = '', phase = 0, pot = 0, betToMatch = " + str(bigBlind)) handLog += (player.addToPot(gameId, smallBlindPos, smallBlind, "sb") + "\r\n") handLog += (player.addToPot(gameId, bigBlindPos, bigBlind, "bb")) db.updateGame(gameId, "handLog = \"" + handLog + "\"") return UTG
def nextRound(gameId): _, board, currentPlayer, dealer, phase, pot, betToMatch, handLog, _, _, _ = db.getGame( gameId) # 0 - preflop # 1 - postflop # 2 - turn # 3 - river newPhase = phase + 1 numberOfPlayers = db.numberOfPlayersInGame(gameId) db.updateGame(gameId, "currentPlayer = " + str(dealer)) for i in range(numberOfPlayers): db.updatePlayer(gameId, i, "isChecked = 0, amountPutInPotThisRound = 0") db.updateGame(gameId, "phase = " + str(newPhase)) if not allAreAllIn(gameId): newCurrentPlayer = nextPlayer(gameId)[1] db.updateGame(gameId, "currentPlayer = " + str(newCurrentPlayer)) else: newCurrentPlayer = dealer db.updateGame(gameId, "currentPlayer = " + str(newCurrentPlayer)) deck = pd.Deck() deck.get_list( getAllCardsInPlay(gameId)) # remove all cards currently in play deck.shuffle() if newPhase == 1: newBoard = deck.deal(3) handLog = handLog + "\r\nFlop : " + cardToUnicode(str(newBoard[0])) + ", " \ + cardToUnicode(str(newBoard[1])) + ", " + cardToUnicode(str(newBoard[2])) db.updateGame( gameId, "board = \"" + str(newBoard[0]) + ":" + str(newBoard[1]) + ":" + str(newBoard[2]) + "\", betToMatch = 0, handLog = \"" + handLog + "\"") elif newPhase == 2 or newPhase == 3: newBoard = deck.deal(1) if newPhase == 2: handLog = handLog + "\r\nTurn : " + cardToUnicode(str(newBoard[0])) else: handLog = handLog + "\r\nRiver : " + cardToUnicode(str( newBoard[0])) db.updateGame( gameId, "board = \"" + board + ":" + str(newBoard[0]) + "\", betToMatch = 0, handLog = \"" + handLog + "\"") return newCurrentPlayer
def takeFromPot(gameId, player, chips): _, _, _, _, _, pot, _, _, _, _, _ = db.getGame(gameId) playerTuple = db.getPlayer(gameId, player) _, _, address, name, stack, _, _, _, _, amountPutInPot, _, amountPutInPotThisRound = playerTuple logStatement = "" logStatement = "Player " + name + " takes " + str( chips) + " chips from the pot." #update player stack db.updatePlayer(gameId, player, "stack = " + str(stack + chips)) #update pot db.updateGame(gameId, "pot = " + str(pot - chips)) return logStatement
def call(gameId, playerTuple): _, _, _, _, _, pot, betToMatch, handLog, _, _, _ = db.getGame(gameId) _, playerId, address, name, stack, _, _, _, _, amountPutInPot, _, amountPutInPotThisRound = playerTuple chipsToPutIn = betToMatch - amountPutInPotThisRound logStatement = "" if chipsToPutIn == 0: #Check logStatement = handLog + "\r\n" + addToPot(gameId, playerId, chipsToPutIn, "check") else: logStatement = handLog + "\r\n" + addToPot(gameId, playerId, chipsToPutIn, "call") #update player stack db.updatePlayer(gameId, playerId, "isChecked = 1") db.updateGame(gameId, "handLog = \"" + logStatement + "\"")
def addToPot(gameId, player, chips, action): _, _, _, _, _, pot, betToMatch, _, _, _, _ = db.getGame(gameId) playerTuple = db.getPlayer(gameId, player) _, _, address, name, stack, _, _, _, _, amountPutInPot, _, amountPutInPotThisRound = playerTuple logStatement = "" chipsPutIn = chips if stack <= chips: logStatement += "Player " + name + " is all in! " chipsPutIn = stack db.updatePlayer(gameId, player, "isAllIn = 1") logStatement += "Player " + name + " " if action == "sb": # small blind logStatement += "posted the small blind of " + str( chipsPutIn) + " chips." elif action == "bb": # big blind logStatement += "posted the big blind of " + str( chipsPutIn) + " chips." elif action == "call": logStatement += "calls " + str(chipsPutIn) + " chips." elif action == "raise": # check if amount put in actually makes it a raise (i.e. with all in less than btm) if chipsPutIn > betToMatch: db.updateGame( gameId, "betToMatch = " + str(amountPutInPotThisRound + chipsPutIn)) logStatement += "raises to " + str(amountPutInPotThisRound + chipsPutIn) + " chips." # otherwise betToMatch is not increased and no raise has been made elif action == "check": logStatement += "checks." #update player stack db.updatePlayer( gameId, player, "stack = " + str(stack - chipsPutIn) + ", amountPutInPot = " + str(amountPutInPot + chipsPutIn) + ", amountPutInPotThisRound = " + str(amountPutInPotThisRound + chipsPutIn)) #update pot db.updateGame(gameId, "pot = " + str(pot + chipsPutIn)) return logStatement
def showdown(gameId): _, _, currentPlayer, dealer, _, pot, betToMatch, handLog, _, _, _ = db.getGame( gameId) numberOfPlayers = db.numberOfPlayersInGame(gameId) board = db.getGame(gameId)[1] string = "" if board != "": string += "\r\n\r\nThe board was : " for card in board.split(":"): string += cardToUnicode(str(card)) + ", " string = string[:-2] # get rid of trailing comma db.updateGame(gameId, "handLog = \"" + db.getGame(gameId)[7] + string + "\"") isStillIn = [] for i in range(numberOfPlayers): _, _, _, _, stack, cards, isAllIn, folded, eliminated, amountPutInPot, isChecked, _ = db.getPlayer( gameId, i) if not bool(folded) and not bool(eliminated): isStillIn.append([i, amountPutInPot, stack, cards]) thisPot = pot while len(isStillIn) > 1: minimumAIP = min(i[1] for i in isStillIn) thisPot = minimumAIP * len(isStillIn) for i in isStillIn: i[1] -= minimumAIP winners = getWinners(gameId, isStillIn) for i in winners: handLog = db.getGame(gameId)[7] playerTuple = db.getPlayer(gameId, i[0]) logStatement = playerTuple[3] + " shows " + cardToUnicode( playerTuple[5].split(":")[0]) + ", " + cardToUnicode( playerTuple[5].split(":")[1]) logStatement += " (" + i[1] + ")" logStatement += "\r\n" + player.takeFromPot( gameId, i[0], thisPot // len(winners)) db.updateGame( gameId, "handLog = \"" + handLog + "\r\n" + logStatement + "\"") newIsStillIn = [] for i in isStillIn: if i[1] != 0: newIsStillIn.append(i) else: if i[0] not in (j[0] for j in winners): playerTuple = db.getPlayer(gameId, i[0]) logStatement = playerTuple[3] + " shows " + \ cardToUnicode(playerTuple[5].split(":")[0]) + ", " + \ cardToUnicode(playerTuple[5].split(":")[1]) handLog = db.getGame(gameId)[7] db.updateGame( gameId, "handLog = \"" + handLog + "\r\n" + logStatement + "\"") isStillIn = newIsStillIn pot -= thisPot thisPot = 0 if len(isStillIn) == 1: handLog = db.getGame(gameId)[7] logStatement = player.takeFromPot( gameId, isStillIn[0][0], isStillIn[0][1] + (pot - isStillIn[0][1])) db.updateGame(gameId, "handLog = \"" + handLog + "\r\n" + logStatement + "\"") for i in range(numberOfPlayers): _, _, _, _, stack, cards, isAllIn, folded, eliminated, amountPutInPot, isChecked, _ = db.getPlayer( gameId, i) if stack <= 0: db.updatePlayer(gameId, i, "eliminated = 1") db.updatePlayer(gameId, i, "isAllIn = 0")