def test_rank2int(self): self.assertEqual(rank2int('A'), 14) self.assertEqual(rank2int(''), -1) self.assertEqual(rank2int('3'), 3) self.assertEqual(rank2int('T'), 10) self.assertEqual(rank2int('J'), 11) self.assertEqual(rank2int('Q'), 12) self.assertEqual(rank2int('1000'), None) self.assertEqual(rank2int('abc123'), None) self.assertEqual(rank2int('K'), 13)
def compare_hands(self, selfcards, oppocards, publiccards): from rlcard.utils.utils import rank2int # Judge who are the winners winners = [0, 0] if sum(winners) < 1: if selfcards[0][1] == oppocards[0][1]: winners = [1, 1] if sum(winners) < 1: if selfcards[0][1] == publiccards[0][1]: winners[0] = 1 elif oppocards[0][1] == publiccards[0][1]: winners[1] = 1 if sum(winners) < 1: winners = [1, 0] if rank2int(selfcards[0][1]) > rank2int(oppocards[0][1]) else [0, 1] return winners
def judge_game(players, public_cards): ''' Judge the winner of the game. Args: players (list): The list of players who play the game public_card (object): The public card that seen by all the players Returns: (list): Each entry of the list corresponds to one entry of the ''' # Judge who are the winners winners = [0, 0] public_card = public_cards[0] if public_cards != [] else None # If one player folds, the other player is the winner for idx, player in enumerate(players): if player.status == 'folded': winners[(idx + 1) % 2] = 1 break if sum(winners) < 1: if players[0].hand[0].rank == players[1].hand[0].rank: winners = [1, 1] if sum(winners) < 1: for idx, player in enumerate(players): if player.hand[0].rank == public_card.rank: winners[idx] = 1 break if sum(winners) < 1: winners = [1, 0] if rank2int(players[0].hand[0].rank) > rank2int( players[1].hand[0].rank) else [0, 1] # Compute the total chips total = 0 for p in players: total += p.in_chips each_win = float(total) / sum(winners) payoffs = [] for i, _ in enumerate(players): if winners[i] == 1: payoffs.append(each_win - players[i].in_chips) else: payoffs.append(float(-players[i].in_chips)) return payoffs
def judge_game(players, public_card): ''' Judge the winner of the game. Args: players (list): The list of players who play the game public_card (object): The public card that seen by all the players Returns: (list): Each entry of the list corresponds to one entry of the ''' # Judge who are the winners winners = [0] * len(players) fold_count = 0 ranks = [] # If every player folds except one, the alive player is the winner for idx, player in enumerate(players): ranks.append(rank2int(player.hand.rank)) if player.status == 'folded': fold_count += 1 elif player.status == 'alive': alive_idx = idx if fold_count == (len(players) - 1): winners[alive_idx] = 1 # If any of the players matches the public card wins if sum(winners) < 1: for idx, player in enumerate(players): if player.hand.rank == public_card.rank: winners[idx] = 1 break # If non of the above conditions, the winner player is the one with the highest card rank if sum(winners) < 1: max_rank = max(ranks) max_index = [i for i, j in enumerate(ranks) if j == max_rank] for idx in max_index: winners[idx] = 1 # Compute the total chips total = 0 for p in players: total += p.in_chips each_win = float(total) / sum(winners) payoffs = [] for i, _ in enumerate(players): if winners[i] == 1: payoffs.append(each_win - players[i].in_chips) else: payoffs.append(float(-players[i].in_chips)) return payoffs
def judge_game(players): ''' Judge the winner of the game. Args: players (list): The list of players who play the game Returns: (list): Each entry of the list corresponds to one entry of players ''' # Judge who are the winners winners = [0, 0] # If one player folds, the other player is the winner for idx, player in enumerate(players): if player.status == 'folded': winners[(idx + 1) % 2] = 1 break if sum(winners) < 1: p0_rank = rank2int(players[0].hand.rank) p1_rank = rank2int(players[1].hand.rank) winners = [1, 0] if p0_rank > p1_rank else [0, 1] # Compute the total chips total = 0 for p in players: total += p.in_chips each_win = float(total) / sum(winners) payoffs = [] for i, _ in enumerate(players): if winners[i] == 1: payoffs.append(each_win - players[i].in_chips) else: payoffs.append(float(-players[i].in_chips)) return payoffs