source
Deck
Deck ()
A deck of 52 cards
When we initially create a deck, all cards will be presend
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♦️
As a reminder these are the suits we defined for Card
We can check if the Ace of Spades in the deck
source
Deck.pop
Deck.pop (idx:int=-1)
Remove and return one card
| idx |
int |
-1 |
Index of the card to remove, defaulting to the last card |
deck = Deck()
test_eq(deck.pop(), Card(3, 13)) # K♦️
source
Deck.remove
Deck.remove (card:nbdev_experiment.card.Card)
Removes card from deck and raises an exception if not there
| card |
Card |
A card to remove |
three_of_clubs = Card(2,3)
deck.remove(three_of_clubs)
assert three_of_clubs not in deck
source
Deck.shuffle
Deck.shuffle ()
Shuffle the cards in a deck
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♦️
J♣️; 5♦️; 5♥️; K♣️; 4♠️; 3♣️; Q♠️; 8♦️; 7♥️; J♦️; 6♦️; A♦️; 4♣️; 9♦️; 2♠️; K♦️; 10♦️; 3♠️; Q♣️; 4♥️; 7♣️; J♥️; 8♣️; 4♦️; 6♥️; K♥️; 7♠️; 5♠️; 9♠️; A♥️; 2♦️; 9♣️; 8♠️; 3♥️; 5♣️; 2♣️; J♠️; 6♠️; 3♦️; 10♥️; 10♠️; 7♦️; 10♣️; A♣️; 2♥️; 9♥️; A♠️; K♠️; Q♥️; 8♥️; 6♣️; Q♦️
source
draw_n
draw_n (n:int, replace:bool=True)
Draw n cards from a deck with replacement (if replace=True)
| n |
int |
|
Number of cards to draw |
| replace |
bool |
True |
wheather or not you want replacement |
[Q♣️, 3♣️, K♦️, A♣️, 6♠️]