whist_core.cards.card_container¶
Extraction of common methods for class that contains a set of cards
Module Contents¶
Classes¶
Abstract Base Class for card containers. Duplicate cards are not allowed. |
|
Base Class unordered card containers |
|
Base Class ordered card containers |
- class whist_core.cards.card_container.CardContainer¶
Bases:
pydantic.BaseModel,abc.ABCAbstract Base Class for card containers. Duplicate cards are not allowed.
- cards: tuple[whist_core.cards.card.Card, Ellipsis]¶
- classmethod empty() CardContainer¶
Creates an empty card container.
- Returns:
empty ard container
- Return type:
correct subtype of CardContainer
- classmethod with_cards(*cards) CardContainer¶
Creates a card container with the given cards.
- Parameters:
cards – cards to add
- Returns:
card container with given cards
- Return type:
correct subtype of CardContainer
- classmethod full() CardContainer¶
Create a full card container.
- Returns:
full card container
- Return type:
correct subtype of CardContainer
- pop_random() whist_core.cards.card.Card¶
Removes one random card from card container.
- Returns:
A card from deck.
- __contains__(card: whist_core.cards.card.Card) bool¶
Returns if a card is in container. True if yes else False.
- __len__()¶
Returns the amount of cards in the container.
- __iter__() Iterator[whist_core.cards.card.Card]¶
Iterates over all cards.
- __str__() str¶
Returns string representation of all cards.
- __repr__() str¶
Returns string representation of all cards with class name.
- remove(card: whist_core.cards.card.Card) None¶
Remove a card from this container.
- Parameters:
card – card to remove
- abstract _remove_impl(card: whist_core.cards.card.Card) None¶
- add(card: whist_core.cards.card.Card) None¶
Add a card to this container.
- Parameters:
card – card to add
- abstract _add_impl(card: whist_core.cards.card.Card) None¶
- contains_suit(suit: whist_core.cards.card.Suit) bool¶
Checks if a card of a suit is still in the card container.
- Parameters:
suit – which should be checked
- Returns:
True if contains this suit else False
- get_cards_of_suit(suit: whist_core.cards.card.Suit) Iterator[whist_core.cards.card.Card]¶
Get all cards of a suit in the card container.
- Parameters:
suit – which should be checked
- Returns:
iterator of cards of given suit
- class whist_core.cards.card_container.UnorderedCardContainer(**data)¶
Bases:
CardContainerBase Class unordered card containers
- _cards_set: set[whist_core.cards.card.Card]¶
- __contains__(card: whist_core.cards.card.Card) bool¶
Returns if a card is in container. True if yes else False.
- _remove_impl(card: whist_core.cards.card.Card) None¶
- _add_impl(card: whist_core.cards.card.Card) None¶
- __resync() None¶
de-duplicate and re-sort self.cards - i.e. synchronize with the set representation
- class whist_core.cards.card_container.OrderedCardContainer¶
Bases:
CardContainerBase Class ordered card containers
- property first: whist_core.cards.card.Card | None¶
Returns the first card in the card container. :return: The first card played if it exists. Else None.
- property last: whist_core.cards.card.Card | None¶
Returns the last card in the card container. :return: The last card played if it exists. Else None.
- _remove_impl(card: whist_core.cards.card.Card) None¶
- _add_impl(card: whist_core.cards.card.Card) None¶
- get_turn(card: whist_core.cards.card.Card) int¶
Gets the turn of a card played. :param card: for which the turn number shall be found :return: the index of the card in the card container. 0 is the first the card played
- get_turn_and_winner_card(trump: whist_core.cards.card.Suit) tuple[int, whist_core.cards.card.Card] | None¶
Returns the highest trump card or the highest card of the suit played first. :param trump: suit of trump :return: the winning card and its index