Deck
Deck ()
Represents a deck of cards
Deck ()
Represents a deck of cards
A Deck of cards is a collection of Card
objects:
A♣️; 2♣️; 3♣️; 4♣️; 5♣️; 6♣️; 7♣️; 8♣️; 9♣️; 10♣️; J♣️; Q♣️; K♣️; A♦️; 2♦️; 3♦️; 4♦️; 5♦️; 6♦️; 7♦️; 8♦️; 9♦️; 10♦️; J♦️; Q♦️; K♦️; A❤️; 2❤️; 3❤️; 4❤️; 5❤️; 6❤️; 7❤️; 8❤️; 9❤️; 10❤️; J❤️; Q❤️; K❤️; A♠️; 2♠️; 3♠️; 4♠️; 5♠️; 6♠️; 7♠️; 8♠️; 9♠️; 10♠️; J♠️; Q♠️; K♠️
There are 52 cards in a deck.
Deck.pop (index=-1)
Removes and returns card index
from the deck
Type | Default | Details | |
---|---|---|---|
index | int | -1 | Card number to pop |
There are 51 cards left in the deck now.
You can show the docs for methods not created with patch
by calling show_doc
. For example, the code show_doc(Deck.remove)
produces the following documentation:
Deck.remove (card:cards_deck.card.Card)
Removes card
from the deck or raises exception if it is not there
Type | Details | |
---|---|---|
card | Card | Card to remove |
If we remove a card from the Deck we can verify that it no longer exists:
However, another card that we haven’t removed, such as the 10 of hearts
will still be in the Deck of cards because we haven’t removed it:
Hand ()
Represents a deck of cards
move_cards (source:__main__.Deck, dest:__main__.Hand, num:int)
Pop the given number of cards from the deck and move to dest
.
Type | Details | |
---|---|---|
source | Deck | deck to move cards from |
dest | Hand | destination to move cards to |
num | int | number of cards to move |
Let’s try something fun with our deck of cards, drawing a card with replacement:
draw_n (n:int, replace:bool=True)
Draw n
cards, with replacement iif replace
Type | Default | Details | |
---|---|---|---|
n | int | number of cards to draw | |
replace | bool | True | whether or not draw with replacement |
This isn’t terribly interesting from a statistical perspective. However, its an example of how you can include visualizations in your nbdev projects!
We can create a CLI with @call parse
draw_cards (n:int, replace:bool=True, outfile:str=None)
Draw n
cards optionally with replacement
Type | Default | Details | |
---|---|---|---|
n | int | number of cards to draw | |
replace | bool | True | whether or not draw with replacement |
outfile | str | None | output file, defaults to stdout |