-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (57 loc) · 1.81 KB
/
main.py
File metadata and controls
80 lines (57 loc) · 1.81 KB
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
import random
from typing import List, Tuple
import json
from coding.game import Game
players = [
'Micheál',
'Melissa',
]
def get_input(choices: List[Tuple]):
all_tiles = set()
all_commands = set()
all_lines = set()
for command, lines, tiles in choices:
all_lines |= set(lines)
all_commands.add(command)
all_tiles |= set(tiles)
# tile_list = ', '.join([f'{t.var} ({t.id})' for t in tiles])
#
# print(f"{command} ({command.id})")
# f" lines: {str(lines)[1:-1]}\n"
# f" tiles: {tile_list}")
print(str(all_lines)[1:-1])
print(', '.join([f"{c[0]} ({c[0].id})" for c in choices]))
print(', '.join([f'{t.var} ({t.id})' for t in all_tiles]))
while True:
line = int(input('line: '))
cmd_id = int(input('command: '))
tile_id = int(input('tile: '))
try:
command = [c for c in all_commands if c.id == cmd_id][0]
tile = [t for t in all_tiles if t.id == tile_id][0]
break
except (IndexError, ValueError):
pass
return line, command, tile
def random_choice(choices: List[Tuple]):
choice = random.choice(choices)
command = choice[0]
line = random.choice(choice[1])
tile = random.choice(choice[2])
# print(f'Choice: {line:3} {command} --> {tile}')
return line, command, tile
def main():
commands = json.load(open('commands.json'))
game = Game(commands)
generator = game.run_game(players)
choices = generator.send(None)
while choices:
# for line in game.list_code():
# print(line)
response = random_choice(choices)
try:
choices = generator.send(response)
except StopIteration:
break
if __name__ == "__main__":
main()