-
Notifications
You must be signed in to change notification settings - Fork 0
/
pile.py
49 lines (35 loc) · 1.19 KB
/
pile.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
import random
from card import Card, CardType
class Pile:
def __init__(self, cards):
self.cards = cards
def __getitem__(self, key):
return self.cards[key]
def __str__(self):
representation = f'Pile with {len(self.cards)} cards:\n'
for card in self.cards:
representation += f'{card}\n'
return representation
@staticmethod
def from_config_file(path_to_file):
new_cards = [
Card(None, CardType.WILDCARD),
Card(None, CardType.WILDCARD)
]
with open(path_to_file) as f:
card_count = int(f.readline().strip())
for _ in range(card_count):
territory = f.readline().strip()
card_type = f.readline().strip()
new_cards.append(Card(territory, CardType[card_type]))
return Pile(new_cards)
def shuffle(self):
random.shuffle(self.cards)
def remove_card(self, card):
self.cards.remove(card)
def remove_card_with_index(self, index):
self.cards.remove(self.cards[index])
def add_card(self, card):
self.cards.append(card)
def draw_card(self):
return self.cards.pop(0)