-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_sgf.py
More file actions
56 lines (48 loc) · 1.11 KB
/
parse_sgf.py
File metadata and controls
56 lines (48 loc) · 1.11 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
import sys
import copy
from game_logic import Board
from MCTS import MCTS
if len(sys.argv) == 1:
sys.exit()
file = sys.argv[1]
ins = open(file, "r")
for i in ins:
if i in ['\n', '\r\n']:
break
board = Board()
ai = MCTS()
next_player = 2
for i in ins:
if i[0] != ';':
break
print(i)
player = 1
if i[1] == 'B':
player = 2
next_player = 1
else:
next_player = 2
x = i[i.index('[')+1]
y = i[i.index(']')-1]
#board.grid[ord(y)-97][ord(x)-97] = player
board.update_board(ord(x)-97, ord(y)-97, player)
for i in range(19):
for j in range(19):
print(board.grid[i][j], end=' ')
print()
b = ai.find_next_move(copy.deepcopy(board), next_player)
move = ";"
if next_player == 1:
move += "W["
else:
move += "B["
coord = b.move_history[len(b.move_history)-1]
move += chr(coord[0]+97)+chr(coord[1]+97)+']'
print("NEW BOARD\n~~~~~~~~")
for i in range(19):
for j in range(19):
#if board.grid[i][j] != b.grid[i][j]:
#move += chr(j+97)+chr(i+97)+']'
print(b.grid[i][j], end=' ')
print()
print('\n'+move)