source
Deck
Deck ()
A deck of 52 cards, not including jokers.
When we initially create a deck, all of the cards will be present:
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♣️
That should be 52 cards.
We can check if a card is on the deck:
source
Deck.pop
Deck.pop (idx:int=-1)
Remove and return one card.
idx |
int |
-1 |
The index of the card to remove (default: last card) |
Let’s pop a card
And now the dack should have only 51 cards
source
Deck.remove
Deck.remove (card:nbdev_tutorial.card.Card)
Remove a specific card.
card23 = Card(2, 3)
deck.remove(card23)
assert card23 not in deck
source
Deck.shuffle
Deck.shuffle ()
Shuffle the cards.
source
draw_n
draw_n (n:int, replace:bool=True)
Draw n cards from the deck.
n |
int |
|
The number of cards to draw |
replace |
bool |
True |
Whether to replace the cards after drawing |
[8♥️, 4♣️, 3♣️, 5♥️, 5♠️]