Skip to content

Commit

Permalink
Solve issues with folds and all-ins with more than 2 players
Browse files Browse the repository at this point in the history
Former-commit-id: d222b9b
  • Loading branch information
aypee19 committed Jan 12, 2021
1 parent bd6316a commit f07b76b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion rlcard/games/nolimitholdem/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def __init__(self, num_players, init_raise_amount, dealer, np_random):
# If every player agree to not raise, the round is overr
self.not_raise_num = 0

# Count players that are not playing anymore (folded or all-in)
self.not_playing_num = 0

# Raised amount for each player
self.raised = [0 for _ in range(self.num_players)]

Expand Down Expand Up @@ -110,6 +113,12 @@ def proceed_round(self, players, action):

self.game_pointer = (self.game_pointer + 1) % self.num_players

if player.status == PlayerStatus.ALLIN:
self.not_playing_num += 1
self.not_raise_num -= 1 # Because already counted in not_playing_num
if player.status == PlayerStatus.FOLDED:
self.not_playing_num += 1

# Skip the folded players
while players[self.game_pointer].status == PlayerStatus.FOLDED:
self.game_pointer = (self.game_pointer + 1) % self.num_players
Expand Down Expand Up @@ -156,6 +165,6 @@ def is_over(self):
Returns:
(boolean): True if the current round is over
'''
if self.not_raise_num >= self.num_players:
if self.not_raise_num + self.not_playing_num >= self.num_players:
return True
return False
9 changes: 5 additions & 4 deletions tests/games/test_nolimitholdem_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_step_3_players(self):
game = Game(num_players=3)

# test check
game.init_game()
_, first_player_id = game.init_game()
self.assertEqual(Stage.PREFLOP, game.stage)
game.step(Action.CALL)
game.step(Action.CALL)
Expand All @@ -84,12 +84,13 @@ def test_step_3_players(self):
game.step(Action.CALL)

self.assertEqual(Stage.FLOP, game.stage)
self.assertEqual((first_player_id - 2) % 3, game.round.game_pointer)
game.step(Action.CHECK)
game.step(Action.CHECK)
game.step(Action.CHECK)
game.step(Action.RAISE_POT)
game.step(Action.CALL)

self.assertEqual(Stage.TURN, game.stage)
game.step(Action.CHECK)
self.assertEqual((first_player_id - 2) % 3, game.round.game_pointer)
game.step(Action.CHECK)
game.step(Action.CHECK)

Expand Down

0 comments on commit f07b76b

Please sign in to comment.