API¶
Basic types¶
-
class
cardsource.cards.
Card
(value)¶ Represents a single playing card
A
Card
object supports a number of operations.When compared to another card, a card is greater than another card if the rank (A, 7, 2) is higher than the other card’s rank. Suits are not considered. Jokers are higher than any card. For equivalence, both suit and rank must be equal for the objects to be equal.
-
class
cardsource.hand.
Hand
¶ Represents a playing card game hand containing instances of
cardsource.cards.Card
A
Hand
is an iterable Python object that supports being added to other hands as well as other common iterable operations. Hands are not directly comparable but this is common in subclasses ofHand
.-
append
(card)¶ Adds a Card to the hand
This class can be overridden in subclasses to ensure that the correct type of cards are added to the hand. Hands should not contain both instances of
Card
and subclasses ofCard
.Parameters: card ( cardsource.cards.Card
) – the card to add
-
clear
()¶ Removes all cards from the hand
-
count
(card)¶ Returns the number of instances of the specified card
Parameters: card ( cardsource.cards.Card
) – the card to search forReturn type: int Returns: the number of instances of the specified card
-
extend
(otherhand)¶ Extends hand by appending cards from another hand
Parameters: card ( cardsource.hand.Hand
) – the hand to append to this hand
-
-
class
cardsource.deck.
Deck
(numjokers=0)¶ Represents a playing card deck optionally with jokers. Each member is an instance of
cardsource.cards.Card
.A
Deck
is an iterable object that supports a number of standard Python operations like indexing, iteration and slicing.-
append
(card)¶ Put a card on the top of the deck
Parameters: card ( cardsource.cards.Card
) – the card to add
-
appendleft
(card)¶ Put a card on the bottom of the deck
Parameters: card ( cardsource.cards.Card
) – the card to add
-
clear
()¶ Remove all cards in the deck
-
pop
()¶ Removes and returns the top card in the deck
Raises: IndexError if the deck is empty Returns: the top card in the deck Return type: cardsource.cards.Card
-
shuffle
()¶ Shuffle the deck
Uses
random.shuffle
-