rlcard.games.uno

rlcard.games.uno.dealer

class rlcard.games.uno.dealer.UnoDealer(np_random)

Bases: object

Initialize a uno 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

flip_top_card()

Flip top card when a new game starts

Returns

The object of UnoCard at the top of the deck

Return type

(object)

shuffle()

Shuffle the deck

rlcard.games.uno.game

class rlcard.games.uno.game.UnoGame(allow_step_back=False)

Bases: object

static get_action_num()

Return the number of applicable actions

Returns

The number of actions. There are 61 actions

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_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

Tuple containing:

(dict): The first state in one 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

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

class rlcard.games.uno.judger.UnoJudger

Bases: object

static judge_winner(players, np_random)

Judge the winner of the game

Parameters

players (list) – The list of players who play the game

Returns

The player id of the winner

Return type

(list)

rlcard.games.uno.player

class rlcard.games.uno.player.UnoPlayer(player_id, np_random)

Bases: object

get_player_id()

Return the id of the player

rlcard.games.uno.round

class rlcard.games.uno.round.UnoRound(dealer, num_players, np_random)

Bases: object

flip_top_card()

Flip the top card of the card pile

Returns

the top card in game

Return type

(object of UnoCard)

get_state(players, player_id)

Get player’s state

Parameters
  • players (list) – The list of UnoPlayer

  • player_id (int) – The id of the player

perform_top_card(players, top_card)

Perform the top card

Parameters
  • players (list) – list of UnoPlayer objects

  • top_card (object) – object of UnoCard

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

replace_deck()

Add cards have been played to deck

rlcard.games.uno.card

class rlcard.games.uno.card.UnoCard(card_type, color, trait)

Bases: object

get_str()

Get the string representation of card

Returns

The string of card’s color and trait

Return type

(str)

info = {'color': ['r', 'g', 'b', 'y'], 'trait': ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'skip', 'reverse', 'draw_2', 'wild', 'wild_draw_4'], 'type': ['number', 'action', 'wild']}
static print_cards(cards, wild_color=False)

Print out card in a nice form

Parameters
  • card (str or list) – The string form or a list of a UNO card

  • wild_color (boolean) – True if assign collor to wild cards

rlcard.games.uno.utils

rlcard.games.uno.utils.cards2list(cards)

Get the corresponding string representation of cards

Parameters

cards (list) – list of UnoCards objects

Returns

string representation of cards

Return type

(string)

rlcard.games.uno.utils.encode_hand(plane, hand)

Encode hand and represerve it into plane

Parameters
  • plane (array) – 3*4*15 numpy array

  • hand (list) – list of string of hand’s card

Returns

3*4*15 numpy array

Return type

(array)

rlcard.games.uno.utils.encode_target(plane, target)

Encode target and represerve it into plane

Parameters
  • plane (array) – 1*4*15 numpy array

  • target (str) – string of target card

Returns

1*4*15 numpy array

Return type

(array)

rlcard.games.uno.utils.hand2dict(hand)

Get the corresponding dict representation of hand

Parameters

hand (list) – list of string of hand’s card

Returns

dict of hand

Return type

(dict)

rlcard.games.uno.utils.init_deck()

Generate uno deck of 108 cards