deck

デッキです

source

Deck

 Deck ()

A deck of cards.


source

Deck.pop

 Deck.pop (idx:int=-1)

Remove card from deck.

Type Default Details
idx int -1 The index of the card to remove. Default is the last card

source

Deck.shuffle

 Deck.shuffle ()

Shuffle the cards in this deck.

deck = Deck()
deck
A♣\;2♣\;3♣\;4♣\;5♣\;6♣\;7♣\;8♣\;9♣\;T♣\;J♣\;Q♣\;K♣\;A♦\;2♦\;3♦\;4♦\;5♦\;6♦\;7♦\;8♦\;9♦\;T♦\;J♦\;Q♦\;K♦\;A♥\;2♥\;3♥\;4♥\;5♥\;6♥\;7♥\;8♥\;9♥\;T♥\;J♥\;Q♥\;K♥\;A♠\;2♠\;3♠\;4♠\;5♠\;6♠\;7♠\;8♠\;9♠\;T♠\;J♠\;Q♠\;K♠

デッキの枚数は52枚のはず

len(deck)
52

Card の柄は何があるかを思い出す

suits
['♣', '♦', '♥', '♠']

クラブのエースがデッキにあるかの判定

Card(1, 1) in deck
True
deck = Deck()
test_eq(deck.pop(), Card(3, 13)) # The last card is the King of Spades

51枚のカードがデッキに残っています

test_eq(len(deck), 51)

source

Deck.remove

 Deck.remove (card:nbdev_cards.card.Card)

Removes card from the deck or raises exception if it is not there

Type Details
card Card Card to remove
card23 = Card(2, 3)
deck.remove(card23)

assert card23 not in deck

source

draw_n

 draw_n (n:int, replace:bool=True)

Draw n cards from the deck.

Type Default Details
n int Number of cards to draw
replace bool True Whether to replace the drawn cards