-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstdafx.h
More file actions
333 lines (269 loc) · 6.55 KB
/
stdafx.h
File metadata and controls
333 lines (269 loc) · 6.55 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#pragma once
#include <iostream>
#include <xmmintrin.h>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF 10000
#define INVALID 32767
#define MAX_DEPTH 100
#ifdef __linux__
typedef unsigned char U8;
typedef char S8;
typedef unsigned short int U16;
typedef short int S16;
typedef unsigned int U32;
typedef int S32;
typedef unsigned long long U64;
typedef long long S64;
#else
#define U64 unsigned __int64
#define U32 unsigned __int32
#define U16 unsigned __int16
#define U8 unsigned __int8
#define S64 signed __int64
#define S32 signed __int32
#define S16 signed __int16
#define S8 signed __int8
#endif
/* Move ordering constants */
#define SORT_KING 400000000
#define SORT_HASH 200000000
#define SORT_CAPT 100000000
#define SORT_PROM 90000000
#define SORT_KILL 80000000
#define STARTFEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
#define VERSION_STRING "1.1"
#define COMPILE_STRING " compiled 30.12.2014"
#define BOOK_NONE 0
#define BOOK_NARROW 1
#define BOOK_BROAD 2
enum epiece {
KING,
QUEEN,
ROOK,
BISHOP,
KNIGHT,
PAWN,
PIECE_EMPTY
};
enum ecolor {
WHITE,
BLACK,
COLOR_EMPTY
};
enum esqare {
A1=0 , B1, C1, D1, E1, F1, G1, H1,
A2=16 , B2, C2, D2, E2, F2, G2, H2,
A3=32 , B3, C3, D3, E3, F3, G3, H3,
A4=48 , B4, C4, D4, E4, F4, G4, H4,
A5=64 , B5, C5, D5, E5, F5, G5, H5,
A6=80 , B6, C6, D6, E6, F6, G6, H6,
A7=96 , B7, C7, D7, E7, F7, G7, H7,
A8=112, B8, C8, D8, E8, F8, G8, H8
};
enum ecastle {
CASTLE_WK = 1,
CASTLE_WQ = 2,
CASTLE_BK = 4,
CASTLE_BQ = 8
};
enum emflag {
MFLAG_NORMAL = 0,
MFLAG_CAPTURE = 1,
MFLAG_EPCAPTURE = 2,
MFLAG_CASTLE = 4,
MFLAG_EP = 8,
MFLAG_PROMOTION = 16,
MFLAG_NULLMOVE = 32
};
struct sboard {
U8 pieces[128];
U8 color[128];
char stm; // side to move: 0 = white, 1 = black
char castle; // 1 = shortW, 2 = longW, 4 = shortB, 8 = longB
char ep; // en passant square
U8 ply;
U64 hash;
U64 phash;
int rep_index;
U64 rep_stack[1024];
S8 king_loc[2];
int pcsq_mg[2];
int pcsq_eg[2];
int piece_material[2];
int pawn_material[2];
U8 piece_cnt[2][6];
U8 pawns_on_file[2][8];
U8 pawns_on_rank[2][8];
U8 pawn_ctrl[2][128];
};
extern sboard b;
struct smove {
char id;
char from;
char to;
U8 piece_from;
U8 piece_to;
U8 piece_cap;
char flags;
char castle;
char ply;
char ep;
int score;
};
struct sSearchDriver {
int myside;
U8 depth;
int history[2][128][128];
int cutoff [2][128][128];
smove killers[1024] [2];
U64 nodes;
S32 movetime;
U64 q_nodes;
unsigned long starttime;
} extern sd;
enum etimef {
FTIME=1,
FINC=2,
FMOVESTOGO=4,
FDEPTH=8,
FNODES=16,
FMATE=32,
FMOVETIME=64,
FINFINITE=128
};
enum etask {
TASK_NOTHING,
TASK_SEARCH,
TASK_PONDER
} extern task;
struct structtime {
int time[2];
int inc[2];
int movestogo;
int depth;
int nodes;
int mate;
int movetime;
U8 flags;
} extern chronos;
struct s_options {
int ponder;
};
extern s_options options;
struct s_eval_data {
int PIECE_VALUE[6];
int SORT_VALUE[6];
/* Piece-square tables - we use size of the board representation,
not 0..63, to avoid re-indexing. Initialization routine, however,
uses 0..63 format for clarity */
int mgPst[6][2][128];
int egPst[6][2][128];
/* piece-square tables for pawn structure */
int weak_pawn[2][128]; // isolated and backward pawns are scored in the same way
int passed_pawn[2][128];
int protected_passer[2][128];
int sqNearK [2][128][128];
/* single values - letter p before a name signifies a penalty */
int BISHOP_PAIR;
int P_KNIGHT_PAIR;
int P_ROOK_PAIR;
int ROOK_OPEN;
int ROOK_HALF;
int P_BISHOP_TRAPPED_A7;
int P_BISHOP_TRAPPED_A6;
int P_KNIGHT_TRAPPED_A8;
int P_KNIGHT_TRAPPED_A7;
int P_BLOCK_CENTRAL_PAWN;
int P_KING_BLOCKS_ROOK;
int SHIELD_2;
int SHIELD_3;
int P_NO_SHIELD;
int RETURNING_BISHOP;
int P_C3_KNIGHT;
int P_NO_FIANCHETTO;
int FIANCHETTO;
int TEMPO;
int ENDGAME_MAT;
};
extern s_eval_data e;
extern char vector[5][8];
extern bool slide[5];
extern char vectors[5];
void board_display();
void clearBoard();
void fillSq(U8 color, U8 piece, S8 sq);
void clearSq(S8 sq);
int board_loadFromFen(char * fen);
int com_send(char * command);
int com_sendmove(smove m);
int com_uci(char * command);
int com_xboard(char * command);
int com_nothing(char * command);
int com();
int com_init();
int com_ismove(char * command);
void CheckInput();
U8 movegen(smove * moves, U8 tt_move);
U8 movegen_qs(smove * moves);
void movegen_sort(U8 movecount, smove * m, U8 current);
void convert_0x88_a(S8 sq, char * a);
U8 convert_a_0x88(char * a);
char * algebraic_writemove(smove m, char * a);
int algebraic_moves(char * a);
int move_make(smove move);
int move_unmake(smove move);
int move_makeNull();
int move_unmakeNull(char ep);
// the next couple of functions respond to questions about moves or move lists
int move_iscapt(smove m);
int move_isprom(smove m);
int move_canSimplify(smove m);
int move_countLegal();
int move_isLegal(smove m);
smove strToMove(char * a);
// subsidiary functions used to initialize opening book are hidden in book.h
void initBook();
int getBookMove(int book_type);
void search_run(); // interface of the search functions
void clearHistoryTable();
void setDefaultEval();
void setBasicValues();
void setSquaresNearKing();
void setPcsq();
void correctValues();
void readIniFile();
void processIniString(char line[250] );
int eval(int alpha, int beta, int use_hash);
int isPiece(U8 color, U8 piece, S8 sq);
int getTropism(int sq1, int sq2);
void printEval();
void printEvalFactor(int wh, int bl);
int Quiesce( int alpha, int beta );
int badCapture(smove move);
int Blind(smove move);
int isAttacked(char byColor, S8 sq);
int leaperAttack( char byColor, S8 sq, char byPiece );
int straightAttack(char byColor, S8 sq, int vect);
int diagAttack(int byColor, S8 sq, int vect);
int bishAttack(int byColor, S8 sq, int vect);
void perft_start(char * command);
U64 perft(U8 depth);
void util_bench(char * command);
int util_pv(char * pv);
unsigned int gettime();
int time_uci_ponderhit();
void time_uci_go(char * command);
void time_xboard_go();
void time_nothing_go();
void time_calc_movetime();
bool time_stop_root();
bool time_stop();
int isRepetition();
int isDraw();
void printWelcome();
void printHelp();
void printStats();
void printSearchHeader();