rlcard.utils

rlcard.utils.utils

rlcard.utils.utils.assign_task(task_num, process_num)

Assign the number of tasks according to the number of processes

Parameters
  • task_num (int) – An integer of assignments of tasks

  • process_num (int) – An integer of the number of processes

Returns

An list of the numbers of tasks assigned to processes

Return type

per_stasks (list)

rlcard.utils.utils.elegent_form(card)

Get a elegent form of a card string

Parameters

card (string) – A card string

Returns

A nice form of card

Return type

elegent_card (string)

rlcard.utils.utils.get_cards_from_ranks(player, ranks)

Get chosen cards and remained cards from a player’s hand according to input rank list

Parameters
  • player (Player) – Player object

  • ranks (list) – A list of rank (string)

Returns

Tuple containing:

(list): A list of Card objects, chosen cards (list): A list of Card objects, remained cards

Return type

(tupel)

Note: This function will not affect the player’s original hand.

rlcard.utils.utils.get_downstream_player_id(player, players)

Obtain the downsteam player’s player_id

Parameters
  • player (Player) – The current player

  • players (list) – A list of players

Note: This function assumes player_id(s) in ‘players’ list start from 0, and are consequent.

rlcard.utils.utils.get_random_cards(cards, num, seed=None)

Randomly get a number of chosen cards out of a list of cards

Parameters
  • cards (list) – List of Card object

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

  • seed (int) – Optional, random seed

Returns

A list of chosen cards (list): A list of remained cards

Return type

(list)

rlcard.utils.utils.get_upstream_player_id(player, players)

Obtain the upsteam player’s player_id

Parameters
  • player (Player) – The current player

  • players (list) – A list of players

Note: This function assumes player_id(s) in ‘players’ list starts from 0, and are consequent.

rlcard.utils.utils.init_54_deck()

Initialize a standard deck of 52 cards, BJ and RJ

Returns

Alist of Card object

Return type

(list)

rlcard.utils.utils.init_players(n)

Initilize a list of Player objects with n players

Parameters

n (int) – The number of players to be initialized

Returns

A list of Player objects with player_id(s) start from 0 and are consequent

Return type

(list)

rlcard.utils.utils.init_standard_deck()

Initialize a standard deck of 52 cards

Returns

A list of Card object

Return type

(list)

rlcard.utils.utils.is_in_cards(origin_cards, check_cards)

Check if a list of Card objects contains another list of Card objects

Parameters
  • cards (list) – A list of Card objects which to be checked if it contains another list of Card objects

  • check_cards (list) – A list of Card objects which to be checked if it is in a list of Card objecrts

Returns

True if the cards are in the original cards.

Return type

(boolean)

rlcard.utils.utils.is_pair(cards)

Check whether the card is a pair

Parameters

cards (list) – A list of Card object

Returns

True if the list is a pair

Return type

(boolean)

rlcard.utils.utils.is_single(cards)

Check whether the card is singel

Parameters

cards (list) – A list of Card object

Returns

True if the list is single

Return type

(boolean)

rlcard.utils.utils.print_card(cards)

Nicely print a card or list of cards

Parameters

card (string or list) – The card(s) to be printed

rlcard.utils.utils.rank2int(rank)

Get the coresponding number of a rank.

Parameters

rank (str) – rank stored in Card object

Returns

the number corresponding to the rank

Return type

(int)

Note

  1. If the input rank is an empty string, the function will return -1.

  2. If the input rank is not valid, the function will return None.

rlcard.utils.utils.remove_illegal(action_probs, legal_actions)
Remove illegal actions and normalize the

probability vector

Parameters
  • action_probs (numpy.array) – A 1 dimention numpy array.

  • legal_actions (list) – A list of indices of legal actions.

Returns

A normalized vector without legal actions.

Return type

probd (numpy.array)

rlcard.utils.utils.reorganize(trajectories, payoffs)

Reorganize the trajectory to make it RL friendly

Parameters
  • trajectory (list) – A list of trajectories

  • payoffs (list) – A list of payoffs for the players. Each entry corresponds to one player

Returns

A new trajectories that can be fed into RL algorithms.

Return type

(list)

rlcard.utils.utils.set_global_seed(seed)

Set the global see for reproducing results

Parameters

seed (int) – The seed

Note: If using other modules with randomness, they also need to be seeded

rlcard.utils.utils.take_out_cards(cards, remove_cards)

Take out specific cards from a list of cards

Parameters
  • cards (list) – A list of Card objects from which to be taken out some cards

  • remove_cards (list) – A list of Card objects that need to be taken out

Returns

A list of Card objects. The cards in ‘remove_cards’ list that doesn’t make cards in ‘cards’ list taken out

Return type

(list)

Note

1. This function will affect the first input Card list, but will not affect the second input Card list. 2. For each card in ‘remove_cards’ list, it will make only one card in ‘cards’ list taken out, which means to take out one kind of cards with the same suit and rank in ‘cards’ list, you need to have the same number of cards with the same suit and rank in ‘remove_cards’ list.

rlcard.utils.logger

class rlcard.utils.logger.Logger(xlabel='', ylabel='', legend='', log_path=None, csv_path=None)

Bases: object

Logger saves the running results and helps make plots from the results

add_point(x=None, y=None)

Add a point to the plot

Parameters
  • x (Number) – x coordinate value

  • y (Number) – y coordinate value

close_file()

Close the created file objects

log(text)

Write the text to log file then print it.

Parameters

text (string) – text to log

make_plot(save_path='')

Make plot using all stored points

Parameters

save_path (string) – where to store the plot