rlcard.games.limitholdem

rlcard.games.limitholdem.dealer

class rlcard.games.limitholdem.dealer.LimitholdemDealer

Bases: object

deal_card()

Deal one card from the deck

Returns

The drawn card from the deck

Return type

(Card)

shuffle()

Shuffle the deck

rlcard.games.limitholdem.game

class rlcard.games.limitholdem.game.LimitholdemGame(allow_step_back=False)

Bases: object

static get_action_num()

Return the number of applicable actions

Returns

The number of actions. There are 4 actions (call, raise, check and fold)

Return type

(int)

Return the legal actions for current player

Returns

A list of legal actions

Return type

(list)

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_player_num()

Return the number of players in Limit Texas Hold’em

Returns

The number of players in the game

Return type

(int)

get_state(player)

Return player’s state

Parameters

player_id (int) – player id

Returns

The state of the player

Return type

(dict)

init_game()

Initialilze the game of Limit Texas Hold’em

This version supports two-player limit texas hold’em

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 plater’s 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

Bases: object

The Judger class for Texas Hold’em

static 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)

rlcard.games.limitholdem.player

class rlcard.games.limitholdem.player.LimitholdemPlayer(player_id)

Bases: object

get_player_id()

Return the id of the player

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

Implement Limit Texas Hold’em Round class

class rlcard.games.limitholdem.round.LimitholdemRound(raise_amount, allowed_raise_num, num_players)

Bases: object

Round can call other Classes’ functions to keep the game running

Obtain the legal actions for the curent 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’s 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

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’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CJ’, ‘SJ’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CT’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘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)

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’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CJ’, ‘SJ’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CT’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘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]

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’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CJ’, ‘SJ’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CT’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘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.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’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CJ’, ‘SJ’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘C7’], [‘CT’, ‘ST’, ‘H9’, ‘B9’, ‘C2’, ‘C8’, ‘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]