-
Notifications
You must be signed in to change notification settings - Fork 16
/
Trick.py
51 lines (42 loc) · 1.12 KB
/
Trick.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
50
51
from Card import Card, Suit
hearts = 3 # the corresponding index to the suit hearts
spades = 2
queen = 12
class Trick:
def __init__(self):
self.trick = [0, 0, 0, 0]
self.suit = Suit(-1)
self.cardsInTrick = 0
self.points = 0
self.highest = 0 # rank of the high trump suit card in hand
self.winner = -1
def reset(self):
self.trick = [0, 0, 0, 0]
self.suit = -1
self.cardsInTrick = 0
self.points = 0
self.highest = 0
self.winner = -1
# def cardsInTrick(self):
# count = 0
# for card in self.trick:
# if card is not 0:
# count += 1
# return count
def setTrickSuit(self, card):
self.suit = card.suit
def addCard(self, card, index):
if self.cardsInTrick == 0: # if this is the first card added, set the trick suit
self.setTrickSuit(card)
print 'Current trick suit:', self.suit
self.trick[index] = card
self.cardsInTrick += 1
if card.suit == Suit(hearts):
self.points += 1
elif card == Card(queen, spades):
self.points += 13
if card.suit == self.suit:
if card.rank.rank > self.highest:
self.highest = card.rank.rank
self.winner = index
print "Highest:",self.highest