-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate_game.py
executable file
·49 lines (38 loc) · 1.24 KB
/
simulate_game.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
#!/usr/bin/python3
import play4500
from luzhanqi import LuzhanqiBoard as L
import logging
import coordinates
import sys
board = coordinates.CoordinateSystemState(L.system)
for i, pos in enumerate(L.initial_positions()):
board[pos] = '+' + str(i)
for i, pos in enumerate(L.initial_enemy_positions()):
board[pos] = '-' + str(i)
logging.basicConfig(level=logging.DEBUG,
stream=sys.stdout)
for line in open(sys.argv[1]):
match = play4500.movement_re.match(line)
if not match:
print(line, end='')
continue
start = play4500.parse_coord(match.group(1))
end = play4500.parse_coord(match.group(2))
enemy_move = False
if match.group(3) == sys.argv[2]:
enemy_move = True
start = -start
end = -end
mtype = match.group(4)
if mtype == 'move' or mtype == 'win':
board[end] = board[start]
board[start] = None
elif mtype == 'loss':
board[start] = None
elif mtype == 'tie':
board[start] = None
board[end] = None
print('{} {} {} {}'.format(start, end, match.group(3), match.group(4)))
markers = {pos: board[pos] for pos in board
if board[pos] is not None}
L.log_board_with_markers(markers)