Hand

Simple module that holds the cards of multiple players
Code
class Hand:
    def __init__(
        # Max amount of cards it can be hold
        self, max_cards: Optional[int] = None
    ):
        self._max_cards = max_cards
        self.cards: List[Card] = []

    def __getitem__(self, value: int):
        return self.cards[value]

    def __len__(self):
        return len(self.cards)

    def __iter__(self) -> Iterator[Card]:
        return iter(self.cards)

    def __repr__(self):
        return "\n".join(str(card) for card in self.cards)

source

Hand

 Hand (max_cards:Optional[int]=None)

Initialize self. See help(type(self)) for accurate signature.

Type Default Details
max_cards typing.Optional[int] None Max amount of cards it can be hold

source

Hand.draw

 Hand.draw (card:itepifanio_deck.core.Card)

source

Hand.discard

 Hand.discard (index:int=0)

source

Hand.value

 Hand.value ()

Usage example

The hand can be used as a property for players in a deck game. Check the following hand definition that can draw and discard a card

hand = Hand()
card = Card(rank=1, suit="spades")

hand.draw(card)  # type: ignore
hand
Card(rank=1, suit='spades')

The hand is iterable

[card for card in hand]
[Card(rank=1, suit='spades')]
hand.discard()  # type: ignore
len(hand)
0