-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.py
140 lines (108 loc) · 3.78 KB
/
cli.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
from os import system
from quantumwerewolf import Game
def ask_yesno(query, yes, no):
answer = input(query + ' (yes/no) ')
if answer == 'yes' or answer == 'y':
if isinstance(yes, str):
print(yes)
else:
yes()
elif answer == 'no' or answer == 'n':
if isinstance(no, str):
print(no)
else:
no()
else:
print('invalid answer')
ask_yesno(query, yes, no)
def ask_player(query):
answer = input(query + ' Name: ')
if answer in g.players and g.killed[g.ID(answer)] == 0:
return answer
else:
print(' "{}" is not a living player'.format(answer))
print(' Players alive are:')
for i, p in enumerate(g.players):
if g.killed[i] == 0:
print(" {}".format(p))
return ask_player(query)
if __name__ == "__main__":
g = Game()
system('clear')
print("Enter player name(s) separated by spaces.")
print("Enter no name to continue.")
# Get player names
new_player = True
while new_player:
names = input(" Name(s): ")
if names != '':
g.add_players(names.split())
else:
new_player = False
system('clear')
print("Current Players:")
for i, p in enumerate(g.players):
print(" {}: {}".format(i+1,p))
# Set the deck
print("\nPlay with following roles?")
for (role, count) in g.role_count.items():
if count == 1:
suffix = ''
else:
suffix = 's'
print(" {} {}{}".format(count, role, suffix))
def set_role(role, amount):
def set_seer_value():
g.set_role(role, amount)
return set_seer_value
def ask_roles():
# ask for new roles
g.role_count['werewolf'] = int(input('\nNumber of werewolves: '))
ask_yesno('Include seer?', set_role('seer',1), set_role('seer',0))
ask_yesno('', "roles confirmed!", ask_roles)
system('clear')
# Start game
g.start()
# loop turns for every player
turn_counter = 0
while g.started == True:
turn_counter += 1
# night
system('clear')
print('Night falls and all players take their actions in turns privately\n')
start_probabilities = g.probs
for i, p in enumerate(g.players):
if g.killed[i] == 1:
continue
input("{}'s turn (press ENTER to continue)".format(p))
system('clear')
print("{}'s turn".format(p))
# display game and player info (role superposition)
player_probabilities = start_probabilities[i]
print('\n Your role:')
print(" Villager: {:3.0f}%".format(100*player_probabilities['villager']))
print(" Seer: {:3.0f}%".format(100*player_probabilities['seer']))
print(" werewolf: {:3.0f}%\n".format(100*player_probabilities['werewolf']))
# seer
if player_probabilities['seer'] != 0:
target = ask_player(' SEER: Whose role do you inspect?\n ')
g.seer(p,target)
# werewolf
if player_probabilities['werewolf'] != 0:
target = ask_player(' WEREWOLF: Who do you attack?\n ')
g.werewolf(p,target)
input("\n(press ENTER to continue)")
system('clear')
# day
input('All player have had their turn (press ENTER to continue)')
system('clear')
print('The day begins')
g.print_probabilities()
# vote
target = ask_player('\nWHOLE VILLAGE: Who do you lynch?\n ')
g.kill(target)
input('(press ENTER to continue)')
# check win
if g.check_win():
print("Game over")
break