-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevaluator.py
79 lines (64 loc) · 2.17 KB
/
evaluator.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
77
78
79
import chess
import weights
import config
pawnScore = config.PAWN_SCORE
materialPnts = [pawnScore, 4 * pawnScore, int(round(4.1 * pawnScore)), 6 * pawnScore, 12 * pawnScore, 0]
phasePnts = [0, 1, 1, 2, 4, 0]
def evaluator(board, result):
pnts = 0
if not result == "*":
if result[0] == "1":
if result[1] == "/":
pnts = 0
else:
pnts = config.MAX_SCORE
else:
pnts = -config.MAX_SCORE
if (board.turn == False):
pnts = -pnts
return pnts
matPnts = initPnts = endPnts = 0
phase = totalPhase = 24
for i in range(0, 64):
piece = board.piece_at(i)
if piece:
phase -= phasePnts[piece.piece_type - 1]
if piece.color:
matPnts += materialPnts[piece.piece_type - 1]
initPnts += weights.initPosPnts[piece.piece_type - 1][i]
endPnts += weights.finalPosPnts[piece.piece_type - 1][i]
else:
matPnts -= materialPnts[piece.piece_type - 1]
initPnts -= weights.initPosPnts[piece.piece_type - 1][63 - i]
endPnts -= weights.finalPosPnts[piece.piece_type - 1][63 - i]
phase = (phase * 256 + (totalPhase / 2)) / totalPhase
pnts = matPnts + ((initPnts * (256 - phase)) + (endPnts * phase)) / 256
if (board.turn == False):
pnts = -pnts
return pnts
def findFeatures(board, color):
featuresRawInit = [[0 for i in range (0, 64)] for j in range (0, 6)]
featuresRawFin = [[0 for i in range (0, 64)] for j in range (0, 6)]
featuresInit = []
featuresFin = []
colorType = 1 if color else -1
phase = totalPhase = 24
for i in range(0, 64):
piece = board.piece_at(i)
if piece:
phase -= phasePnts[piece.piece_type - 1]
phase = (phase * 256 + (totalPhase / 2)) / totalPhase
for i in range(0, 64):
piece = board.piece_at(i)
if piece:
if piece.color:
featuresRawInit[piece.piece_type - 1][i] += (256.0 - phase) / 256.0 * colorType
featuresRawFin[piece.piece_type - 1][i] += phase / 256.0 * colorType
else:
featuresRawInit[piece.piece_type - 1][63 - i] -= (256.0 - phase) / 256.0 * colorType
featuresRawFin[piece.piece_type - 1][63 - i] -= phase / 256.0 * colorType
for j in range(6):
for i in range(64):
featuresInit.append(featuresRawInit[j][i])
featuresFin.append(featuresRawFin[j][i])
return (featuresInit, featuresFin)