Welcome to Deck of Cards’s documentation!¶
Contents:
deck_of_cards package¶
Module contents¶
A Python Implementation Of A Deck of Cards
Submodules¶
deck_of_cards.card module¶
This module provides the Card
object.
This module also has 5 constant attributes that help validate or string format
the Card
object: POSSIBLE_SUIT
, POSSIBLE_RANK
,
, JOKER_SUIT
, JOKER_RANK
, and RANK_TRANSLATION
-
class
deck_of_cards.card.
Card
(rank, suit)[source]¶ Bases:
object
A Card object
Parameters: - rank (int) – a rank in
POSSIBLE_RANK
orJOKER_RANK
- suit (str) – a case-independent string in
POSSIBLE_SUIT
orJOKER_SUIT
Raises: ValueError
-
__eq__
(other)[source]¶ Override equality method
Returns: True if two objects are cards and have the same _rank
and_suit
Return type: bool
-
__repr__
()[source]¶ This method returns an unambigious string representation of the card object
Returns: unambigious string represenation of card object Return type: str
-
__str__
()[source]¶ This method returns a nice string representation of the card object
useful in printing card object as “%s”
Returns: human readable string represenation of card object Return type: str
-
_rank
= None¶ Holds an integer which represents the card rank
-
_suit
= None¶ Holds the suit as a lowercase string
- rank (int) – a rank in
-
deck_of_cards.card.
JOKER_RANK
= 0¶ a number representing the Joker’s rank
-
deck_of_cards.card.
JOKER_SUIT
= 'joker'¶ a string representing the Joker’s suit
-
deck_of_cards.card.
POSSIBLE_RANK
= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]¶ an array with the possible ranks
-
deck_of_cards.card.
POSSIBLE_SUIT
= ['hearts', 'diamonds', 'spades', 'clubs']¶ an array with all the possible suit strings
-
deck_of_cards.card.
RANK_TRANSLATION
= {1: 'ace', 11: 'jack', 12: 'queen', 13: 'king'}¶ a dictionary which translates the special face cards to strings
deck_of_cards.deck module¶
This module provides the Deck
object
-
class
deck_of_cards.deck.
Deck
(with_jokers=True)[source]¶ Bases:
object
A Deck object
A new deck starts out ordered.
If jokers are included, contains (2 + 4 * 13)
deck_of_cards.card.Card
objectsIf no jokers are included, contains (4 * 13)
deck_of_cards.card.Card
objectsParameters: with_jokers (bool) – include jokers if True -
_cards
= []¶ an array of unused
deck_of_cards.card.Card
objects that are waiting to be dealt
-
_discarded_cards
= []¶ an array of discarded
deck_of_cards.card.Card
objects
-
_in_play_cards
= []¶ an array of
deck_of_cards.card.Card
objects that have been dealt
-
_with_jokers
= True¶ a boolean to represent if jokers exist in deck
-
check_deck
()[source]¶ Check to make sure all the cards are accounted
Returns: True if all cards are accounted Return type: bool
-
deal
()[source]¶ Deals a single
deck_of_cards.card.Card
from_cards
Raises an IndexError when
_cards
is emptyReturns: a single deck_of_cards.card.Card
Return type: deck_of_cards.card.Card
Raises: IndexError
-
discard
(cards)[source]¶ Remove cards from the
_in_play_cards
array and add them to_discarded_cards
arrayRaises a ValueError when trying to discard a card that does not exist in
_in_play_cards
.Parameters: cards (array) – an array of deck_of_cards.card.Card
objects or a singledeck_of_cards.card.Card
Raises: ValueError
-
-
deck_of_cards.deck.
LOGGER
= <logging.Logger object>¶ a logger object