Skip to content

Commit

Permalink
add chips config for NLholdem
Browse files Browse the repository at this point in the history
Former-commit-id: 9c34aaa
  • Loading branch information
ruzhwei committed Jan 12, 2021
1 parent 8fea33a commit d280913
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rlcard/envs/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, config):
self.action_recorder = []

# Game specific configurations
# Currently only support blackjack
# Currently only support blackjack、limit-holdem、no-limit-holdem
# TODO support game configurations for all the games
supported_envs = ['blackjack', 'limit-holdem', 'no-limit-holdem']
if self.name in supported_envs:
Expand Down
1 change: 1 addition & 0 deletions rlcard/envs/nolimitholdem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

DEFAULT_GAME_CONFIG = {
'game_player_num': 2,
'chips_for_each': [100]*2,
}

class NolimitholdemEnv(Env):
Expand Down
10 changes: 7 additions & 3 deletions rlcard/games/nolimitholdem/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ def __init__(self, allow_step_back=False, num_players=2):

# config players
self.num_players = num_players
self.init_chips = 100
self.init_chips = [100]*2

def configure(self, game_config):
''' Specifiy some game specific parameters, such as player number
'''
self.num_players = game_config['game_player_num']
self.init_chips = game_config['chips_for_each']

def init_game(self):
''' Initialilze the game of Limit Texas Hold'em
Expand All @@ -56,8 +57,8 @@ def init_game(self):
# Initilize a dealer that can deal cards
self.dealer = Dealer(self.np_random)

# Initilize two players to play the game
self.players = [Player(i, self.init_chips, self.np_random) for i in range(self.num_players)]
# Initilize players to play the game
self.players = [Player(i, self.init_chips[i], self.np_random) for i in range(self.num_players)]

# Initialize a judger class which will decide who wins in the end
self.judger = Judger(self.np_random)
Expand Down Expand Up @@ -213,6 +214,9 @@ def get_player_num(self):
'''
return self.num_players

def get_players(self):
return self.players

def get_payoffs(self):
''' Return the payoffs of the game
Expand Down
9 changes: 9 additions & 0 deletions tests/envs/test_nolimitholdem_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,14 @@ def test_multiplayers(self):
player_num = env.game.get_player_num()
self.assertEqual(player_num, 5)

def test_config_chips(self):
env = rlcard.make('no-limit-holdem', config={'game_player_num':5, 'chips_for_each':[100, 200, 400, 600, 900]})
env.game.init_game()
players = env.game.players
chips = []
for i in range(5):
chips.append(players[i].remained_chips + players[i].in_chips)
self.assertEqual(chips, [100, 200, 400, 600, 900])

if __name__ == '__main__':
unittest.main()

0 comments on commit d280913

Please sign in to comment.