popgym.core.deck

Module Contents

Classes

Deck

An object that represents a collection of cards.

Functions

ascii_version_of_card(ranks, suits[, return_string])

Instead of a boring text version of the card we render an ASCII image of

Attributes

RANKS

SUITS

SUITS_UNICODE

COLORS

DECK_SIZE

popgym.core.deck.ascii_version_of_card(ranks, suits, return_string=True)

Instead of a boring text version of the card we render an ASCII image of the card.

Parameters:
  • cards – One or more card objects

  • return_string – By default we return the string version of the card, but the dealer hide the 1st card and we

keep it as a list so that the dealer can add a hidden card in front of the list

exception popgym.core.deck.DeckEmptyError

Bases: Exception

Common base class for all non-exit exceptions.

popgym.core.deck.RANKS
popgym.core.deck.SUITS
popgym.core.deck.SUITS_UNICODE = ['♠', '♦', '♥', '♣']
popgym.core.deck.COLORS
popgym.core.deck.DECK_SIZE = 52
class popgym.core.deck.Deck(num_decks=1, shuffle=False)

An object that represents a collection of cards.

A deck can represent a single deck or multiple decks

get_obs_space(fields=['colors', 'suits', 'ranks'], hand_size=1)
define_hand_value(fn: Callable[[List[str]], int], fields: List[str]) None

Pass in a function to be used to define the value of a hand or set of cards

clone() Deck
value(player: str) int

Returns the value of a players hand by calling the function passed to define_hand_value

value_idx(idx: List[int]) int

Returns the value of a selection of cards

add_players(*players: List[str]) None
deal(player: str, num_cards: int = 1) None

Deals a number of cards to the specified player from the deck

discard_hands(*players: List[str])

Discards the cards in the hand of a player. Note that these cards do not go back into the deck. Call reset() to fold the hands back into the deck

discard_all()

Discards the cards in all player hands. Note that these cards do not go back into the deck. Call reset() to fold the hands back into the deck

discard(player: str, hand_idx: int)

Discards one card in the players hand at the specified idx. Note this idx refers to the idx of the card in the hand, rather than the idx of the card in the deck

reset(shuffle=True, rng=None)

Empties the hands of all players and places cards back into the deck in their original position. Optionally shuffles the deck afterwards

show(player: str, fields: List[str] = ['colors', 'suits', 'ranks'], pad_to=None) List[numpy.ndarray]

Shows the hand of the player, returning the fields specified of the cards they hold. Optionally zero-pad to a size.

hand_size(player: str) int
visualize(player: str) str

Returns a string visualization of a player’s hand, for printing to the terminal

visualize_idx(idx: List[int]) str

Returns a string visualization of the following idx, referring to cards in the hand or deck