-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample-bot.py
39 lines (32 loc) · 962 Bytes
/
example-bot.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
import json
import sys
import random
END_OF_TRANSMISSION = "EOT"
FINISHED_TOKEN = "FINISHED"
def get_game_state():
data = ''
while (data_fraction := input()) != END_OF_TRANSMISSION:
data += data_fraction
if data.startswith(FINISHED_TOKEN):
# Game is over
_, winner, reason, context = data.split(' ', 3)
return (winner, reason, context), True
return json.loads(data), False
def get_patrons_to_pick():
data = input()
patrons, round_nr = data.split()
patrons = patrons.split(',')
return patrons, round_nr
def debug(msg):
print(msg, file=sys.stderr)
if __name__ == '__main__':
for _ in range(2):
patrons, round_nr = get_patrons_to_pick()
debug(f'Received: {patrons} in round {round_nr}')
print(random.choice(patrons))
while True:
data, finished = get_game_state()
if finished:
debug(data)
break
print('ENDTURN')