-
Notifications
You must be signed in to change notification settings - Fork 8
/
annotations.py
101 lines (83 loc) · 3.91 KB
/
annotations.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from sgflib import Property
from utils import convert_position, is_pass
def format_winrate(stats, move_list, board_size, next_game_move):
comment = ""
if 'winrate' in stats:
comment += "Overall black win%%: %.2f%%\n" % (stats['winrate'] * 100)
else:
comment += "Overall black win%: not computed (Leela still in opening book)\n"
if len(move_list) > 0 and move_list[0]['pos'] != next_game_move:
comment += "Leela's preferred next move: %s\n" % convert_position(board_size, move_list[0]['pos'])
else:
comment += "\n"
return comment
def format_delta_info(delta, this_move, board_size):
comment = ""
LB_values = []
if delta <= -0.2:
comment += "=================================\n"
comment += "Leela thinks %s is a big mistake!\n" % convert_position(board_size, this_move)
comment += "Winning percentage drops by %.2f%%!\n" % (-delta * 100)
comment += "=================================\n"
if not is_pass(board_size, this_move):
LB_values.append("%s:%s" % (this_move, "?"))
elif delta <= -0.1:
comment += "=================================\n"
comment += "Leela thinks %s is a mistake!\n" % convert_position(board_size, this_move)
comment += "Winning percentage drops by %.2f%%\n" % (-delta * 100)
comment += "=================================\n"
if not is_pass(board_size, this_move):
LB_values.append("%s:%s" % (this_move, "?"))
elif delta <= -0.05:
comment += "=================================\n"
comment += "Leela thinks %s is not the best choice.\n" % convert_position(board_size, this_move)
comment += "Winning percentage drops by %.2f%%\n" % (-delta * 100)
comment += "=================================\n"
if not is_pass(board_size, this_move):
LB_values.append("%s:%s" % (this_move, "?"))
elif delta <= -0.025:
comment += "=================================\n"
comment += "Leela slightly dislikes %s.\n" % convert_position(board_size, this_move)
comment += "=================================\n"
comment += "\n"
return comment, LB_values
def flip_winrate(wr, color):
return (1.0 - wr) if color == "white" else wr
def format_analysis(stats, move_list, this_move, board_size):
abet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
comment = ""
if 'bookmoves' in stats:
comment += "==========================\n"
comment += "Considered %d/%d bookmoves\n" % (stats['bookmoves'], stats['positions'])
else:
comment += "==========================\n"
comment += "Visited %d nodes\n" % (stats['visits'])
comment += "\n"
for move_label, move in list(zip(abet, move_list)):
comment += "%s -> Win%%: %.2f%% (%d visits) \n" \
% (move_label, flip_winrate(move['winrate'], move['color']) * 100, move['visits'])
# Check for pos being "" or "tt", values which indicate passes, and don't attempt to display markers for them
LB_values = ["%s:%s" % (mv['pos'], L) for L, mv in zip(abet, move_list) if mv['pos'] != "" and mv['pos'] != "tt"]
mvs = [mv['pos'] for mv in move_list]
if this_move not in mvs and this_move is not None and not is_pass(board_size, this_move):
TR_values = [this_move]
else:
TR_values = []
return comment, LB_values, TR_values
def annotate_sgf(cursor, comment, LB_values, TR_values):
c_node = cursor.node
if comment:
if 'C' in c_node:
c_node['C'].data[0] += comment
else:
c_node.add_property(Property('C', [comment]))
if LB_values:
if 'LB' in c_node:
c_node['LB'].extend(LB_values)
else:
c_node.add_property(Property('LB', LB_values))
if TR_values:
if 'TR' in c_node:
c_node['TR'].extend(TR_values)
else:
c_node.add_property(Property('TR', TR_values))