-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.py
428 lines (388 loc) · 13 KB
/
agent.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
from twilio.rest import Client
import random
import time
import copy
# +14155238886
# join prove-serious
# client credentials are read from TWILIO_ACCOUNT_SID and AUTH_TOKEN
client = Client(
"AC694a0a1bb4494297124460beb33a165a", "31e0622e6a8327b63f44201e8791b1f6"
)
win_condition = []
def send_info(number, message):
# this is the Twilio sandbox testing number
from_whatsapp_number = "whatsapp:+14155238886"
# replace this number with your own WhatsApp Messaging number
to_whatsapp_number = "whatsapp:" + number
client.messages.create(
body=message, from_=from_whatsapp_number, to=to_whatsapp_number
)
# print(message)
class player:
def __init__(self, name, number, role, job):
self.name = name
self.number = number
self.role = role
self.job = job
def grudge(player, players):
global win_condition
print(
player.name,
" can get a new win condition, switch sides, or just simply gain information about another player.",
)
temporary = copy.deepcopy(players)
random.shuffle(temporary)
if temporary[0].name == player.name:
player2 = temporary[1]
else:
player2 = temporary[0]
message = (
"You now have a grudge against "
+ player2.name
+ ". You will only win if he/she dies."
)
send_info(player.number, message)
win_condition.append(["grudge", player.name, player2.name])
def infatutation(player, players):
global win_condition
temporary = copy.deepcopy(players)
print(
player.name,
" can get a new win condition, switch sides, or just simply gain information about another player.",
)
random.shuffle(temporary)
if temporary[0].name == player.name:
player2 = temporary[1]
else:
player2 = temporary[0]
message = (
"You now feel a lot of love for "
+ player2.name
+ ". You will only win if he/she survives"
)
send_info(player.number, message)
# print(message)
win_condition.append(["infatuation", player.name, player2.name])
def scapegoat(player, players):
global win_condition
print(
player.name,
" can get a new win condition, switch sides, or just simply gain information about another player.",
)
message = "You are now the scapegoat. You win if you get imprisoned. ONLY you win."
send_info(player.number, message)
# print(message)
win_condition.append(["scapegoat", player.name])
def switch(player, players):
print(
player.name,
" can get a new win condition, switch sides, or just simply gain information about another player.",
)
if player.role == "virus":
player.role = "service"
old = "virus"
new = "service"
else:
player.role = "virus"
old = "service"
new = "virus"
message = "You were " + old + ", but you are now " + new + ";)"
send_info(player.number, message)
# print(message)
def info(player, players):
temporary = copy.deepcopy(players)
print(
player.name,
" can get a new win condition, switch sides, or just simply gain information about another player.",
)
random.shuffle(temporary)
if temporary[0].name == player.name:
message = temporary[1].name + " works for " + temporary[1].role
else:
message = temporary[0].name + " works for " + temporary[0].role
send_info(player.number, message)
# print(message)
def photograph(player, players):
temporary = copy.deepcopy(players)
print(
player.name,
" has seen a photograph of two people and know they work for same agency.",
)
random.shuffle(temporary)
i = 1
# comment this if there are only 2 virus::::::
if len(players) > 6:
for t in temporary:
if t.name == player.name:
temporary.remove(t)
break
while temporary[i].role != temporary[0].role:
i += 1
player2 = temporary[i]
player1 = temporary[0]
message = (
"Right now, "
+ player1.name
+ " and "
+ player2.name
+ " work for the same agency."
)
send_info(player.number, message)
# print(message)
def reveal(player, players):
temporary = copy.deepcopy(players)
print(player.name, " is going to know the agency of another player.")
for t in temporary:
if t.name == player.name:
temporary.remove(t)
player1 = temporary[0]
message = "Right now, " + player1.name + " is working for " + player1.role
send_info(player.number, message)
# print(message)
def intelligence(player, players):
temporary = copy.deepcopy(players)
# comment this if there are only 2 virus::::::
if len(players) > 6:
for t in temporary:
if t.name == player.name:
temporary.remove(t)
break
print(player.name, " will get 2 names, one is virus and one is not.")
for p in temporary:
if p.role == "service":
player1 = p.name
break
for p in temporary:
if p.role == "virus":
player2 = p.name
break
message = (
player1
+ " and "
+ player2
+ " are the two names. One is Virus, One is service."
)
send_info(player.number, message)
# print(message)
def confession(player, players):
temporary = copy.deepcopy(players)
print(player.name, "must show one player who they are working for.")
name = input("Enter that players name:")
for p in temporary:
if p.name == name:
message = player.name + " works for " + player.role
send_info(p.number, message)
# print(message)
return
def choose_two(player, players):
temporary = copy.deepcopy(players)
print(
player.name, "must choose two agents. They will know if one of them is virus."
)
name1 = input("Enter first name:")
name2 = input("Enter second name:")
for p in temporary:
if p.name == name1 or p.name == name2:
if p.role == "virus":
message = "One of " + name1 + " and " + name2 + " is virus"
send_info(player.number, message)
# print(message)
return
else:
pass
message = "Both " + name1 + " and " + name2 + " are service"
send_info(player.number, message)
# print(message)
def dojob(player, players):
j = player.job
if j == 1:
photograph(player, players)
elif j == 2:
reveal(player, players)
elif j == 3:
intelligence(player, players)
elif j == 4:
confession(player, players)
elif j == 5:
choose_two(player, players)
elif j == 6:
grudge(player, players)
elif j == 7:
infatutation(player, players)
elif j == 8:
scapegoat(player, players)
elif j == 9:
switch(player, players)
else:
info(player, players)
return
def find_role(name, players):
for player in players:
if player.name == name:
return player.role
def remove_player(name, players):
for player in players:
if player.name == name:
players.remove(player)
return
def print_result(lynched, players):
global win_condition
win_list = []
if win_condition == []:
print("Nobody got a win condition.")
else:
for condition in win_condition:
if condition[0] == "scapegoat":
print(condition[1], "was a scapegoat.")
if lynched == condition[1]:
print(lynched, " wins!")
return
else:
remove_player(condition[1], players)
for condition in win_condition:
if condition[0] == "infatuation":
print(condition[1], "was in love with", condition[2])
if lynched != condition[2]:
win_list.append(condition[1])
else:
remove_player(condition[1], players)
if condition[0] == "grudge":
print(condition[1], "had a grudge against", condition[2])
if lynched == condition[2]:
win_list.append(condition[1])
else:
remove_player(condition[1], players)
role = find_role(lynched, players)
for player in players:
if player.role != role:
win_list.append(player.name)
win_list = set(win_list)
print("Winners are:")
for player in players:
if player.name in win_list:
print(player.name, player.role)
return
if __name__ == "__main__":
cont = input("Press enter to continue")
print("Starting game......")
fptr = open("info.txt", "r")
f1 = fptr.readlines()
players_number = int(f1[0])
names = []
players = []
role = []
numbers = []
ind = 1
for _ in range(players_number):
names.append(f1[ind].strip("\n"))
ind += 1
for _ in range(players_number):
numbers.append(f1[ind].strip("\n"))
ind += 1
v = int(f1[ind].strip("\n"))
ind += 1
s = int(f1[ind].strip("\n"))
count = 0
for _ in range(v):
role.append("virus")
for _ in range(s):
role.append("service")
random.shuffle(role)
# to remove win condition comment this:::::::::::
if players_number > 5:
jobs = [0, 1, 2, 3, 4, 5]
else:
jobs = [1, 2, 3, 4, 5]
hidden = [6, 7, 8, 9, 10]
random.shuffle(jobs)
random.shuffle(hidden)
index = 0
extra = 0
for _ in range(players_number):
# name=input('Enter name of player:')
# number=input('Enter number:')
name = names.pop()
number = numbers.pop()
if _ > 5:
job = jobs[extra]
extra += 1
else:
job = jobs[_]
if job == 0:
job = hidden[0]
random.shuffle(hidden)
players.append(player(name, number, role.pop(), job))
index += 1
random.shuffle(players)
viruses = []
for player in players:
if player.role == "virus":
viruses.append(player)
for player in players:
if player.role == "service":
message = (
"Welcome to Deception!\n You are working for "
+ player.role
+ ".\n Your mission is to find all the V.I.R.U.S Agents."
)
send_info(player.number, message)
else:
message = (
"Welcome to Deception!\n You are working for "
+ player.role
+ ".\n Your team is:\n"
)
for v in viruses:
message += v.name
message += "\n"
message += "All the best!"
send_info(player.number, message)
cont = input("Sent roles to everyone, press enter to continue.")
for player in players:
dojob(player, players)
print()
cont = input("Press enter to continue")
lynched = input("Who did you vote:")
print("")
print_result(lynched, players)
# print(win_condition)
# if win_condition[0] == "normal":
# for player in players:
# if lynched == player.name:
# if player.role == "service":
# print("V.I.R.U.S wins!")
# break
# else:
# print("Service wins!")
# break
# elif win_condition[0] == "scapegoat":
# if lynched == win_condition[1]:
# print(lynched, "wins!")
# else:
# for player in players:
# if lynched == player.name:
# if player.role == "service":
# print("V.I.R.U.S wins!")
# break
# else:
# print("Service wins!")
# break
# if win_condition[0] == "infatuation":
# if lynched == win_condition[2]:
# print(win_condition[1], " loses as he/she was in love with", lynched)
# else:
# print(
# win_condition[1],
# " wins as he/she was in love with",
# win_condition[2],
# )
# if win_condition[0] == "grudge":
# if lynched != win_condition[2]:
# print(win_condition[1], " loses as he/she had grudge with", lynched)
# else:
# print(win_condition[1], " wins as he/she had grudge with", lynched)
# print("win_condition variable is", win_condition)
# for player in players:
# print(player.name, player.role)
fptr.close()
# time.sleep(100)