-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.py
54 lines (41 loc) · 1.3 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
43
44
45
46
47
48
49
50
51
52
53
54
from random import shuffle
SUITS = ["Spades", "Clubs", "Diamonds", "Hearts"]
VALUES = [
"Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King"
]
IS_FACE = [
False, False, False, False, False, False, False,
False, False, False, True, True, True
]
POINT_VALUE = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
class Card:
def __init__(self, suit, value):
if suit not in SUITS:
raise (ValueError if type(suit) is str else TypeError)()
if value not in VALUES:
raise (ValueError if type(value) is str else TypeError)()
self.suit = suit
self.value = value
self.is_face = IS_FACE[VALUES.index(value)]
self.point_value = POINT_VALUE[VALUES.index(value)]
def __str__(self):
return f"{self.value} of {self.suit}"
class Deck:
def __init__(self):
self.cards = []
def default():
deck = Deck()
for suit in SUITS:
for value in VALUES:
deck.cards.append(Card(suit, value))
return deck
def add(self, card):
self.cards.append(card)
def draw(self):
if len(self.cards):
return self.cards.pop()
else:
return None
def shuffle(self):
shuffle(self.cards)