Last active
January 26, 2018 13:22
-
-
Save hiropppe/ad3f9ec393976cc0e2f20edc943d0e81 to your computer and use it in GitHub Desktop.
Simple python script which prints player winning ratio from gogui-twogtp result sgf files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
import re | |
import sys | |
from collections import defaultdict | |
is_alternate_game = False | |
if len(sys.argv) > 1: | |
is_alternate_game = sys.argv[1] in ('--alternate', '-a') | |
n_games = 0 | |
n_unknown = 0 | |
player = {} | |
winner = defaultdict(int) | |
for line in sys.stdin: | |
pb = re.findall(r'(?:\bPB\[(.+?)\])', line) | |
pw = re.findall(r'(?:\bPW\[(.+?)\])', line) | |
result = re.findall(r'(?:\bRE\[(.+?)\])', line) | |
if pb and (is_alternate_game is False or 'B' not in player): | |
player['B'] = pb[0] | |
if pw and (is_alternate_game is False or 'W' not in player): | |
player['W'] = pw[0] | |
if result: | |
n_games += 1 | |
if 'B' == result[0][0].upper(): | |
winner[player['B']] += 1 | |
elif 'W' == result[0][0].upper(): | |
winner[player['W']] += 1 | |
else: | |
n_unknown += 1 | |
for p in player.values(): | |
sys.stdout.write('[{:s}] {:3.2f} % ({:d}/{:d})\n'.format( | |
p, winner[p]*100/n_games, winner[p], n_games)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment