-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.py
42 lines (33 loc) · 1 KB
/
deck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from card import Card, Suits, Ranks
from random import shuffle
class Deck:
def __init__(self):
self.cards = list()
self.discard = list()
for suit in Suits:
for rank in Ranks:
self.cards.append(Card(rank, suit))
self.reshuffle()
self.cardsCount = len(self.cards)
def draw(self):
drawn = self.cards.pop()
self.discard.append(drawn)
return drawn;
def getNumberOfCardsTotal(self):
return self.cardsCount
def getNumberOfCardsLeft(self):
return len(self.cards)
def restartDeck(self):
"""
Puts all the cards back in the deck and reshuffles them.
"""
self.cards.extend(self.discard)
self.reshuffle()
self.discard.clear()
def copyDeck(self):
newDeck = Deck()
copy = list(self.cards)
newDeck.cards = copy
return newDeck
def reshuffle(self):
shuffle(self.cards)