Skip to content

Commit

Permalink
fix compare_hands_bug
Browse files Browse the repository at this point in the history
Former-commit-id: ada376f
  • Loading branch information
ruzhwei committed May 25, 2020
1 parent 6987226 commit dfdc0ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion rlcard/games/limitholdem/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import numpy as np

class Hand:
def __init__(self, all_cards):
Expand Down Expand Up @@ -458,13 +458,22 @@ def determine_winner(key_index, hands, all_players, potential_winner_index):
'''
count = 0
losers = []
winner = [1]*len(hands)
for _ in key_index:
index_winner = compare_ranks(_, hands)
for loser in losers:
index_winner.insert(loser, 0)
for _ in enumerate(winner):
if winner[_[0]] == 1:
winner[_[0]] = index_winner[_[0]]
if winner[_[0]] == 0:
if _[0] not in losers:
i = _[0]
i = i - np.sum(list(map(lambda x: x < i, losers)))
i = int(i)
del hands[i]
losers.append(_[0])
continue
if winner.count(1) == 1:
break
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/test_holdem_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def test_compare_hands(self):
self.assertEqual(winner, [0, 1])
winner = compare_hands( [['CK', 'SJ', 'H9', 'C7', 'C6', 'B3', 'C2'], ['CK', 'SJ', 'H9', 'C7', 'C6', 'B3', 'C2']])
self.assertEqual(winner, [1, 1])

winner = compare_hands([['C5', 'S9', 'S6', 'C2', 'CT', 'C7', 'H5'], ['S7', 'SJ', 'S6', 'C2', 'CT', 'C7', 'H5'], None, None, ['H7', 'DJ', 'S6', 'C2', 'CT', 'C7', 'H5'], None])
self.assertEqual(winner, [0, 1, 0, 0, 1, 0])
if __name__ == '__main__':
unittest.main()

0 comments on commit dfdc0ed

Please sign in to comment.