rlcard.games.doudizhu

rlcard.games.doudizhu.dealer

Implement Doudizhu Dealer class

class rlcard.games.doudizhu.dealer.DoudizhuDealer

Bases: object

Dealer will shuffle, deal cards, and determine players’ roles

deal_cards(players)

Deal cards to players

Parameters

players (list) – list of DoudizhuPlayer objects

determine_role(players)

Determine landlord and peasants according to players’ hand

Parameters

players (list) – list of DoudizhuPlayer objects

Returns

landlord’s player_id

Return type

int

shuffle()

Randomly shuffle the deck

rlcard.games.doudizhu.game

Implement Doudizhu Game class

class rlcard.games.doudizhu.game.DoudizhuGame(allow_step_back=False)

Bases: object

Provide game APIs for env to run doudizhu and get corresponding state information.

An example of state during runtime:
{

‘deck’: ‘3333444455556666777788889999TTTTJJJJQQQQKKKKAAAA2222BR’, ‘seen_cards’: ‘TQA’, ‘landlord’: 0, ‘self’: 2, ‘initial_hand’: ‘3456677799TJQKAAB’, ‘trace’: [(0, ‘8222’), (1, ‘pass’), (2, ‘pass’), (0, ‘6KKK’),

(1, ‘pass’), (2, ‘pass’), (0, ‘8’), (1, ‘Q’)],

‘played_cards’: [‘6’, ‘8’, ‘8’, ‘Q’, ‘K’, ‘K’, ‘K’, ‘2’, ‘2’, ‘2’], ‘others_hand’: ‘333444555678899TTTJJJQQAA2R’, ‘current_hand’: ‘3456677799TJQKAAB’, ‘actions’: [‘pass’, ‘K’, ‘A’, ‘B’]

}

static get_action_num()

Return the total number of abstract acitons

Returns

the total number of abstract actions of doudizhu

Return type

int

get_player_id()

Return current player’s id

Returns

current player’s id

Return type

int

get_player_num()

Return the number of players in doudizhu

Returns

the number of players in doudizhu

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

Initialize players and state.

Returns

first state in one game int: current player’s id

Return type

dict

is_over()

Judge whether a game is over

Returns

True(over) / False(not over)

Return type

Bool

step(action)

Perform one draw of the game

Parameters

action (str) – specific action of doudizhu. Eg: ‘33344’

Returns

next player’s state int: next player’s id

Return type

dict

step_back()

Return to the previous state of the game

Returns

True if the game steps back successfully

Return type

(bool)

rlcard.games.doudizhu.judger

Implement Doudizhu Judger class

class rlcard.games.doudizhu.judger.DoudizhuJudger(players)

Bases: object

Determine what cards a player can play

get_playable_cards(player)

Provide all legal cards the player can play according to his current hand.

Parameters
  • player (DoudizhuPlayer object) – object of DoudizhuPlayer

  • init_flag (boolean) – For the first time, set it True to accelerate the preocess.

Returns

list of string of playable cards

Return type

list

static judge_game(players, player_id)

Judge whether the game is over

Parameters
  • players (list) – list of DoudizhuPlayer objects

  • player_id (int) – integer of player’s id

Returns

True if the game is over

Return type

(bool)

static judge_payoffs(landlord_id, winner_id)

rlcard.games.doudizhu.player

Implement Doudizhu Player class

class rlcard.games.doudizhu.player.DoudizhuPlayer(player_id)

Bases: object

Player can store cards in the player’s hand and the role, determine the actions can be made according to the rules, and can perfrom corresponding action

available_actions(greater_player=None, judger=None)

Get the actions can be made based on the rules

Parameters

greater_player (DoudizhuPlayer object) – player who played

current biggest cards.

judger (DoudizhuJudger object): object of DoudizhuJudger

Returns

list of string of actions. Eg: [‘pass’, ‘8’, ‘9’, ‘T’, ‘J’]

Return type

list

get_state(public, others_hands, actions)
play(action, greater_player=None)

Perfrom action

Parameters
  • action (string) – specific action

  • greater_player (DoudizhuPlayer object) – The player who played current biggest cards.

Returns

If there is a new greater_player, return it, if not, return None

Return type

object of DoudizhuPlayer

rlcard.games.doudizhu.round

Implement Doudizhu Round class

class rlcard.games.doudizhu.round.DoudizhuRound

Bases: object

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

initiate(players)

Call dealer to deal cards and bid landlord.

Parameters

players (list) – list of DoudizhuPlayer objects

proceed_round(player, action)

Call other Classes’s functions to keep one round running

Parameters
  • player (object) – object of DoudizhuPlayer

  • action (str) – string of legal specific action

Returns

player who played current biggest cards.

Return type

object of DoudizhuPlayer

update_public(action)

Update public trace and played cards

Parameters

action (str) – string of legal specific action