-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeck.py
More file actions
47 lines (37 loc) · 1.64 KB
/
Copy pathdeck.py
File metadata and controls
47 lines (37 loc) · 1.64 KB
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
from random import shuffle, randint
from card import Card
class Deck:
def __init__(self):
self.cards = self.build_deck()
self.discard_pile = []
self.shuffle(randint(1, 3))
def build_deck(self):
COLOURS = ("red", "green", "yellow", "blue")
NUM_CARD_VALUES = ("1", "2", "3", "4", "5", "6̲", "7", "8", "9̲") * 2 + ("0",) # Operands are used to account for duplicates
ACT_CARD_VALUES = ("⊘", "⇄", "+ 2") * 2
WIL_CARD_VALUES = ("⨁", "+ 4") * 4
full_deck = [Card("NUM", c, v) for c in COLOURS for v in NUM_CARD_VALUES] + \
[Card("ACT", c, v) for c in COLOURS for v in ACT_CARD_VALUES] + \
[Card("WIL", "white", v) for v in WIL_CARD_VALUES] # WILD cards are white, hence built separately
return full_deck
def shuffle(self, number_of_shuffles = 1):
# Shuffles deck a given number of times, defaults to once
for _ in range(number_of_shuffles):
shuffle(self.cards)
def draw(self, count = 1):
drawn_cards = []
for _ in range(count):
if not self.cards:
self.reshuffle_discard_pile()
drawn_cards.append(self.cards.pop())
for card in drawn_cards:
if card.type == "WIL":
card.colour = "white"
return drawn_cards
def reshuffle_discard_pile(self):
# Keeps the top card as the only remaining card in discard pile
self.cards = self.discard_pile[:-1].copy()
self.shuffle(2)
top_card = self.discard_pile[-1]
self.discard_pile.clear()
self.discard_pile.append(top_card)