-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_results.py
49 lines (43 loc) · 1.58 KB
/
plot_results.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
import numpy as np
import matplotlib.pyplot as plt
import argparse as ap
from collections import namedtuple
parser = ap.ArgumentParser(description = "Read the results of a bout between two chess engines and plot some stats.")
parser.add_argument("result_file", type=ap.FileType('r'), help = "A file of the form produced by test_katyusha.py")
parser.add_argument("name1", help="Name of First Engine", default = "Engine 1")
parser.add_argument("name2", help = "Name of Second Engine", default = "Engine 2")
args = parser.parse_args()
f = args.result_file
#Print the descriptions of the engines
for i in xrange(2): print f.readline()
Games = namedtuple('Games', ['won', 'drew', 'lost'])
n_game = 0
#when first player is white
white_res = np.array([0,0,0])
#when first player is black
black_res = np.array([0,0,0])
res = None
while not f.readline() == "":
#determine who is what
l = f.readline()
score = float(f.readline().strip().split()[-1])
score_ind = int(2*score)
n_game += 1
# print l, score
if "White" in l:
#engine 2 is white
black_res[score_ind] += 1
else:
white_res[2-score_ind] += 1
print "First Engine White", white_res
print "Frist Engine Black ", black_res
res = white_res + black_res
fig, ax = plt.subplots()
plt.title(args.name1+" vs "+args.name2)
rects = ax.bar(np.arange(3), res)
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2, 1.01 * height, str(height), ha="center", va="bottom")
ax.set_xticks(np.arange(3)+.4)
ax.set_xticklabels((args.name1+" Won", "Draw", args.name2+" Won"))
plt.show()