-
Notifications
You must be signed in to change notification settings - Fork 4
/
deck.py
48 lines (37 loc) · 1.19 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
40
41
42
43
44
45
46
47
48
# Class representing a deck in Magic the Gathering
import numpy.random as r
class Deck:
cards = None
def __init__(self):
self.cards = []
def draw_hand(self, num = 7):
""" Draws and returns the top 7 cards in the deck. Cards are removed
from the deck
"""
hand = []
for i in range(num):
hand.append(self.draw())
return hand
def peep(self,num = 7):
""" Looks at the first 'num' cards at the top of the deck. The cards are
not removed from the deck
"""
return self.cards[-num:]
def draw(self):
""" Draws a single card from the top of the deck
"""
return self.cards.pop()
def take_bottom_card(self):
return self.cards.pop(0)
def add_card(self, card):
self.cards.append(card)
def add_card_to_bottom(self, card):
self.cards.insert(0, card)
def clear(self):
""" Empties the deck
"""
del self.cards[:]
def size(self):
return len(self.cards)
def shuffle(self):
r.shuffle(self.cards)