-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.py
42 lines (32 loc) · 1.17 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
from collections import defaultdict
class Deck:
def __init__(self, cards):
self.randomized_cards=defaultdict(int)
self.total_cards=len(cards)
for c in cards:
self.randomized_cards[c] += 1
def get_total_cards(self):
return self.total_cards
def clear(self):
self.randomized_cards.clear()
self.total_cards=0
def shuffle(self):
# nothing to do for now we currently only support randomized cards
pass
#TODO: later support unrandomized cards in the deck
# effectively this function just shuffles it in for now
def put_card_on_bottom(self,card):
self.total_cards += 1
self.randomized_cards[card] += 1
#TODO: support draw card top and bottom
def draw_card(self,card):
if card in self.randomized_cards:
self.total_cards -= 1
self.randomized_cards[card] -= 1
if self.randomized_cards[card] == 0:
del self.randomized_cards[card]
def get_card_choices(self):
result=dict()
for card,quantity in self.randomized_cards.items():
result[card] = quantity
return result