:py:mod:`whist_core.cards.card_container` ========================================= .. py:module:: whist_core.cards.card_container .. autoapi-nested-parse:: Extraction of common methods for class that contains a set of cards Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: whist_core.cards.card_container.CardContainer whist_core.cards.card_container.UnorderedCardContainer whist_core.cards.card_container.OrderedCardContainer .. py:class:: CardContainer Bases: :py:obj:`pydantic.BaseModel`, :py:obj:`abc.ABC` Abstract Base Class for card containers. Duplicate cards are not allowed. .. py:attribute:: cards :type: tuple[whist_core.cards.card.Card, Ellipsis] .. py:method:: empty() -> CardContainer :classmethod: Creates an empty card container. :return: empty ard container :rtype: correct subtype of CardContainer .. py:method:: with_cards(*cards) -> CardContainer :classmethod: Creates a card container with the given cards. :param cards: cards to add :return: card container with given cards :rtype: correct subtype of CardContainer .. py:method:: full() -> CardContainer :classmethod: Create a full card container. :return: full card container :rtype: correct subtype of CardContainer .. py:method:: pop_random() -> whist_core.cards.card.Card Removes one random card from card container. :return: A card from deck. .. py:method:: __contains__(card: whist_core.cards.card.Card) -> bool Returns if a card is in container. True if yes else False. .. py:method:: __len__() Returns the amount of cards in the container. .. py:method:: __iter__() -> Iterator[whist_core.cards.card.Card] Iterates over all cards. .. py:method:: __str__() -> str Returns string representation of all cards. .. py:method:: __repr__() -> str Returns string representation of all cards with class name. .. py:method:: remove(card: whist_core.cards.card.Card) -> None Remove a card from this container. :param card: card to remove .. py:method:: _remove_impl(card: whist_core.cards.card.Card) -> None :abstractmethod: .. py:method:: add(card: whist_core.cards.card.Card) -> None Add a card to this container. :param card: card to add .. py:method:: _add_impl(card: whist_core.cards.card.Card) -> None :abstractmethod: .. py:method:: contains_suit(suit: whist_core.cards.card.Suit) -> bool Checks if a card of a suit is still in the card container. :param suit: which should be checked :return: True if contains this suit else False .. py:method:: 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. :param suit: which should be checked :return: iterator of cards of given suit .. py:class:: UnorderedCardContainer(**data) Bases: :py:obj:`CardContainer` Base Class unordered card containers .. py:attribute:: _cards_set :type: set[whist_core.cards.card.Card] .. py:method:: __contains__(card: whist_core.cards.card.Card) -> bool Returns if a card is in container. True if yes else False. .. py:method:: _remove_impl(card: whist_core.cards.card.Card) -> None .. py:method:: _add_impl(card: whist_core.cards.card.Card) -> None .. py:method:: __resync() -> None de-duplicate and re-sort self.cards - i.e. synchronize with the set representation .. py:class:: OrderedCardContainer Bases: :py:obj:`CardContainer` Base Class ordered card containers .. py:property:: first :type: Optional[whist_core.cards.card.Card] Returns the first card in the card container. :return: The first card played if it exists. Else None. .. py:property:: last :type: Optional[whist_core.cards.card.Card] Returns the last card in the card container. :return: The last card played if it exists. Else None. .. py:method:: _remove_impl(card: whist_core.cards.card.Card) -> None .. py:method:: _add_impl(card: whist_core.cards.card.Card) -> None .. py:method:: 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 .. py:method:: get_turn_and_winner_card(trump: whist_core.cards.card.Suit) -> Optional[tuple[int, whist_core.cards.card.Card]] 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