-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.py
More file actions
44 lines (28 loc) · 832 Bytes
/
deck.py
File metadata and controls
44 lines (28 loc) · 832 Bytes
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
import random
class Card:
def __init__(self, val):
self.val = val
def __eq__(self, value):
return self.val == value.val
def __hash__(self):
return hash(self.val)
def __str__(self):
return str(self.val)
def __repr__(self) -> str:
return str(self.val)
class Deck(object):
def __init__(self) -> None:
self.cards = []
self.create_deck()
def create_deck(self):
for i in range(1, 14):
for _ in range(4):
self.cards.append(Card(i))
def shuffle(self):
random.shuffle(self.cards)
def isEmpty(self):
return len(self.cards) == 0
def draw(self):
if len(self.cards) == 0 or not self.cards:
raise IndexError("The deck is empty.")
return self.cards.pop()