rlcard.games.limitholdem¶
rlcard.games.limitholdem.dealer¶
rlcard.games.limitholdem.game¶
- class rlcard.games.limitholdem.game.LimitHoldemGame(allow_step_back=False, num_players=2)¶
Bases:
object
- configure(game_config)¶
Specify some game specific parameters, such as number of players
- get_legal_actions()¶
Return the legal actions for current player
- Returns:
A list of legal actions
- Return type:
(list)
- static get_num_actions()¶
Return the number of applicable actions
- Returns:
The number of actions. There are 4 actions (call, raise, check and fold)
- Return type:
(int)
- get_num_players()¶
Return the number of players in limit texas holdem
- Returns:
The number of players in the game
- Return type:
(int)
- get_payoffs()¶
Return the payoffs of the game
- Returns:
Each entry corresponds to the payoff of one player
- Return type:
(list)
- get_player_id()¶
Return the current player’s id
- Returns:
current player’s id
- Return type:
(int)
- get_state(player)¶
Return player’s state
- Parameters:
player (int) – player id
- Returns:
The state of the player
- Return type:
(dict)
- init_game()¶
Initialize the game of limit texas holdem
This version supports two-player limit texas holdem
- Returns:
Tuple containing:
(dict): The first state of the game (int): Current player’s id
- Return type:
(tuple)
- is_over()¶
Check if the game is over
- Returns:
True if the game is over
- Return type:
(boolean)
- step(action)¶
Get the next state
- Parameters:
action (str) – a specific action. (call, raise, fold, or check)
- Returns:
Tuple containing:
(dict): next player’s state (int): next player id
- Return type:
(tuple)
- step_back()¶
Return to the previous state of the game
- Returns:
True if the game steps back successfully
- Return type:
(bool)
rlcard.games.limitholdem.judger¶
- class rlcard.games.limitholdem.judger.LimitHoldemJudger(np_random)¶
Bases:
object
The Judger class for limit texas holdem
- judge_game(players, hands)¶
Judge the winner of the game.
- Parameters:
players (list) – The list of players who play the game
hands (list) – The list of hands that from the players
- Returns:
Each entry of the list corresponds to one entry of the
- Return type:
(list)
- split_pot_among_players(in_chips, winners)¶
Splits the next (side) pot among players. Function is called in loop by distribute_pots_among_players until all chips are allocated.
- Parameters:
in_chips (list) – List with number of chips bet not yet distributed for each player
winners (list) – List with 1 if the player is among winners else 0
- Returns:
Of how much chips each player get after this pot has been split and list of chips left to distribute
- Return type:
(list)
- split_pots_among_players(in_chips_initial, winners)¶
Splits main pot and side pots among players (to handle special case of all-in players).
- Parameters:
in_chips_initial (list) – List with number of chips bet for each player
winners (list) – List with 1 if the player is among winners else 0
- Returns:
List of how much chips each player get back after all pots have been split
- Return type:
(list)
rlcard.games.limitholdem.player¶
- class rlcard.games.limitholdem.player.LimitHoldemPlayer(player_id, np_random)¶
Bases:
object
- get_player_id()¶
- get_state(public_cards, all_chips, legal_actions)¶
Encode the state for the player
- Parameters:
public_cards (list) – A list of public cards that seen by all the players
all_chips (int) – The chips that all players have put in
- Returns:
The state of the player
- Return type:
(dict)
rlcard.games.limitholdem.round¶
Limit texas holdem round class implementation
- class rlcard.games.limitholdem.round.LimitHoldemRound(raise_amount, allowed_raise_num, num_players, np_random)¶
Bases:
object
Round can call other Classes’ functions to keep the game running
- get_legal_actions()¶
Obtain the legal actions for the current player
- Returns:
A list of legal actions
- Return type:
(list)
- is_over()¶
Check whether the round is over
- Returns:
True if the current round is over
- Return type:
(boolean)
- proceed_round(players, action)¶
Call other classes functions to keep one round running
- Parameters:
players (list) – The list of players that play the game
action (str) – An legal action taken by the player
- Returns:
The game_pointer that indicates the next player
- Return type:
(int)
- start_new_round(game_pointer, raised=None)¶
Start a new bidding round
- Parameters:
game_pointer (int) – The game_pointer that indicates the next player
raised (list) – Initialize the chips for each player
Note: For the first round of the game, we need to setup the big/small blind
rlcard.games.limitholdem.utils¶
- class rlcard.games.limitholdem.utils.Hand(all_cards)¶
Bases:
object
- evaluateHand()¶
Evaluate all the seven cards, get the best combination catagory And pick the best five cards (for comparing in case 2 hands have the same Category) .
- get_hand_five_cards()¶
Get the best five cards of a player :returns: the best five cards among the seven cards of a player :rtype: (list)
- rlcard.games.limitholdem.utils.compare_hands(hands)¶
Compare all palyer’s all seven cards :param hands: cards of those players with same highest hand_catagory. :type hands: list :param e.g. hands = [[‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CJ’: :param ‘SJ’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]]:
- Returns:
player1 wins [1, 0, 0]: player0 wins [1, 1, 1]: draw [1, 1, 0]: player1 and player0 draws
- Return type:
[0, 1, 0]
- if hands[0] == None:
return [0, 1]
- elif hands[1] == None:
return [1, 0]
- rlcard.games.limitholdem.utils.compare_ranks(position, hands, winner)¶
Compare cards in same position of plays’ five handcards :param position: the position of a card in a sorted handcard :type position: int :param hands: cards of those players. :type hands: list :param e.g. hands = [[‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CJ’: :param ‘SJ’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]]: :param winner: array of same length than hands with 1 if the hand is among winners and 0 among losers
- Returns:
new updated winner array [0, 1, 0]: player1 wins [1, 0, 0]: player0 wins [1, 1, 1]: draw [1, 1, 0]: player1 and player0 draws
- rlcard.games.limitholdem.utils.determine_winner(key_index, hands, all_players, potential_winner_index)¶
Find out who wins in the situation of having players with same highest hand_catagory :param key_index: the position of a card in a sorted handcard :type key_index: int :param hands: cards of those players with same highest hand_catagory. :type hands: list :param e.g. hands = [[‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CJ’: :param ‘SJ’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]]: :param all_players: all the players in this round, 0 for losing and 1 for winning or draw :type all_players: list :param potential_winner_index: the positions of those players with same highest hand_catagory in all_players :type potential_winner_index: list
- Returns:
player1 wins [1, 0, 0]: player0 wins [1, 1, 1]: draw [1, 1, 0]: player1 and player0 draws
- Return type:
[0, 1, 0]
- rlcard.games.limitholdem.utils.determine_winner_four_of_a_kind(hands, all_players, potential_winner_index)¶
Find out who wins in the situation of having players which all have a four of a kind :param key_index: the position of a card in a sorted handcard :type key_index: int :param hands: cards of those players with a four of a kind :type hands: list :param e.g. hands = [[‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CJ’: :param ‘SJ’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]]: :param all_players: all the players in this round, 0 for losing and 1 for winning or draw :type all_players: list :param potential_winner_index: the positions of those players with same highest hand_catagory in all_players :type potential_winner_index: list
- Returns:
player1 wins [1, 0, 0]: player0 wins [1, 1, 1]: draw [1, 1, 0]: player1 and player0 draws
- Return type:
[0, 1, 0]
- rlcard.games.limitholdem.utils.determine_winner_straight(hands, all_players, potential_winner_index)¶
Find out who wins in the situation of having players all having a straight or straight flush :param key_index: the position of a card in a sorted handcard :type key_index: int :param hands: cards of those players which all have a straight or straight flush :type hands: list :param all_players: all the players in this round, 0 for losing and 1 for winning or draw :type all_players: list :param potential_winner_index: the positions of those players with same highest hand_catagory in all_players :type potential_winner_index: list
- Returns:
player1 wins [1, 0, 0]: player0 wins [1, 1, 1]: draw [1, 1, 0]: player1 and player0 draws
- Return type:
[0, 1, 0]
- rlcard.games.limitholdem.utils.final_compare(hands, potential_winner_index, all_players)¶
Find out the winners from those who didn’t fold :param hands: cards of those players with same highest hand_catagory. :type hands: list :param e.g. hands = [[‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CJ’: :param ‘SJ’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]: :param [‘CT’: :param ‘ST’: :param ‘H9’: :param ‘B9’: :param ‘C2’: :param ‘C8’: :param ‘C7’]]: :param potential_winner_index: index of those with same max card_catagory in all_players :type potential_winner_index: list :param all_players: a list of all the player’s win/lose situation, 0 for lose and 1 for win :type all_players: list
- Returns:
player1 wins [1, 0, 0]: player0 wins [1, 1, 1]: draw [1, 1, 0]: player1 and player0 draws
- Return type:
[0, 1, 0]
- if hands[0] == None:
return [0, 1]
- elif hands[1] == None:
return [1, 0]