-
Notifications
You must be signed in to change notification settings - Fork 0
/
sueca_scorer.py
98 lines (75 loc) · 2.73 KB
/
sueca_scorer.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
import sueca_suits_ranks as sr
import sueca_cards as sc
import sueca_tricks as st
import sueca_games as sg
class SuecaGameIncomplete(Exception):
pass
class GameFileCouldNotBeFound(Exception):
pass
def runGame(fname, showCards = False, showGame = False):
try:
tc, ts = st.parseGameFile(fname)
g = sg.Game(tc)
except FileNotFoundError:
raise GameFileCouldNotBeFound(f"Could not find the game file '{fname}'")
if len(ts) < 10:
raise SuecaGameIncomplete(f"Game file '{fname}' is incomplete. A complete game takes 10 rounds; the given game includes {len(ts)} rounds only.")
for t in ts:
g.playTrick(t)
score = list(g.score())
all_cards = []
for i in range(4):
for card in g.cardsOf(i+1):
all_cards.append(card.show())
player1 = all_cards[:10]
player2 = all_cards[10:20]
player3 = all_cards[20:30]
player4 = all_cards[30:40]
final_cards = []
final_cards.append(player1)
final_cards.append(player2)
final_cards.append(player3)
final_cards.append(player4)
final_cards_str = []
for i in range(len(final_cards)):
final_cards_str.append(f"Player {i+1}: {', '.join(final_cards[i])}")
a = []
for i in range(10):
a.append(g.gameTricks()[i].show())
if score[0] > score[1]:
winner = f"Pair A won the given sueca game\nScore: {score[0]} - {score[1]}"
elif score[0] == score[1]:
winner = f"The game resulted in a draw\nScore: {score[0]} - {score[1]}"
else:
winner = f"Pair B won the given sueca game\nScore: {score[0]} - {score[1]}"
if showCards == False and showGame == False:
print(winner)
elif showCards == True and showGame == False:
print(winner)
print("Player's cards in the sueca game")
for i in final_cards_str:
print(i)
elif showCards == False and showGame == True:
output = []
output.append(winner)
trump = g.gameTrump().show()
trump_name = sr.suit_full_name(trump)
output.append(f"Trump: {trump} - {trump_name}")
for i in range(len(a)):
output.append(f"{i+1}: {a[i]}")
for o in output:
print(o)
else:
print(winner)
output = []
trump = g.gameTrump().show()
trump_name = sr.suit_full_name(trump)
print(f"Trump: {trump} - {trump_name}")
print("Player's cards in the sueca game")
for i in final_cards_str:
print(i)
output = []
for i in range(len(a)):
output.append(f"{i+1}: {a[i]}")
for o in output:
print(o)