def prior_knowledge_stat(self, board, root, color): s_color = GoBoardUtilGo4.int_to_color(color) stats = [] for move, node in root._children.items(): if color == BLACK: wins = node._black_wins else: wins = node._n_visits - node._black_wins visits = node._n_visits if visits: win_rate = round(float(wins) / visits, 2) else: win_rate = 0 if move == PASS: move = None pointString = board.point_to_string(move) stats.append((pointString, wins, visits, win_rate)) lst = sorted(stats, key=lambda i: i[3], reverse=True) master = [] for stuff in lst: x = len(stuff) - 1 # print(stuff[0:x]) rnum = int(round(stuff[2])) # print(int(round(stuff[2]))) lst1 = [stuff[0], stuff[1], rnum] master.append(lst1) #sys.stderr.write("Sstatistics: {} \n".format(lst)) sys.stderr.flush() return master
def print_stat(self, board, root, color): s_color = GoBoardUtilGo4.int_to_color(color) sys.stderr.write("Number of children {} \n".format(len( root._children))) sys.stderr.flush() sys.stderr.write("Number of roots visits: {} \n".format( root._n_visits)) sys.stderr.flush() stats = [] for move, node in root._children.items(): if color == BLACK: wins = node._black_wins else: wins = node._n_visits - node._black_wins visits = node._n_visits if visits: win_rate = round(float(wins) / visits, 2) else: win_rate = 0 if move == PASS: move = None pointString = board.point_to_string(move) stats.append((pointString, win_rate, wins, visits)) sys.stderr.write("Statistics: {} \n".format( sorted(stats, key=lambda i: i[3], reverse=True))) sys.stderr.flush()