rlcard.games.simpledoudizhu

rlcard.games.simpledoudizhu.dealer

Implement Doudizhu Dealer class

class rlcard.games.simpledoudizhu.dealer.SimpleDoudizhuDealer(np_random)

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

static init_simple_doudizhu_deck()

Initialize a deck of 24 cards for simple Doudizhu

Returns

A list of Card object

Return type

(list)

shuffle()

Randomly shuffle the deck

rlcard.games.simpledoudizhu.game

Implement Doudizhu Game class

class rlcard.games.simpledoudizhu.game.SimpleDoudizhuGame(allow_step_back=False)

Bases: object

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

An example of state during runtime:

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.simpledoudizhu.player

Implement Doudizhu Player class

class rlcard.games.simpledoudizhu.player.SimpleDoudizhuPlayer(player_id, np_random)

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

property current_hand
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

play_back()

Restore recorded cards back to self._current_hand

set_current_hand(value)

rlcard.games.simpledoudizhu.round

Implement Doudizhu Round class

class rlcard.games.simpledoudizhu.round.SimpleDoudizhuRound(np_random)

Bases: object

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

cards_ndarray_to_list(ndarray_cards)
find_last_greater_player_id_in_trace()

Find the last greater_player’s id in trace

Returns

The last greater_player’s id in trace

find_last_played_cards_in_trace(player_id)

Find the player_id’s last played_cards in trace

Returns

The player_id’s last played_cards in trace

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

step_back(players)

Reverse the last action

Parameters

players (list) – list of DoudizhuPlayer objects

Returns

The last player id and the cards played

update_public(action)

Update public trace and played cards

Parameters

action (str) – string of legal specific action