-
Notifications
You must be signed in to change notification settings - Fork 0
/
sueca_games.py
142 lines (111 loc) · 4.82 KB
/
sueca_games.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import sueca_cards as sc
import sueca_tricks as st
class CardAlreadyPlayed(Exception):
pass
class DealerDoesNotHoldTrumpCard(Exception):
pass
class IllegalCardPlayed(Exception):
pass
class Game:
def __init__(self, game):
self.game = game
self.score1 = 0
self.score2 = 0
self.player1pos = 1
self.player2pos = 2
self.player3pos = 3
self.player4pos = 4
self.player1card = []
self.player2card = []
self.player3card = []
self.player4card = []
self.player1pcard = []
self.player2pcard = []
self.player3pcard = []
self.player4pcard = []
self.duplicate_card_tracker = []
self.tricks = []
def gameTrump(self):
card = self.game.show()
return sc.Card(card)
def score(self):
return (self.score1, self.score2)
def playTrick(self, t):
trick_str = t.show()
trick_obj = st.Trick(trick_str)
playedTrick = trick_obj.trick_winner(self.game.show()[-1])
self.tricks.append(trick_obj)
if playedTrick == self.player1pos:
cards_in_trick = trick_str.split(" ")
self.player1card.append(cards_in_trick[self.player1pos - 1])
self.player2card.append(cards_in_trick[self.player2pos - 1])
self.player3card.append(cards_in_trick[self.player3pos - 1])
self.player4card.append(cards_in_trick[self.player4pos - 1])
self.player1pos = 1
self.player2pos = 2
self.player3pos = 3
self.player4pos = 4
self.score1 += trick_obj.points()
elif playedTrick == self.player2pos:
cards_in_trick = trick_str.split(" ")
self.player1card.append(cards_in_trick[self.player1pos - 1])
self.player2card.append(cards_in_trick[self.player2pos - 1])
self.player3card.append(cards_in_trick[self.player3pos - 1])
self.player4card.append(cards_in_trick[self.player4pos - 1])
self.player1pos = 4
self.player2pos = 1
self.player3pos = 2
self.player4pos = 3
self.score2 += trick_obj.points()
elif playedTrick == self.player3pos:
cards_in_trick = trick_str.split(" ")
self.player1card.append(cards_in_trick[self.player1pos - 1])
self.player2card.append(cards_in_trick[self.player2pos - 1])
self.player3card.append(cards_in_trick[self.player3pos - 1])
self.player4card.append(cards_in_trick[self.player4pos - 1])
self.player1pos = 3
self.player2pos = 4
self.player3pos = 1
self.player4pos = 2
self.score1 += trick_obj.points()
elif playedTrick == self.player4pos:
cards_in_trick = trick_str.split(" ")
self.player1card.append(cards_in_trick[self.player1pos - 1])
self.player2card.append(cards_in_trick[self.player2pos - 1])
self.player3card.append(cards_in_trick[self.player3pos - 1])
self.player4card.append(cards_in_trick[self.player4pos - 1])
self.player1pos = 2
self.player2pos = 3
self.player3pos = 4
self.player4pos = 1
self.score2 += trick_obj.points()
if len(self.player4card) == 10:
if self.game.show() not in self.player2card:
raise DealerDoesNotHoldTrumpCard(f"Player 2 (dealer) does not hold the trump card {self.game.show()}")
for card in self.player1card:
self.player1pcard.append(sc.Card(card))
for card in self.player2card:
self.player2pcard.append(sc.Card(card))
for card in self.player3card:
self.player3pcard.append(sc.Card(card))
for card in self.player4card:
self.player4pcard.append(sc.Card(card))
tracker_helper = trick_str.split(" ")
for card in tracker_helper:
self.duplicate_card_tracker.append(card)
if len(self.duplicate_card_tracker) != len(set(self.duplicate_card_tracker)):
raise CardAlreadyPlayed("A duplicate card was played")
def cardsOf(self, p):
if p > 4:
raise ValueError(f"Invalid player number: {p}")
else:
if p == 1:
return self.player1pcard
elif p == 2:
return self.player2pcard
elif p == 3:
return self.player3pcard
elif p == 4:
return self.player4pcard
def gameTricks(self):
return self.tricks