-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval_n.py
77 lines (55 loc) · 1.83 KB
/
eval_n.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
import chess.pgn
import chess
import pystockfish
import os, sys
import random
from djeval import *
# must be run from contest_* image, not from scoreserver, because it uses pandas
def mean(foo):
return sum(foo) / len(foo)
def describe_movescores(ms):
# https://github.com/ornicar/lila/blob/master/modules/analyse/src/main/Advice.scala#L44-L47
print "Avg cp loss: ", mean(ms)
print "Inaccuracies: ", sum((ms > -100) & (ms <= -50))
print "Mistakes: ", sum((ms > -300) & (ms <= -100))
print "Blunders: ", sum( (ms <= -300))
print ms.describe()
def describe_position_scores(ps):
ds = []
print "POSITION SCORES"
sps = Series(ps)
print sps.describe()
clipped_sps = sps.clip(-999,999)
print "WHITE"
describe_movescores((clipped_sps.diff())[1::2])
print "BLACK"
describe_movescores((-1 * clipped_sps.diff())[2::2])
DEBUG = ('DEBUG' in os.environ)
if 'THREADS' in os.environ:
threads = int(os.environ['THREADS'])
else:
threads = 1
if 'HASH' in os.environ:
hash = int(os.environ['HASH'])
else:
hash = 100
backwards = ('BACKWARDS' in os.environ)
fname = os.environ['FNAME']
depth = None
if 'DEPTH' in os.environ:
depth = int(os.environ['DEPTH'])
movetime = None
if 'MOVETIME' in os.environ:
movetime = int(os.environ['MOVETIME'])
depth = None
engine = pystockfish.Engine(depth=depth, param={'Threads':threads, 'Hash':hash}, movetime=movetime)
game_fd = open(fname, 'r')
for gamesread in range(0,int(sys.argv[1])):
while random.random() > 0.01:
game = chess.pgn.read_game(game_fd)
msg("ANALYZING %s" % (game.headers['Event']))
if backwards:
result_struct = do_it_backwards(engine=engine, game=game, debug=DEBUG)
else:
result_struct = do_it(engine=engine, game=game, depth=depth, debug=DEBUG)
print result_struct