rlcard.games.mahjong

rlcard.games.mahjong.dealer

class rlcard.games.mahjong.dealer.MahjongDealer(np_random)

Bases: object

Initialize a mahjong dealer class

deal_cards(player, num)

Deal some cards from deck to one player

Parameters:
  • player (object) – The object of DoudizhuPlayer

  • num (int) – The number of cards to be dealed

shuffle()

Shuffle the deck

rlcard.games.mahjong.game

class rlcard.games.mahjong.game.MahjongGame(allow_step_back=False)

Bases: object

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 Mahjong

Returns:

the number of players in the game

Return type:

(int)

get_player_id()

return the id of current player in Mahjong

Returns:

the number of players in the game

Return type:

(int)

get_state(player_id)

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 Mahjong

This version supports two-player Mahjong

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.mahjong.judger

Implement Mahjong Judger class

class rlcard.games.mahjong.judger.MahjongJudger(np_random)

Bases: object

Determine what cards a player can play

cal_set(cards)

Calculate the set for given cards :param Cards: List of cards. :type Cards: list

Returns:

Sets (list): List of cards that has been pop from user’s hand

Return type:

Set_count (int)

static check_consecutive(_list)

Check if list is consecutive :param _list: The target list :type _list: list

Returns:

consecutive or not

Return type:

Result (bool)

judge_chow(dealer, players, last_player)

Judge which player has chow :param dealer: The dealer object. :type dealer: object :param players: List of all players :type players: list :param last_player: The player id of last player :type last_player: int

judge_game(game)

Judge which player has win the game :param dealer: The dealer object. :type dealer: object :param players: List of all players :type players: list :param last_player: The player id of last player :type last_player: int

judge_hu(player)

Judge whether the player has win the game :param player: Target player :type player: object

Returns:

Win or not Maximum_score (int): Set count score of the player

Return type:

Result (bool)

static judge_pong_gong(dealer, players, last_player)

Judge which player has pong/gong :param dealer: The dealer object. :type dealer: object :param players: List of all players :type players: list :param last_player: The player id of last player :type last_player: int

rlcard.games.mahjong.player

class rlcard.games.mahjong.player.MahjongPlayer(player_id, np_random)

Bases: object

chow(dealer, cards)

Perform Chow :param dealer: Dealer :type dealer: object :param Cards: The cards to be Chow. :type Cards: object

get_player_id()

Return the id of the player

gong(dealer, cards)

Perform Gong :param dealer: Dealer :type dealer: object :param Cards: The cards to be Gong. :type Cards: object

play_card(dealer, card)

Play one card :param dealer: Dealer :type dealer: object :param Card: The card to be play. :type Card: object

pong(dealer, cards)

Perform Pong :param dealer: Dealer :type dealer: object :param Cards: The cards to be Pong. :type Cards: object

print_hand()

Print the cards in hand in string.

print_pile()

Print the cards in pile of the player in string.

rlcard.games.mahjong.round

class rlcard.games.mahjong.round.MahjongRound(judger, dealer, num_players, np_random)

Bases: object

get_state(players, player_id)

Get player’s state

Parameters:
  • players (list) – The list of MahjongPlayer

  • player_id (int) – The id of the player

Returns:

The information of the state

Return type:

state (dict)

proceed_round(players, action)

Call other Classes’s functions to keep one round running

Parameters:
  • player (object) – object of UnoPlayer

  • action (str) – string of legal action

rlcard.games.mahjong.card

class rlcard.games.mahjong.card.MahjongCard(card_type, trait)

Bases: object

get_str()

Get the string representation of card

Returns:

The string of card’s color and trait

Return type:

(str)

info = {'trait': ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'green', 'red', 'white', 'east', 'west', 'north', 'south'], 'type': ['dots', 'bamboo', 'characters', 'dragons', 'winds']}
set_index_num(index_num)

rlcard.games.mahjong.utils

rlcard.games.mahjong.utils.cards2list(cards)
rlcard.games.mahjong.utils.encode_cards(cards)
rlcard.games.mahjong.utils.init_deck()
rlcard.games.mahjong.utils.pile2list(pile)