# AUTOGENERATED! DO NOT EDIT! File to edit: ../01_deck.ipynb.

# %% auto 0
__all__ = ['Deck', 'draw_n']

# %% ../01_deck.ipynb 4
from .card import *
from fastcore.utils import *
import random

# %% ../01_deck.ipynb 5
class Deck: 
          "A deck of 52 cards, not including jokers"
          def __init__(self):self.cards = [Card(s,r) for s in range(4) for r in range(1,14)]
          def __len__(self):return len(self.cards)
          def __str__(self):return ';'.join(map(str,self.cards))
          def __contains__(self,card):return card in self.cards
          __repr__ = __str__
          def shuffle(self):
             "shuffle the cards in this deck"
             random.shuffle(self.cards)

# %% ../01_deck.ipynb 11
@patch
def pop(self:Deck,
        idx:int=-1): #the index of the card to remove,defaulting to the last one
    "remove and return one card"
    return self.cards.pop(idx)
    

# %% ../01_deck.ipynb 12
@patch
def remove(self:Deck,card:Card):# Card to remove
    "Removes card from the deck or raise exception if it's not there"
    self.cards.remove(card)

# %% ../01_deck.ipynb 17
def draw_n(n:int, #number of cards to draw
           replace:bool=True): # whether or not to draw with replacement
    deck=Deck()
    deck.shuffle()
    if replace: return [deck.cards[random.choice(range(len(deck.cards)))] for _ in range(n)]

    else : return deck.cards[:n]
