forked from INF142/team-local-tactics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team-local-tactics.py
127 lines (97 loc) · 3.77 KB
/
team-local-tactics.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
from rich import print
from rich.prompt import Prompt
from rich.table import Table
from champlistloader import load_some_champs
from core import Champion, Match, Shape, Team
def print_available_champs(champions: dict[Champion]) -> None:
# Create a table containing available champions
available_champs = Table(title='Available champions')
# Add the columns Name, probability of rock, probability of paper and
# probability of scissors
available_champs.add_column("Name", style="cyan", no_wrap=True)
available_champs.add_column("prob(:raised_fist-emoji:)", justify="center")
available_champs.add_column("prob(:raised_hand-emoji:)", justify="center")
available_champs.add_column("prob(:victory_hand-emoji:)", justify="center")
# Populate the table
for champion in champions.values():
available_champs.add_row(*champion.str_tuple)
print(available_champs)
def input_champion(prompt: str,
color: str,
champions: dict[Champion],
player1: list[str],
player2: list[str]) -> None:
# Prompt the player to choose a champion and provide the reason why
# certain champion cannot be selected
while True:
match Prompt.ask(f'[{color}]{prompt}'):
case name if name not in champions:
print(f'The champion {name} is not available. Try again.')
case name if name in player1:
print(f'{name} is already in your team. Try again.')
case name if name in player2:
print(f'{name} is in the enemy team. Try again.')
case _:
player1.append(name)
break
def print_match_summary(match: Match) -> None:
EMOJI = {
Shape.ROCK: ':raised_fist-emoji:',
Shape.PAPER: ':raised_hand-emoji:',
Shape.SCISSORS: ':victory_hand-emoji:'
}
# For each round print a table with the results
for index, round in enumerate(match.rounds):
# Create a table containing the results of the round
round_summary = Table(title=f'Round {index+1}')
# Add columns for each team
round_summary.add_column("Red",
style="red",
no_wrap=True)
round_summary.add_column("Blue",
style="blue",
no_wrap=True)
# Populate the table
for key in round:
red, blue = key.split(', ')
round_summary.add_row(f'{red} {EMOJI[round[key].red]}',
f'{blue} {EMOJI[round[key].blue]}')
print(round_summary)
print('\n')
# Print the score
red_score, blue_score = match.score
print(f'Red: {red_score}\n'
f'Blue: {blue_score}')
# Print the winner
if red_score > blue_score:
print('\n[red]Red victory! :grin:')
elif red_score < blue_score:
print('\n[blue]Blue victory! :grin:')
else:
print('\nDraw :expressionless:')
def main() -> None:
print('\n'
'Welcome to [bold yellow]Team Local Tactics[/bold yellow]!'
'\n'
'Each player choose a champion each time.'
'\n')
champions = load_some_champs()
print_available_champs(champions)
print('\n')
player1 = []
player2 = []
# Champion selection
for _ in range(2):
input_champion('Player 1', 'red', champions, player1, player2)
input_champion('Player 2', 'blue', champions, player2, player1)
print('\n')
# Match
match = Match(
Team([champions[name] for name in player1]),
Team([champions[name] for name in player2])
)
match.play()
# Print a summary
print_match_summary(match)
if __name__ == '__main__':
main()