-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeck.py
38 lines (34 loc) · 884 Bytes
/
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
from random import randint
class Deck():
def __init__(self, cards=None):
if cards:
self.cards = cards
else:
self.cards = self.generateDeck()
self.shuffle()
self.shuffle()
def generateDeck(self):
cards = []
for suit in range(4):
for card in range(1, 11):
if card == 10:
for _ in range(4):
cards.append(card)
else:
cards.append(card)
return cards
def shuffle(self):
shuffled = []
cards = self.cards
while len(cards):
index = randint(0, len(cards) - 1)
shuffled.append(cards[index])
if index == len(cards) - 1:
cards = cards[0:index - 1]
else:
first = cards[0:index]
first.extend(cards[index + 1:])
cards = first
self.cards = shuffled
def dealOne(self):
return self.cards.pop()