Skip to content

Commit

Permalink
hands list should not be edited
Browse files Browse the repository at this point in the history
  • Loading branch information
aypee19 committed Jan 13, 2021
1 parent fd68506 commit 813c67f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
6 changes: 2 additions & 4 deletions rlcard/games/limitholdem/judger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ def judge_game(self, players, hands):
(list): Each entry of the list corresponds to one entry of the
'''
# Convert the hands into card indexes
for i, hand in enumerate(hands):
if hands[i] is not None:
h = [card.get_index() for card in hand]
hands[i] = h
hands = [[card.get_index() for card in hand] if hand is not None else None
for hand in hands]

winners = compare_hands(hands)

Expand Down
27 changes: 14 additions & 13 deletions rlcard/games/limitholdem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,16 +554,16 @@ def compare_hands(hands):
else:
for _ in enumerate(hands):
if hands[_[0]] is not None:
hands[_[0]] = Hand(hands[_[0]])
hands[_[0]].evaluateHand()
hand_category.append(hands[_[0]].category)
hand = Hand(hands[_[0]])
hand.evaluateHand()
hand_category.append(hand.category)
elif hands[_[0]] is None:
hand_category.append(0)
else:
for i in enumerate(hands):
hands[i[0]] = Hand(hands[i[0]])
hands[i[0]].evaluateHand()
hand_category.append(hands[i[0]].category)
hand = Hand(hands[i[0]])
hand.evaluateHand()
hand_category.append(hand.category)
potential_winner_index = [i for i, j in enumerate(hand_category) if j == max(hand_category)]# potential winner are those with same max card_catagory

return final_compare(hands, potential_winner_index, all_players)
Expand Down Expand Up @@ -595,17 +595,18 @@ def final_compare(hands, potential_winner_index, all_players):
equal_hands = []
for _ in potential_winner_index:
equal_hands.append(hands[_])
if hands[potential_winner_index[0]].category == 8:
hand = Hand(hands[potential_winner_index[0]])
if hand.category == 8:
return determine_winner_four_of_a_kind(equal_hands, all_players, potential_winner_index)
if hands[potential_winner_index[0]].category == 7:
if hand.category == 7:
return determine_winner([2, 0], equal_hands, all_players, potential_winner_index)
if hands[potential_winner_index[0]].category == 4:
if hand.category == 4:
return determine_winner([2, 1, 0], equal_hands, all_players, potential_winner_index)
if hands[potential_winner_index[0]].category == 3:
if hand.category == 3:
return determine_winner([4, 2, 0], equal_hands, all_players, potential_winner_index)
if hands[potential_winner_index[0]].category == 2:
if hand.category == 2:
return determine_winner([4, 2, 1, 0], equal_hands, all_players, potential_winner_index)
if hands[potential_winner_index[0]].category == 1 or hands[potential_winner_index[0]].category == 6:
if hand.category == 1 or hand.category == 6:
return determine_winner([4, 3, 2, 1, 0], equal_hands, all_players, potential_winner_index)
if hands[potential_winner_index[0]].category in [5, 9]:
if hand.category in [5, 9]:
return determine_winner_straight(equal_hands, all_players, potential_winner_index)

0 comments on commit 813c67f

Please sign in to comment.