whist_core.cards.card_container

Extraction of common methods for class that contains a set of cards

Classes

CardContainer

Abstract Base Class for card containers. Duplicate cards are not allowed.

UnorderedCardContainer

Base Class unordered card containers

OrderedCardContainer

Base Class ordered card containers

Module Contents

class whist_core.cards.card_container.CardContainer

Bases: pydantic.BaseModel, abc.ABC

Abstract Base Class for card containers. Duplicate cards are not allowed.

cards: tuple[whist_core.cards.card.Card, Ellipsis]
classmethod empty()

Creates an empty card container.

Returns:

empty ard container

Return type:

correct subtype of CardContainer

classmethod with_cards(*cards)

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()

Create a full card container.

Returns:

full card container

Return type:

correct subtype of CardContainer

pop_random()

Removes one random card from card container.

Returns:

A card from deck.

Return type:

whist_core.cards.card.Card

__contains__(card)

Returns if a card is in container. True if yes else False.

Parameters:

card (whist_core.cards.card.Card)

Return type:

bool

__len__()

Returns the amount of cards in the container.

__iter__()

Iterates over all cards.

Return type:

Iterator[whist_core.cards.card.Card]

__str__()

Returns string representation of all cards.

Return type:

str

__repr__()

Returns string representation of all cards with class name.

Return type:

str

remove(card)

Remove a card from this container.

Parameters:

card (whist_core.cards.card.Card) – card to remove

Return type:

None

abstractmethod _remove_impl(card)
Parameters:

card (whist_core.cards.card.Card)

Return type:

None

add(card)

Add a card to this container.

Parameters:

card (whist_core.cards.card.Card) – card to add

Return type:

None

abstractmethod _add_impl(card)
Parameters:

card (whist_core.cards.card.Card)

Return type:

None

contains_suit(suit)

Checks if a card of a suit is still in the card container.

Parameters:

suit (whist_core.cards.card.Suit) – which should be checked

Returns:

True if contains this suit else False

Return type:

bool

get_cards_of_suit(suit)

Get all cards of a suit in the card container.

Parameters:

suit (whist_core.cards.card.Suit) – which should be checked

Returns:

iterator of cards of given suit

Return type:

Iterator[whist_core.cards.card.Card]

class whist_core.cards.card_container.UnorderedCardContainer(**data)

Bases: CardContainer

Base Class unordered card containers

_cards_set: set[whist_core.cards.card.Card]
__contains__(card)

Returns if a card is in container. True if yes else False.

Parameters:

card (whist_core.cards.card.Card)

Return type:

bool

_remove_impl(card)
Parameters:

card (whist_core.cards.card.Card)

Return type:

None

_add_impl(card)
Parameters:

card (whist_core.cards.card.Card)

Return type:

None

__resync()

de-duplicate and re-sort self.cards - i.e. synchronize with the set representation

Return type:

None

class whist_core.cards.card_container.OrderedCardContainer

Bases: CardContainer

Base Class ordered card containers

_remove_impl(card)
Parameters:

card (whist_core.cards.card.Card)

Return type:

None

_add_impl(card)
Parameters:

card (whist_core.cards.card.Card)

Return type:

None

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.

Return type:

Optional[whist_core.cards.card.Card]

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.

Return type:

Optional[whist_core.cards.card.Card]

get_turn(card)

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

Parameters:

card (whist_core.cards.card.Card)

Return type:

int

get_turn_and_winner_card(trump)

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

Parameters:

trump (whist_core.cards.card.Suit)

Return type:

Optional[tuple[int, whist_core.cards.card.Card]]