-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsgfmill_Test.py
40 lines (32 loc) · 1.2 KB
/
sgfmill_Test.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
from sgfmill import sgf, boards, ascii_boards
import os
# # print 19x19 board
# b = boards.Board(19)
# b.play(16, 15, 'b')
# b.play(3, 3, 'w')
# print(ascii_boards.render_board(b))
path = r".\go_data"
print(path)
for sgf_file in [i for i in os.listdir('.\go_data') if i.endswith('.sgf')]:
with open('.\go_data\\' + sgf_file, "rb") as f:
game = sgf.Sgf_game.from_bytes(f.read())
# Get game attributes
b_player = game.get_player_name("b")
w_player = game.get_player_name("w")
# Ignore games without players' names
if b_player is None or w_player is None:
continue
board_size = game.get_size()
root_node = game.get_root()
b_rank = root_node.get("BR")
w_rank = root_node.get("WR")
result = root_node.get("RE")
print('file name:', sgf_file)
print("Black player:\t", b_player)
print("White player:\t", w_player)
print("Black Rank:\t", b_rank)
print("White Rank:\t", w_rank)
print("result:\t", result)
# List of game sequence
game_sequence = [node.get_move() for node in game.get_main_sequence() if node.get_move()[1] is not None] # get rid of the first none sequence
print(game_sequence)