-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation.h
192 lines (176 loc) · 6.1 KB
/
evaluation.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// header file for the evaluation function
#ifndef EVALUATION_H
#define EVALUATION_H
#include "board.h"
#include "stack.h"
// FOR NOW WE USE THE OPEN-SOURCE "SIMPLE EVALUATION FUNCTION" FROM CHESSPROGRAMMING.ORG
// see: "https://www.chessprogramming.org/Simplified_Evaluation_Function" as of 2019
static const Score pieceScore[13] = {
100, -100, // pawn
320, -320, // knight
330, -330, // bishop
500, -500, // rook
900, -900, // queen
20000, -20000, // king
0 // none
};
static const Score pieceSquareTable[13][64] = {
/* wPawn */ {
0, 0, 0, 0, 0, 0, 0, 0,
50, 50, 50, 50, 50, 50, 50, 50,
10, 10, 20, 30, 30, 20, 10, 10,
5, 5, 10, 25, 25, 10, 5, 5,
0, 0, 0, 20, 20, 0, 0, 0,
5, -5,-10, 0, 0,-10, -5, 5,
5, 10, 10,-20,-20, 10, 10, 5,
0, 0, 0, 0, 0, 0, 0, 0,
},
/* bPawn */ {
0, 0, 0, 0, 0, 0, 0, 0,
-5,-10,-10, 20, 20,-10,-10, -5,
-5, 5, 10, 0, 0, 10, 5, -5,
0, 0, 0,-20,-20, 0, 0, 0,
-5, -5,-10,-25,-25,-10, -5, -5,
-10,-10,-20,-30,-30,-20,-10,-10,
-50,-50,-50,-50,-50,-50,-50,-50,
0, 0, 0, 0, 0, 0, 0, 0,
},
/* wKnight */ {
-50,-40,-30,-30,-30,-30,-40,-50,
-40,-20, 0, 0, 0, 0,-20,-40,
-30, 0, 10, 15, 15, 10, 0,-30,
-30, 5, 15, 20, 20, 15, 5,-30,
-30, 0, 15, 20, 20, 15, 0,-30,
-30, 5, 10, 15, 15, 10, 5,-30,
-40,-20, 0, 5, 5, 0,-20,-40,
-50,-40,-30,-30,-30,-30,-40,-50,
},
/* bKnight */ {
50, 40, 30, 30, 30, 30, 40, 50,
40, 20, 0, -5, -5, 0, 20, 40,
30, -5,-10,-15,-15,-10, -5, 30,
30, 0,-15,-20,-20,-15, 0, 30,
30, -5,-15,-20,-20,-15, -5, 30,
30, 0,-10,-15,-15,-10, 0, 30,
40, 20, 0, 0, 0, 0, 20, 40,
50, 40, 30, 30, 30, 30, 40, 50,
},
/* wBishop */ {
-20,-10,-10,-10,-10,-10,-10,-20,
-10, 0, 0, 0, 0, 0, 0,-10,
-10, 0, 5, 10, 10, 5, 0,-10,
-10, 5, 5, 10, 10, 5, 5,-10,
-10, 0, 10, 10, 10, 10, 0,-10,
-10, 10, 10, 10, 10, 10, 10,-10,
-10, 5, 0, 0, 0, 0, 5,-10,
-20,-10,-10,-10,-10,-10,-10,-20,
},
/* bBishop */ {
20, 10, 10, 10, 10, 10, 10, 20,
10, -5, 0, 0, 0, 0, -5, 10,
10,-10,-10,-10,-10,-10,-10, 10,
10, 0,-10,-10,-10,-10, 0, 10,
10, -5, -5,-10,-10, -5, -5, 10,
10, 0, -5,-10,-10, -5, 0, 10,
10, 0, 0, 0, 0, 0, 0, 10,
20, 10, 10, 10, 10, 10, 10, 20,
},
/* wRook */ {
0, 0, 0, 0, 0, 0, 0, 0,
5, 10, 10, 10, 10, 10, 10, 5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
-5, 0, 0, 0, 0, 0, 0, -5,
0, 0, 0, 5, 5, 0, 0, 0,
},
/* bRook */ {
0, 0, 0, -5, -5, 0, 0, 0,
5, 0, 0, 0, 0, 0, 0, 5,
5, 0, 0, 0, 0, 0, 0, 5,
5, 0, 0, 0, 0, 0, 0, 5,
5, 0, 0, 0, 0, 0, 0, 5,
5, 0, 0, 0, 0, 0, 0, 5,
-5,-10,-10,-10,-10,-10,-10, -5,
0, 0, 0, 0, 0, 0, 0, 0,
},
/* wQueen */ {
-20,-10,-10, -5, -5,-10,-10,-20,
-10, 0, 0, 0, 0, 0, 0,-10,
-10, 0, 5, 5, 5, 5, 0,-10,
-5, 0, 5, 5, 5, 5, 0, -5,
0, 0, 5, 5, 5, 5, 0, -5,
-10, 5, 5, 5, 5, 5, 0,-10,
-10, 0, 5, 0, 0, 0, 0,-10,
-20,-10,-10, -5, -5,-10,-10,-20,
},
/* bQueen */ {
20, 10, 10, 5, 5, 10, 10, 20,
10, 0, -5, 0, 0, 0, 0, 10,
10, -5, -5, -5, -5, -5, 0, 10,
0, 0, -5, -5, -5, -5, 0, 5,
5, 0, -5, -5, -5, -5, 0, 5,
10, 0, -5, -5, -5, -5, 0, 10,
10, 0, 0, 0, 0, 0, 0, 10,
20, 10, 10, 5, 5, 10, 10, 20,
},
/* wKing (midgame) */ { // TODO: include endgame table
-30,-40,-40,-50,-50,-40,-40,-30,
-30,-40,-40,-50,-50,-40,-40,-30,
-30,-40,-40,-50,-50,-40,-40,-30,
-30,-40,-40,-50,-50,-40,-40,-30,
-20,-30,-30,-40,-40,-30,-30,-20,
-10,-20,-20,-20,-20,-20,-20,-10,
20, 20, 0, 0, 0, 0, 20, 20,
20, 30, 10, 0, 0, 10, 30, 20,
},
/* bKing (midgame) */ { // TODO: include endgame table
-20,-30,-10, 0, 0,-10,-30,-20,
-20,-20, 0, 0, 0, 0,-20,-20,
10, 20, 20, 20, 20, 20, 20, 10,
20, 30, 30, 40, 40, 30, 30, 20,
30, 40, 40, 50, 50, 40, 40, 30,
30, 40, 40, 50, 50, 40, 40, 30,
30, 40, 40, 50, 50, 40, 40, 30,
30, 40, 40, 50, 50, 40, 40, 30,
},
/* none */ {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
},
};
/* TODO: include this
static const Score kingEndgamePieceSquareTable[] = {
-50,-40,-30,-20,-20,-30,-40,-50,
-30,-20,-10, 0, 0,-10,-20,-30,
-30,-10, 20, 30, 30, 20,-10,-30,
-30,-10, 30, 40, 40, 30,-10,-30,
-30,-10, 30, 40, 40, 30,-10,-30,
-30,-10, 20, 30, 30, 20,-10,-30,
-30,-30, 0, 0, 0, 0,-30,-30,
-50,-30,-30,-30,-30,-30,-30,-50,
};
// bKing (endgame)
{
50, 30, 30, 30, 30, 30, 30, 50,
30, 30, 0, 0, 0, 0, 30, 30,
30, 10,-20,-30,-30,-20, 10, 30,
30, 10,-30,-40,-40,-30, 10, 30,
30, 10,-30,-40,-40,-30, 10, 30,
30, 10,-20,-30,-30,-20, 10, 30,
30, 20, 10, 0, 0, 10, 20, 30,
50, 40, 30, 20, 20, 30, 40, 50,
},
*/
// THIS SHOULD BE INCREMENTALLY UPDATED ON THE BOARD
Score evaluate(Board *board);
Score static_exchange_evaluation(SquareCode square, Board *board, Stack *stack);
Score capture_static_evaluation(SquareCode from, SquareCode to, Board *board, Stack *stack);
#endif