Cards

from dgisim import Cards

__eq__ and __hash__ are implemented so that any two Cards with the equivalent content are equal to each other and have the same hash.

class Cards(cards: dict[type[Card], int])

A container for easy management of cards.

add(card: type[Card]) Cards
Returns:

new cards with addition of one card.

contains(card: type[Card]) bool
Returns:

True if card can be found.

Note if there’s at least one OmniCard, then True is always returned.

classmethod decoding(encoding: list[int], encoding_plan: EncodingPlan) None | Cards
Returns:

the Cards object decoded from encoding.

empty() bool
Returns:

True if there’s no cards.

encoding(encoding_plan: EncodingPlan) list[int]
Returns:

the encoding of this Cards object.

extend(cards: Cards | dict[type[Card], int], limit: None | int = None) Cards
Returns:

new cards with addition of cards discarding some if the combined num exceeds limit.

classmethod from_empty() Cards
Returns:

an empty Cards object.

hide_all() Cards
Returns:

the hidden version of cards. (replace all by OmniCard)

Returns:

True if the current cards are legal (num >= 0 for each kind).

not_empty() bool
Returns:

True if there’s at least one card.

num_cards() int
Returns:

the number of cards.

pick_random(num: int) tuple[dgisim.card.cards.Cards, dgisim.card.cards.Cards]
Returns:

a tuple of [cards left, cards selected].

num random cards are selected and returned with the left over cards.

pick_random_of_type(num: int, card_type: type[Card]) tuple[Cards, Cards]

Similar to .pick_random_cards() but only select from cards of type card_type.

remove(card: type[Card]) Cards
Returns:

new cards with removal of one card.

remove_all(card: type[Card]) Cards
Returns:

new cards with removal of all cards of exactly type card.

If the card cannot be found, then no cards are removed no matter what.

switch_random_different(cards_back: Cards) tuple[dgisim.card.cards.Cards, dgisim.card.cards.Cards]
Returns:

a tuple of [cards left, cards selected].

cards_back is the cards to be put back into the pool, and self should be the pool.

The selected cards try to be different from the cards in cards_back.