def initial_ranking(hand): rnk1 = Card.get_rank_int(max(hand)) # valor de la mano 1 col1 = Card.get_suit_int(max(hand)) # color / palo de la mano 1 rnk2 = Card.get_rank_int(min(hand)) col2 = Card.get_suit_int(min(hand)) if col1 == col2: return(init_rank.suited[rnk1][rnk2]) return(init_rank.unsuited[rnk1][rnk2])
def my_card_ranking(self): if not all([self.cards, self.board]): print "Cards: board:%s, mine:%s" % (self.board, self.cards) return -1 # worst cprint("My cards: %s, %s" % (self.board, self.cards), "cyan") return Card.get_card_suite(self.board, self.cards)
def my_card_ranking(self): if not all([self.cards, self.board]): print "Cards: board:%s, mine:%s" % (self.board, self.cards) return -1 # worst from holdem.card import Card print "My cards: %s, %s" % (self.board, self.cards) return Card.get_card_suite(self.board, self.cards)
def GetFullDeck(): if Deck._FULL_DECK: return list(Deck._FULL_DECK) # create the standard 52 card deck for rank in Card.STR_RANKS: for suit, val in Card.CHAR_SUIT_TO_INT_SUIT.items(): Deck._FULL_DECK.append(Card.new(rank + suit)) return list(Deck._FULL_DECK)
def game(nplayers, pretty_print = False): """ Parameters ---------- nplayers : int number of players in the simulated game. pretty_print : Boolean, optional It prints the game simulation. The default is False. Returns ------- initial_rank : list initial ranking positions of the drawn hands ranking : list global result ranking of each of the drawn hands. lower ranking means higher global hand (lowest rank is an imperial flush) """ deck = Deck() # Repartimos 2 cartas a cada jugador hands = [deck.draw(2) for _ in range(nplayers)] # Cada jugador decide si apuesta o no apuesta en base a su posicion y su mano inicial. initial_rank = [initial_ranking(hand) for hand in hands] # ranking inicial p/2 jugadores, seg�n Michael Shackleford. # Se reparte las 5 cartas comunes. board = deck.draw(5) if pretty_print: [Card.print_pretty_cards(i) for i in hands] # imprime la mano de cada jugador Card.print_pretty_cards(board) # imprime tablero evaluator.hand_summary(board, hands) # imprime ganador # Se calcula el ranking de cadfloat64a mano. ranking = [evaluator.evaluate(hand, board) for hand in hands] return([initial_rank, ranking])
def _extract_features(records): # "Deal", "Flop", "Turn", "River": 0, 1, 2, 3 privateCards = [ Card(card).serial for card in records["privateCards"] ] deal_round = [ round_seq, raiseCount[0], betCount[0], privateCards[0], privateCards[1], 0, 0, 0, 0, 0, # public card 0, # card ranking ] #+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram flop_round = [round_seq, raiseCount[1], betCount[1], privateCards[0], privateCards[1], publicCards[0], publicCards[1], publicCards[2], 0, 0, Card.get_card_suite(table_info["publicCards"][0:3], records["privateCards"]) ] \ if round_seq >= 1 else \ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]# + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram #+ holdem_cal(records["privateCards"], table_info["publicCards"][0:3])[0] \ turn_round = [round_seq, raiseCount[2], betCount[2], privateCards[0], privateCards[1], publicCards[0], publicCards[1], publicCards[2], publicCards[3], 0, Card.get_card_suite(table_info["publicCards"][0:4], records["privateCards"]), ] \ if round_seq >= 2 else \ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]# + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram #+ holdem_cal(records["privateCards"], table_info["publicCards"][0:4])[0] \ river_round = [round_seq, raiseCount[3], betCount[3], privateCards[0], privateCards[1], publicCards[0], publicCards[1], publicCards[2], publicCards[3], publicCards[4], Card.get_card_suite(table_info["publicCards"][0:5], records["privateCards"]), ] \ if round_seq == 3 else \ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]# + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram #+ holdem_cal(records["privateCards"], table_info["publicCards"][0:5])[0] \ return [deal_round, flop_round, turn_round, river_round]
def get_features(self, table_info, round_seq): ############################################ # roundName, raiseCount, betCount,privateCards, publicCards, evaluate, histogram # 0 , 1 , 2 , 1, 23 , 1, 2, 4, 0,0, 7624, TBD # 0.0, 0.0, 0.9130434782608695, 0.0, 0.0, 0.0, 0.08695652173913043, 0.0, 0.0, 0.0, 1, 11, 22, 33, 44, 55 ############## ###### card Histogram # High Card : 0.0 # Pair : 0.0 # Two Pair : 0.913043478261 # Three of a Kind : 0.0 # Straight : 0.0 # Flush : 0.0 # Full House : 0.0869565217391 # Four of a Kind : 0.0 # Straight Flush : 0.0 # Royal Flush : 0.0 ####################### #numPlayers = table_info["numPlayers"] if not table_info: return None raiseCount = table_info["raiseCount"] betCount = table_info["betCount"] publicCards = [Card(card).serial for card in table_info["publicCards"]] def _extract_features(records): # "Deal", "Flop", "Turn", "River": 0, 1, 2, 3 privateCards = [ Card(card).serial for card in records["privateCards"] ] deal_round = [ round_seq, raiseCount[0], betCount[0], privateCards[0], privateCards[1], 0, 0, 0, 0, 0, # public card 0, # card ranking ] #+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram flop_round = [round_seq, raiseCount[1], betCount[1], privateCards[0], privateCards[1], publicCards[0], publicCards[1], publicCards[2], 0, 0, Card.get_card_suite(table_info["publicCards"][0:3], records["privateCards"]) ] \ if round_seq >= 1 else \ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]# + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram #+ holdem_cal(records["privateCards"], table_info["publicCards"][0:3])[0] \ turn_round = [round_seq, raiseCount[2], betCount[2], privateCards[0], privateCards[1], publicCards[0], publicCards[1], publicCards[2], publicCards[3], 0, Card.get_card_suite(table_info["publicCards"][0:4], records["privateCards"]), ] \ if round_seq >= 2 else \ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]# + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram #+ holdem_cal(records["privateCards"], table_info["publicCards"][0:4])[0] \ river_round = [round_seq, raiseCount[3], betCount[3], privateCards[0], privateCards[1], publicCards[0], publicCards[1], publicCards[2], publicCards[3], publicCards[4], Card.get_card_suite(table_info["publicCards"][0:5], records["privateCards"]), ] \ if round_seq == 3 else \ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]# + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # card histogram #+ holdem_cal(records["privateCards"], table_info["publicCards"][0:5])[0] \ return [deal_round, flop_round, turn_round, river_round] results = [] # not found the winner in this game, it is possible the winner has no private cards if "winner" not in table_info: return results # add winer into the 1st results.append( _extract_features(self.player_records[table_info["winner"]][ table_info["tableNo"]])) # add the loser for player in table_info["player"]: if player == table_info["winner"]: continue elif player not in self.player_records: continue player_rec = self.player_records[player] if table_info["tableNo"] not in player_rec: continue results.append( _extract_features( self.player_records[player][table_info["tableNo"]])) return results
def __str__(self): return Card.print_pretty_cards(self.cards)
def is_almost_flush(self): return Card.is_almost_flush(self.board, self.cards)
def is_almost_straight(self): return Card.is_almost_straight(self.board, self.cards)
def board_ranking(self): if not len(self.board) == 5: return 0 return Card.get_card_suite(self.board[:3], self.board[3:])