-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabelCreate_score.py
65 lines (50 loc) · 1.35 KB
/
labelCreate_score.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 30 16:34:14 2019
@author: shailesh
"""
import helpers
import chess
from chess import pgn
import chess.engine
import chess.svg
gameFile = open("Data/ficsgamesdb_201901_chess2000_nomovetimes_107218.pgn")
engine = chess.engine.SimpleEngine.popen_uci("/usr/games/stockfish")
#info = engine.analyse(board, chess.engine.Limit(depth=20))
#print("Score:", info["score"])
positions = []
scores = []
counter = 1
while(counter<5000):
print(counter)
try:
game = pgn.read_game(gameFile)
board = game.board()
except:
break
for move in game.mainline_moves():
# predictedMove = engineMoveList[i]
# print(counter,'\n')
score = str(engine.analyse(board, chess.engine.Limit(depth="10"))["score"])
if(score[0] in '+-0') :
if score =='0':
score = 0
else:
score = int(score[1:])
if counter%2==0: #All scores are with respect to white
score*=-1
else: #When mate is seen
sign = score[1]
if sign == '-':
score = -100000
else:
score = 100000
positions.append(board.fen()+"\n")
scores.append(str(score)+"\n")
board.push(move)
counter+=1
with open("Data/ScoreData/inputs.txt","w") as inputs:
inputs.writelines(positions)
with open("Data/ScoreData/labels.txt","w") as labels:
labels.writelines(scores)