Subversion Repositories Games.Chess Giants

Rev

Rev 33 | Rev 154 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 pmbaty 1
#include "chess.h"
2
/* *INDENT-OFF* */#if !defined(INLINEASM)
108 pmbaty 3
unsigned char msb[65536];
33 pmbaty 4
unsigned char lsb[65536];
5
#endif
6
unsigned char msb_8bit[256];
7
unsigned char lsb_8bit[256];
8
unsigned char pop_cnt_8bit[256];
9
uint64_t mask_pawn_connected[2][64];
10
uint64_t mask_pawn_isolated[64];
11
uint64_t mask_passed[2][64];
12
uint64_t mask_pattacks[2][64];
13
uint64_t pawn_race[2][2][64];
14
BOOK_POSITION book_buffer[BOOK_CLUSTER_SIZE];
15
BOOK_POSITION book_buffer_char[BOOK_CLUSTER_SIZE];
16
const int OOsqs[2][3] =  {{E8, F8, G8}, {E1, F1, G1}};
17
const int OOOsqs[2][3] = {{E8, D8, C8}, {E1, D1, C1}};
18
const int OOfrom[2] = {E8, E1};
19
const int OOto[2] =   {G8, G1};
20
const int OOOto[2] =  {C8, C1};
21
#define VERSION      "25.0.1"
22
char version[8] = {VERSION};
23
PLAYING_MODE mode = normal_mode;
24
int batch_mode = 0;                  /* no asynch reads */
25
int swindle_mode = 1;                /* try to swindle */
26
int call_flag = 0;
27
int crafty_rating = 2500;
28
int opponent_rating = 2500;
29
int last_search_value = 0;
30
int pruning_margin[10] = {0, 100, 150, 200, 250, 300, 400, 500, 600, 700};
108 pmbaty 31
int pruning_depth = 7;
33 pmbaty 32
int movecnt_pruning[4] = {0, 12, 15, 18};
33
int movecnt_depth = 3;
34
int pgn_suggested_percent = 0;
35
char pgn_event[128] = {"?"};
36
char pgn_site[128] = {"?"};
37
char pgn_date[128] = {"????.??.??"};
38
char pgn_round[128] = {"?"};
39
char pgn_white[128] = {"unknown"};
40
char pgn_white_elo[128] = {""};
41
char pgn_black[128] = {"Crafty " VERSION};
42
char pgn_black_elo[128] = {""};
108 pmbaty 43
char pgn_result[128] = {"*"};
33 pmbaty 44
char *B_list[128];
45
char *AK_list[128];
108 pmbaty 46
char *GM_list[128];
33 pmbaty 47
char *IM_list[128];
48
char *SP_list[128];
49
char *SP_opening_filename[128];
50
char *SP_personality_filename[128];
51
int output_format = 0;
108 pmbaty 52
#if !defined(NOEGTB)
53
int EGTBlimit = 0;
54
int EGTB_use = 0;
55
int EGTB_draw = 0;
33 pmbaty 56
int EGTB_depth = 6;
108 pmbaty 57
size_t EGTB_cache_size = 4096 * 4096;
58
void *EGTB_cache = (void *) 0;
59
int EGTB_setup = 0;
60
#endif
61
int xboard = 0;
62
int xboard_done = 0;
63
int pong = 0;
64
int early_exit = 99;
65
int new_game = 0;
66
char book_path[128] = {BOOKDIR};
67
char log_path[128] = {LOGDIR};
68
char tb_path[128] = {TBDIR};
69
char rc_path[128] = {RCDIR};
70
int initialized = 0;
71
int kibitz = 0;
72
int post = 0;
73
int log_id = 0;
74
int game_wtm = 1;
75
int last_opponent_move = 0;
76
int check_depth = 1;                  /* extend checks one ply                */
77
int null_depth = 3;                   /* R=3 + (next line)                    */
78
int null_divisor = 6;                 /* R = null_depth + depth / 6           */
79
int LMR_rdepth = 1;                   /* leave 1 full ply after reductions    */
80
int LMR_min= 1;                       /* minimum reduction 1 ply              */
81
int LMR_max= 15;                      /* maximum reduction 15 plies           */
82
double LMR_db = 1.8;                  /* depth is 1.8x as important as        */
83
double LMR_mb = 1.0;                  /* moves searched in the formula.       */
84
double LMR_s = 2.0;                   /* smaller numbers increase reductions. */
85
uint8_t LMR[32][64];
86
int rep_index;
87
int search_depth = 0;
88
uint64_t search_nodes = 0;
89
uint64_t temp_search_nodes = 0;
90
int search_move = 0;
91
int predicted = 0;
92
int time_used = 0;
93
int time_used_opponent = 0;
94
int analyze_mode = 0;
95
int annotate_mode = 0;
96
int input_status = 0;
97
int resign = 9;
98
int resign_counter = 0;
99
int resign_count = 5;
100
int draw_counter = 0;
101
int draw_count = 5;
102
int draw_offer_pending = 0;
103
int draw_offered = 0;
104
int offer_draws = 1;
105
int dynamic_draw_score = 1;
106
int adaptive_hash = 0;
107
size_t adaptive_hash_min = 0;
108
size_t adaptive_hash_max = 0;
109
size_t adaptive_hashp_min = 0;
110
size_t adaptive_hashp_max = 0;
111
int time_limit = 100;
112
int force = 0;
113
char initial_position[80] = {""};
114
char ponder_text[512] = {""};
115
char book_hint[512] = {""};
116
int over = 0;
117
int usage_level = 0;
118
char audible_alarm = 0x07;
119
char speech = 0;
120
int book_accept_mask = ~03;
121
int book_reject_mask = 3;
122
int book_random = 1;
123
float book_weight_learn = 1.0;
124
float book_weight_freq = 1.0;
125
float book_weight_eval = 0.1f; // Pierre-Marie Baty -- added type cast
126
int book_search_trigger = 20;
127
int learn = 1;
128
int learning = 100;
129
int learn_value = 0;
130
int abort_search;      /*  1 = abort / print stats, 2 = abort no print stats */
131
int iteration;
132
int root_wtm = 1;
133
int last_root_value;
134
ROOT_MOVE root_moves[256];
135
int n_root_moves;
136
int difficulty;
137
int absolute_time_limit;
138
int search_time_limit;
139
int burp;
140
int quit = 0;
141
unsigned opponent_start_time, opponent_end_time;
142
unsigned program_start_time, program_end_time;
143
unsigned start_time, end_time;
144
TREE *block[MAX_BLOCKS + 1];
145
THREAD thread[CPUS];
146
#if (CPUS > 1)
147
lock_t lock_smp, lock_io;
148
#if defined(UNIX)
149
  pthread_attr_t attributes;
150
#endif
151
#endif
152
unsigned int smp_max_threads = 0;
153
unsigned int smp_split_group = 8;       /* max threads per group              */
154
unsigned int smp_split_at_root = 1;     /* enable split at root               */
155
unsigned int smp_min_split_depth = 5;   /* don't split within 5 plies of tips */
156
unsigned int smp_gratuitous_depth = 10; /* gratuitous splits if depth > 10    */
157
unsigned int smp_gratuitous_limit = 6;  /* max gratuitous splits / thread     */
158
int smp_affinity = 0;                   /* anything >= 0 is enabled           */
159
int smp_numa = 0;                       /* disables NUMA mode by default      */
160
                                        /* enable if you really have NUMA     */
161
/*
162
      This is the autotune configuration section.  Each line represents one
163
      smp search parameter that can be tuned.  The first three values are the
164
      min, max and increment that autotune will use for this paramenter.  The
165
      fourth parameter is a string autotune will display to explain what it is
166
      currently tuning.  The fifth parameter is the command used to change this
167
      parameter (this is added to the .craftyrc/crafty.rc file after tuning is
168
      completed.  The last parameter is a pointer to the variable that must be
169
      changed to adjust the parameter while running the autotune tests.
170
*/
171
int autotune_params = 4;
172
struct autotune tune[16] = {
173
  { 4, 20, 4, "max thread group", "smpgroup", &smp_split_group},
174
  { 4,  8, 1, "min split depth", "smpmin", &smp_min_split_depth},
175
  {10, 16, 2, "min gratuitous split depth", "smpgsd", &smp_gratuitous_depth},
176
  { 1,  8, 2, "gratuitous split limit", "smpgsl", &smp_gratuitous_limit},
177
};
178
unsigned parallel_splits;
179
unsigned parallel_splits_wasted;
180
unsigned parallel_aborts;
181
unsigned parallel_joins;
182
unsigned busy_percent = 0;
183
uint64_t game_max_blocks = 0;
184
volatile int smp_split = 0;
185
volatile int smp_threads = 0;
186
volatile int initialized_threads = 0;
187
int crafty_is_white = 0;
188
unsigned nodes_between_time_checks = 1000000;
189
unsigned nodes_per_second = 1000000;
190
int next_time_check = 100000;
191
int transposition_age = 0;
192
int thinking = 0;
193
int pondering = 0;
194
int puzzling = 0;
195
int booking = 0;
196
/************************************************************
197
 *                                                          *
198
 *    1 -> display move/time/results/etc.                   *
199
 *    2 -> display PV.                                      *
200
 *    4 -> display fail high / fail low moves               *
201
 *    8 -> display search statistics.                       *
202
 *   16 -> display root moves as they are searched.         *
203
 *   32 -> display general informational messages.          *
204
 *   64 -> display ply-1 move list / flags after each       *
205
 *           iteration.                                     *
206
 *  128 -> display root moves and scores before search      *
207
 *           begins.                                        *
208
 * 2048 -> error messages (can not be disabled).            *
209
 *                                                          *
210
 ************************************************************
211
 */
212
int display_options = 1 | 2 | 8 | 16 | 32 | 2048;
213
unsigned noise_level = 100;
214
int noise_block = 0;
215
int tc_moves = 60;
216
int tc_time = 180000;
217
int tc_time_remaining[2] = {180000, 180000};
218
int tc_moves_remaining[2] = {60, 60};
219
int tc_secondary_moves = 30;
220
int tc_secondary_time = 90000;
221
int tc_increment = 0;
222
int tc_sudden_death = 0;
223
int tc_safety_margin = 0;
224
int draw_score[2] = {0, 0};
225
char kibitz_text[4096];
226
int kibitz_depth;
227
int move_number = 1;
228
int moves_out_of_book = 0;
229
int first_nonbook_factor = 0;
230
int first_nonbook_span = 0;
231
int smp_nice = 1;
232
#if defined(SKILL)
233
int skill = 100;
234
#endif
235
int show_book = 0;
236
int book_selection_width = 5;
237
int ponder = 1;
238
int trace_level = 0;
239
/*  for the following 6 lines, each pair should have */
240
/*  the same numeric value (the size value).         */
241
size_t hash_table_size = 1ull << 20;
242
uint64_t hash_mask = ((1ull << 20) - 1) & ~3;
243
size_t hash_path_size = 1ull << 16;
244
uint64_t hash_path_mask = ((1ull << 16) - 1) & ~15;
245
size_t pawn_hash_table_size = 1ull << 18;
246
uint64_t pawn_hash_mask = (1ull << 18) - 1;
247
uint64_t mask_clear_entry = 0xff9ffffffffe0000ull;
248
size_t eval_hash_table_size = 65536;
249
uint64_t eval_hash_mask = 65536 - 1;
250
int abs_draw_score = 0;
251
int accept_draws = 1;
252
const char translate[13] =
253
    {'k', 'q', 'r', 'b', 'n', 'p', 0, 'P', 'N', 'B', 'R', 'Q', 'K'};
254
const uint64_t magic_bishop[64] = {
255
  0x0002020202020200ull, 0x0002020202020000ull, 0x0004010202000000ull,
256
  0x0004040080000000ull, 0x0001104000000000ull, 0x0000821040000000ull,
257
  0x0000410410400000ull, 0x0000104104104000ull, 0x0000040404040400ull,
258
  0x0000020202020200ull, 0x0000040102020000ull, 0x0000040400800000ull,
259
  0x0000011040000000ull, 0x0000008210400000ull, 0x0000004104104000ull,
260
  0x0000002082082000ull, 0x0004000808080800ull, 0x0002000404040400ull,
261
  0x0001000202020200ull, 0x0000800802004000ull, 0x0000800400A00000ull,
262
  0x0000200100884000ull, 0x0000400082082000ull, 0x0000200041041000ull,
263
  0x0002080010101000ull, 0x0001040008080800ull, 0x0000208004010400ull,
264
  0x0000404004010200ull, 0x0000840000802000ull, 0x0000404002011000ull,
265
  0x0000808001041000ull, 0x0000404000820800ull, 0x0001041000202000ull,
266
  0x0000820800101000ull, 0x0000104400080800ull, 0x0000020080080080ull,
267
  0x0000404040040100ull, 0x0000808100020100ull, 0x0001010100020800ull,
268
  0x0000808080010400ull, 0x0000820820004000ull, 0x0000410410002000ull,
269
  0x0000082088001000ull, 0x0000002011000800ull, 0x0000080100400400ull,
270
  0x0001010101000200ull, 0x0002020202000400ull, 0x0001010101000200ull,
271
  0x0000410410400000ull, 0x0000208208200000ull, 0x0000002084100000ull,
272
  0x0000000020880000ull, 0x0000001002020000ull, 0x0000040408020000ull,
273
  0x0004040404040000ull, 0x0002020202020000ull, 0x0000104104104000ull,
274
  0x0000002082082000ull, 0x0000000020841000ull, 0x0000000000208800ull,
275
  0x0000000010020200ull, 0x0000000404080200ull, 0x0000040404040400ull,
276
  0x0002020202020200ull
277
};
278
const uint64_t magic_bishop_mask[64] = {
279
  0x0040201008040200ull, 0x0000402010080400ull, 0x0000004020100A00ull,
280
  0x0000000040221400ull, 0x0000000002442800ull, 0x0000000204085000ull,
281
  0x0000020408102000ull, 0x0002040810204000ull, 0x0020100804020000ull,
282
  0x0040201008040000ull, 0x00004020100A0000ull, 0x0000004022140000ull,
283
  0x0000000244280000ull, 0x0000020408500000ull, 0x0002040810200000ull,
284
  0x0004081020400000ull, 0x0010080402000200ull, 0x0020100804000400ull,
285
  0x004020100A000A00ull, 0x0000402214001400ull, 0x0000024428002800ull,
286
  0x0002040850005000ull, 0x0004081020002000ull, 0x0008102040004000ull,
287
  0x0008040200020400ull, 0x0010080400040800ull, 0x0020100A000A1000ull,
288
  0x0040221400142200ull, 0x0002442800284400ull, 0x0004085000500800ull,
289
  0x0008102000201000ull, 0x0010204000402000ull, 0x0004020002040800ull,
290
  0x0008040004081000ull, 0x00100A000A102000ull, 0x0022140014224000ull,
291
  0x0044280028440200ull, 0x0008500050080400ull, 0x0010200020100800ull,
292
  0x0020400040201000ull, 0x0002000204081000ull, 0x0004000408102000ull,
293
  0x000A000A10204000ull, 0x0014001422400000ull, 0x0028002844020000ull,
294
  0x0050005008040200ull, 0x0020002010080400ull, 0x0040004020100800ull,
295
  0x0000020408102000ull, 0x0000040810204000ull, 0x00000A1020400000ull,
296
  0x0000142240000000ull, 0x0000284402000000ull, 0x0000500804020000ull,
297
  0x0000201008040200ull, 0x0000402010080400ull, 0x0002040810204000ull,
298
  0x0004081020400000ull, 0x000A102040000000ull, 0x0014224000000000ull,
299
  0x0028440200000000ull, 0x0050080402000000ull, 0x0020100804020000ull,
300
  0x0040201008040200ull
301
};
302
const unsigned magic_bishop_shift[64] = {
303
  58, 59, 59, 59, 59, 59, 59, 58,
304
  59, 59, 59, 59, 59, 59, 59, 59,
305
  59, 59, 57, 57, 57, 57, 59, 59,
306
  59, 59, 57, 55, 55, 57, 59, 59,
307
  59, 59, 57, 55, 55, 57, 59, 59,
308
  59, 59, 57, 57, 57, 57, 59, 59,
309
  59, 59, 59, 59, 59, 59, 59, 59,
310
  58, 59, 59, 59, 59, 59, 59, 58
311
};
312
uint64_t magic_bishop_table[5248];
313
uint64_t *magic_bishop_indices[64] = {
314
  magic_bishop_table + 4992, magic_bishop_table + 2624,
315
  magic_bishop_table + 256, magic_bishop_table + 896,
316
  magic_bishop_table + 1280, magic_bishop_table + 1664,
317
  magic_bishop_table + 4800, magic_bishop_table + 5120,
318
  magic_bishop_table + 2560, magic_bishop_table + 2656,
319
  magic_bishop_table + 288, magic_bishop_table + 928,
320
  magic_bishop_table + 1312, magic_bishop_table + 1696,
321
  magic_bishop_table + 4832, magic_bishop_table + 4928,
322
  magic_bishop_table + 0, magic_bishop_table + 128,
323
  magic_bishop_table + 320, magic_bishop_table + 960,
324
  magic_bishop_table + 1344, magic_bishop_table + 1728,
325
  magic_bishop_table + 2304, magic_bishop_table + 2432,
326
  magic_bishop_table + 32, magic_bishop_table + 160,
327
  magic_bishop_table + 448, magic_bishop_table + 2752,
328
  magic_bishop_table + 3776, magic_bishop_table + 1856,
329
  magic_bishop_table + 2336, magic_bishop_table + 2464,
330
  magic_bishop_table + 64, magic_bishop_table + 192,
331
  magic_bishop_table + 576, magic_bishop_table + 3264,
332
  magic_bishop_table + 4288, magic_bishop_table + 1984,
333
  magic_bishop_table + 2368, magic_bishop_table + 2496,
334
  magic_bishop_table + 96, magic_bishop_table + 224,
335
  magic_bishop_table + 704, magic_bishop_table + 1088,
336
  magic_bishop_table + 1472, magic_bishop_table + 2112,
337
  magic_bishop_table + 2400, magic_bishop_table + 2528,
338
  magic_bishop_table + 2592, magic_bishop_table + 2688,
339
  magic_bishop_table + 832, magic_bishop_table + 1216,
340
  magic_bishop_table + 1600, magic_bishop_table + 2240,
341
  magic_bishop_table + 4864, magic_bishop_table + 4960,
342
  magic_bishop_table + 5056, magic_bishop_table + 2720,
343
  magic_bishop_table + 864, magic_bishop_table + 1248,
344
  magic_bishop_table + 1632, magic_bishop_table + 2272,
345
  magic_bishop_table + 4896, magic_bishop_table + 5184
346
};
347
int16_t magic_bishop_mobility_table[5248];
348
int16_t *magic_bishop_mobility_indices[64] = {
349
  magic_bishop_mobility_table + 4992, magic_bishop_mobility_table + 2624,
350
  magic_bishop_mobility_table + 256, magic_bishop_mobility_table + 896,
351
  magic_bishop_mobility_table + 1280, magic_bishop_mobility_table + 1664,
352
  magic_bishop_mobility_table + 4800, magic_bishop_mobility_table + 5120,
353
  magic_bishop_mobility_table + 2560, magic_bishop_mobility_table + 2656,
354
  magic_bishop_mobility_table + 288, magic_bishop_mobility_table + 928,
355
  magic_bishop_mobility_table + 1312, magic_bishop_mobility_table + 1696,
356
  magic_bishop_mobility_table + 4832, magic_bishop_mobility_table + 4928,
357
  magic_bishop_mobility_table + 0, magic_bishop_mobility_table + 128,
358
  magic_bishop_mobility_table + 320, magic_bishop_mobility_table + 960,
359
  magic_bishop_mobility_table + 1344, magic_bishop_mobility_table + 1728,
360
  magic_bishop_mobility_table + 2304, magic_bishop_mobility_table + 2432,
361
  magic_bishop_mobility_table + 32, magic_bishop_mobility_table + 160,
362
  magic_bishop_mobility_table + 448, magic_bishop_mobility_table + 2752,
363
  magic_bishop_mobility_table + 3776, magic_bishop_mobility_table + 1856,
364
  magic_bishop_mobility_table + 2336, magic_bishop_mobility_table + 2464,
365
  magic_bishop_mobility_table + 64, magic_bishop_mobility_table + 192,
33 pmbaty 366
  magic_bishop_mobility_table + 576, magic_bishop_mobility_table + 3264,
108 pmbaty 367
  magic_bishop_mobility_table + 4288, magic_bishop_mobility_table + 1984,
368
  magic_bishop_mobility_table + 2368, magic_bishop_mobility_table + 2496,
369
  magic_bishop_mobility_table + 96, magic_bishop_mobility_table + 224,
33 pmbaty 370
  magic_bishop_mobility_table + 704, magic_bishop_mobility_table + 1088,
108 pmbaty 371
  magic_bishop_mobility_table + 1472, magic_bishop_mobility_table + 2112,
33 pmbaty 372
  magic_bishop_mobility_table + 2400, magic_bishop_mobility_table + 2528,
373
  magic_bishop_mobility_table + 2592, magic_bishop_mobility_table + 2688,
374
  magic_bishop_mobility_table + 832, magic_bishop_mobility_table + 1216,
375
  magic_bishop_mobility_table + 1600, magic_bishop_mobility_table + 2240,
376
  magic_bishop_mobility_table + 4864, magic_bishop_mobility_table + 4960,
377
  magic_bishop_mobility_table + 5056, magic_bishop_mobility_table + 2720,
378
  magic_bishop_mobility_table + 864, magic_bishop_mobility_table + 1248,
379
  magic_bishop_mobility_table + 1632, magic_bishop_mobility_table + 2272,
380
  magic_bishop_mobility_table + 4896, magic_bishop_mobility_table + 5184
381
};
382
uint64_t magic_rook_table[102400];
383
uint64_t *magic_rook_indices[64] = {
384
  magic_rook_table + 86016, magic_rook_table + 73728,
385
  magic_rook_table + 36864, magic_rook_table + 43008,
386
  magic_rook_table + 47104, magic_rook_table + 51200,
387
  magic_rook_table + 77824, magic_rook_table + 94208,
388
  magic_rook_table + 69632, magic_rook_table + 32768,
389
  magic_rook_table + 38912, magic_rook_table + 10240,
390
  magic_rook_table + 14336, magic_rook_table + 53248,
391
  magic_rook_table + 57344, magic_rook_table + 81920,
392
  magic_rook_table + 24576, magic_rook_table + 33792,
393
  magic_rook_table + 6144, magic_rook_table + 11264,
394
  magic_rook_table + 15360, magic_rook_table + 18432,
395
  magic_rook_table + 58368, magic_rook_table + 61440,
396
  magic_rook_table + 26624, magic_rook_table + 4096,
397
  magic_rook_table + 7168, magic_rook_table + 0,
398
  magic_rook_table + 2048, magic_rook_table + 19456,
399
  magic_rook_table + 22528, magic_rook_table + 63488,
400
  magic_rook_table + 28672, magic_rook_table + 5120,
401
  magic_rook_table + 8192, magic_rook_table + 1024,
402
  magic_rook_table + 3072, magic_rook_table + 20480,
403
  magic_rook_table + 23552, magic_rook_table + 65536,
404
  magic_rook_table + 30720, magic_rook_table + 34816,
108 pmbaty 405
  magic_rook_table + 9216, magic_rook_table + 12288,
406
  magic_rook_table + 16384, magic_rook_table + 21504,
407
  magic_rook_table + 59392, magic_rook_table + 67584,
408
  magic_rook_table + 71680, magic_rook_table + 35840,
409
  magic_rook_table + 39936, magic_rook_table + 13312,
410
  magic_rook_table + 17408, magic_rook_table + 54272,
411
  magic_rook_table + 60416, magic_rook_table + 83968,
412
  magic_rook_table + 90112, magic_rook_table + 75776,
413
  magic_rook_table + 40960, magic_rook_table + 45056,
414
  magic_rook_table + 49152, magic_rook_table + 55296,
415
  magic_rook_table + 79872, magic_rook_table + 98304
416
};
417
int16_t magic_rook_mobility_table[102400];
418
int16_t *magic_rook_mobility_indices[64] = {
33 pmbaty 419
  magic_rook_mobility_table + 86016, magic_rook_mobility_table + 73728,
420
  magic_rook_mobility_table + 36864, magic_rook_mobility_table + 43008,
421
  magic_rook_mobility_table + 47104, magic_rook_mobility_table + 51200,
422
  magic_rook_mobility_table + 77824, magic_rook_mobility_table + 94208,
423
  magic_rook_mobility_table + 69632, magic_rook_mobility_table + 32768,
424
  magic_rook_mobility_table + 38912, magic_rook_mobility_table + 10240,
425
  magic_rook_mobility_table + 14336, magic_rook_mobility_table + 53248,
426
  magic_rook_mobility_table + 57344, magic_rook_mobility_table + 81920,
427
  magic_rook_mobility_table + 24576, magic_rook_mobility_table + 33792,
428
  magic_rook_mobility_table + 6144, magic_rook_mobility_table + 11264,
429
  magic_rook_mobility_table + 15360, magic_rook_mobility_table + 18432,
430
  magic_rook_mobility_table + 58368, magic_rook_mobility_table + 61440,
431
  magic_rook_mobility_table + 26624, magic_rook_mobility_table + 4096,
432
  magic_rook_mobility_table + 7168, magic_rook_mobility_table + 0,
433
  magic_rook_mobility_table + 2048, magic_rook_mobility_table + 19456,
434
  magic_rook_mobility_table + 22528, magic_rook_mobility_table + 63488,
435
  magic_rook_mobility_table + 28672, magic_rook_mobility_table + 5120,
108 pmbaty 436
  magic_rook_mobility_table + 8192, magic_rook_mobility_table + 1024,
33 pmbaty 437
  magic_rook_mobility_table + 3072, magic_rook_mobility_table + 20480,
438
  magic_rook_mobility_table + 23552, magic_rook_mobility_table + 65536,
108 pmbaty 439
  magic_rook_mobility_table + 30720, magic_rook_mobility_table + 34816,
33 pmbaty 440
  magic_rook_mobility_table + 9216, magic_rook_mobility_table + 12288,
441
  magic_rook_mobility_table + 16384, magic_rook_mobility_table + 21504,
442
  magic_rook_mobility_table + 59392, magic_rook_mobility_table + 67584,
108 pmbaty 443
  magic_rook_mobility_table + 71680, magic_rook_mobility_table + 35840,
444
  magic_rook_mobility_table + 39936, magic_rook_mobility_table + 13312,
445
  magic_rook_mobility_table + 17408, magic_rook_mobility_table + 54272,
446
  magic_rook_mobility_table + 60416, magic_rook_mobility_table + 83968,
447
  magic_rook_mobility_table + 90112, magic_rook_mobility_table + 75776,
448
  magic_rook_mobility_table + 40960, magic_rook_mobility_table + 45056,
449
  magic_rook_mobility_table + 49152, magic_rook_mobility_table + 55296,
33 pmbaty 450
  magic_rook_mobility_table + 79872, magic_rook_mobility_table + 98304
108 pmbaty 451
};
452
const uint64_t magic_rook[64] = {
33 pmbaty 453
  0x0080001020400080ull, 0x0040001000200040ull, 0x0080081000200080ull,
454
  0x0080040800100080ull, 0x0080020400080080ull, 0x0080010200040080ull,
455
  0x0080008001000200ull, 0x0080002040800100ull, 0x0000800020400080ull,
456
  0x0000400020005000ull, 0x0000801000200080ull, 0x0000800800100080ull,
108 pmbaty 457
  0x0000800400080080ull, 0x0000800200040080ull, 0x0000800100020080ull,
458
  0x0000800040800100ull, 0x0000208000400080ull, 0x0000404000201000ull,
459
  0x0000808010002000ull, 0x0000808008001000ull, 0x0000808004000800ull,
460
  0x0000808002000400ull, 0x0000010100020004ull, 0x0000020000408104ull,
33 pmbaty 461
  0x0000208080004000ull, 0x0000200040005000ull, 0x0000100080200080ull,
108 pmbaty 462
  0x0000080080100080ull, 0x0000040080080080ull, 0x0000020080040080ull,
463
  0x0000010080800200ull, 0x0000800080004100ull, 0x0000204000800080ull,
464
  0x0000200040401000ull, 0x0000100080802000ull, 0x0000080080801000ull,
465
  0x0000040080800800ull, 0x0000020080800400ull, 0x0000020001010004ull,
466
  0x0000800040800100ull, 0x0000204000808000ull, 0x0000200040008080ull,
467
  0x0000100020008080ull, 0x0000080010008080ull, 0x0000040008008080ull,
468
  0x0000020004008080ull, 0x0000010002008080ull, 0x0000004081020004ull,
469
  0x0000204000800080ull, 0x0000200040008080ull, 0x0000100020008080ull,
470
  0x0000080010008080ull, 0x0000040008008080ull, 0x0000020004008080ull,
33 pmbaty 471
  0x0000800100020080ull, 0x0000800041000080ull, 0x00FFFCDDFCED714Aull,
472
  0x007FFCDDFCED714Aull, 0x003FFFCDFFD88096ull, 0x0000040810002101ull,
473
  0x0001000204080011ull, 0x0001000204000801ull, 0x0001000082000401ull,
474
  0x0001FFFAABFAD1A2ull
475
};
476
const uint64_t magic_rook_mask[64] = {
477
  0x000101010101017Eull, 0x000202020202027Cull, 0x000404040404047Aull,
478
  0x0008080808080876ull, 0x001010101010106Eull, 0x002020202020205Eull,
479
  0x004040404040403Eull, 0x008080808080807Eull, 0x0001010101017E00ull,
480
  0x0002020202027C00ull, 0x0004040404047A00ull, 0x0008080808087600ull,
481
  0x0010101010106E00ull, 0x0020202020205E00ull, 0x0040404040403E00ull,
482
  0x0080808080807E00ull, 0x00010101017E0100ull, 0x00020202027C0200ull,
108 pmbaty 483
  0x00040404047A0400ull, 0x0008080808760800ull, 0x00101010106E1000ull,
33 pmbaty 484
  0x00202020205E2000ull, 0x00404040403E4000ull, 0x00808080807E8000ull,
485
  0x000101017E010100ull, 0x000202027C020200ull, 0x000404047A040400ull,
486
  0x0008080876080800ull, 0x001010106E101000ull, 0x002020205E202000ull,
487
  0x004040403E404000ull, 0x008080807E808000ull, 0x0001017E01010100ull,
488
  0x0002027C02020200ull, 0x0004047A04040400ull, 0x0008087608080800ull,
108 pmbaty 489
  0x0010106E10101000ull, 0x0020205E20202000ull, 0x0040403E40404000ull,
33 pmbaty 490
  0x0080807E80808000ull, 0x00017E0101010100ull, 0x00027C0202020200ull,
491
  0x00047A0404040400ull, 0x0008760808080800ull, 0x00106E1010101000ull,
492
  0x00205E2020202000ull, 0x00403E4040404000ull, 0x00807E8080808000ull,
108 pmbaty 493
  0x007E010101010100ull, 0x007C020202020200ull, 0x007A040404040400ull,
494
  0x0076080808080800ull, 0x006E101010101000ull, 0x005E202020202000ull,
495
  0x003E404040404000ull, 0x007E808080808000ull, 0x7E01010101010100ull,
496
  0x7C02020202020200ull, 0x7A04040404040400ull, 0x7608080808080800ull,
33 pmbaty 497
  0x6E10101010101000ull, 0x5E20202020202000ull, 0x3E40404040404000ull,
498
  0x7E80808080808000ull
499
};
500
const unsigned magic_rook_shift[64] = {
501
  52, 53, 53, 53, 53, 53, 53, 52,
502
  53, 54, 54, 54, 54, 54, 54, 53,
108 pmbaty 503
  53, 54, 54, 54, 54, 54, 54, 53,
504
  53, 54, 54, 54, 54, 54, 54, 53,
505
  53, 54, 54, 54, 54, 54, 54, 53,
506
  53, 54, 54, 54, 54, 54, 54, 53,
507
  53, 54, 54, 54, 54, 54, 54, 53,
508
  53, 54, 54, 53, 53, 53, 53, 53
509
};
510
const uint64_t mobility_mask_b[4] = {
511
  0xFF818181818181FFull, 0x007E424242427E00ull,
512
  0x00003C24243C0000ull, 0x0000001818000000ull
513
};
33 pmbaty 514
const uint64_t mobility_mask_r[4] = {
108 pmbaty 515
  0x8181818181818181ull, 0x4242424242424242ull,
516
  0x2424242424242424ull, 0x1818181818181818ull
33 pmbaty 517
};
518
/*
519
  values use to deal with white/black independently
520
 */
521
const int rankflip[2][8] = {
522
  {RANK8, RANK7, RANK6, RANK5, RANK4, RANK3, RANK2, RANK1},
523
  {RANK1, RANK2, RANK3, RANK4, RANK5, RANK6, RANK7, RANK8}
524
};
525
const int sqflip[2][64] = {
526
 {A8, B8, C8, D8, E8, F8, G8, H8,
527
  A7, B7, C7, D7, E7, F7, G7, H7,
528
  A6, B6, C6, D6, E6, F6, G6, H6,
529
  A5, B5, C5, D5, E5, F5, G5, H5,
530
  A4, B4, C4, D4, E4, F4, G4, H4,   /* black */
531
  A3, B3, C3, D3, E3, F3, G3, H3,
108 pmbaty 532
  A2, B2, C2, D2, E2, F2, G2, H2,
33 pmbaty 533
  A1, B1, C1, D1, E1, F1, G1, H1},
534
535
 {A1, B1, C1, D1, E1, F1, G1, H1,
536
  A2, B2, C2, D2, E2, F2, G2, H2,
537
  A3, B3, C3, D3, E3, F3, G3, H3,
538
  A4, B4, C4, D4, E4, F4, G4, H4,
539
  A5, B5, C5, D5, E5, F5, G5, H5,   /* white */
108 pmbaty 540
  A6, B6, C6, D6, E6, F6, G6, H6,
541
  A7, B7, C7, D7, E7, F7, G7, H7,
542
  A8, B8, C8, D8, E8, F8, G8, H8}
33 pmbaty 543
};
544
const int rank1[2] = {RANK8, RANK1};
545
const int rank2[2] = {RANK7, RANK2};
546
const int rank3[2] = {RANK6, RANK3};
547
const int rank4[2] = {RANK5, RANK4};
548
const int rank5[2] = {RANK4, RANK5};
549
const int rank6[2] = {RANK3, RANK6};
550
const int rank7[2] = {RANK2, RANK7};
551
const int rank8[2] = {RANK1, RANK8};
108 pmbaty 552
const int epdir[2] = {8, -8};
33 pmbaty 553
const int csq[2] = {C8, C1};
554
const int dsq[2] = {D8, D1};
555
const int esq[2] = {E8, E1};
556
const int fsq[2] = {F8, F1};
557
const int gsq[2] = {G8, G1};
108 pmbaty 558
uint64_t distance_ring[64][8];
559
const int sign[2] = {-1, 1};
33 pmbaty 560
const int epsq[2] = {+8, -8};
561
const int rook_A[2] = {A8, A1};
562
const int rook_D[2] = {D8, D1};
563
const int rook_F[2] = {F8, F1};
564
const int rook_G[2] = {G8, G1};
565
const int rook_H[2] = {H8, H1};
566
const int pawnadv1[2] = {+8, -8};
567
const int pawnadv2[2] = {+16, -16};
108 pmbaty 568
const int capleft[2] = {+9, -7};
569
const int capright[2] = {+7, -9};
570
const char empty_sqs[9] = {0, '1', '2', '3', '4', '5', '6', '7', '8'};
33 pmbaty 571
const int pcval[7] = {0, 100, 300, 300, 500, 900, 9900};
572
const int p_vals[7] = {0, 1, 3, 3, 5, 9, 99};
573
const int MVV_LVA[7][7] = {
108 pmbaty 574
    {0,  5<<21,  4<<21,  4<<21,  3<<21,  2<<21,  1<<21},
33 pmbaty 575
    {0, 10<<21,  9<<21,  9<<21,  8<<21,  7<<21,  6<<21},
576
    {0, 15<<21, 14<<21, 14<<21, 13<<21, 12<<21, 11<<21},
577
    {0, 15<<21, 14<<21, 14<<21, 13<<21, 12<<21, 11<<21},
578
    {0, 20<<21, 19<<21, 19<<21, 18<<21, 17<<21, 16<<21},
108 pmbaty 579
    {0, 25<<21, 24<<21, 24<<21, 23<<21, 22<<21, 21<<21},
580
    {0, 30<<21, 29<<21, 29<<21, 28<<21, 27<<21, 26<<21}};
581
const int pieces[2][7] = {
582
  {0, -1, -2, -3, -4, -5, -6},
583
  {0, +1, +2, +3, +4, +5, +6}
584
};
585
const int lower_n = 16;
586
const int lower_b = 10;
587
const int mobility_score_n[4] = {1, 2, 3, 4};
588
const int mobility_score_b[4] = {1, 2, 3, 4};
589
const int mobility_score_r[4] = {1, 2, 3, 4};
590
const int mob_curve_r[48] = {
591
  -27,-23,-21,-19,-15,-10, -9, -8,
592
   -7, -6, -5, -4, -3, -2, -1,  0,
593
    1,  2,  3,  4,  5,  6,  7,  8,
594
    9, 10, 11, 12, 13, 14, 15, 16,
595
   17, 18, 19, 20, 21, 22, 23, 24,
596
   25, 26, 27, 28, 29, 30, 31, 32
597
};
598
int piece_values[2][7] = {
599
  {0, -PAWN_VALUE, -KNIGHT_VALUE, -BISHOP_VALUE,
600
      -ROOK_VALUE, -QUEEN_VALUE,    -KING_VALUE},
601
  {0,  PAWN_VALUE,  KNIGHT_VALUE,  BISHOP_VALUE,
602
       ROOK_VALUE,  QUEEN_VALUE,     KING_VALUE}
603
};
604
/*
605
   First term is a character string explaining what the eval
606
   term is used for.
607
608
  Second term is the "type" of the value.
609
     0 = heading entry (no values, just a category name to display).
610
     1 = scalar value.
33 pmbaty 611
     2 = array[mg]
612
     3 = floating point value
613
614
   Third term is the "size" of the scoring term, where 0 is a
108 pmbaty 615
     scalar value, otherwise it is the actual number of elements in
616
     an array of values.
33 pmbaty 617
618
   Fourth term is a pointer to the data value(s).
619
*/
620
struct personality_term personality_packet[256] = {
621
  {"search options                          ", 0, 0, NULL},        /*  0 */
622
  {"check extension                         ", 1, 0, &check_depth},
108 pmbaty 623
  {"null-move reduction                     ", 1, 0, &null_depth},
624
  {"null-move adaptive divisor              ", 1, 0, &null_divisor},
625
  {"LMR min distance to frontier            ", 1, 0, &LMR_rdepth},
626
  {"LMR min reduction                       ", 1, 0, &LMR_min},
627
  {"LMR max reduction                       ", 1, 0, &LMR_max},
628
  {"LMR formula depth bias                  ", 3, 0, &LMR_db},
629
  {"LMR formula moves searched bias         ", 3, 0, &LMR_mb},
630
  {"LMR scale factor                        ", 3, 0, &LMR_s},
631
  {"search options (continued)              ", 0, 0, NULL},        /* 10 */
632
  {"prune depth                             ", 1, 0, &pruning_depth},
633
  {"prune margin [remain_depth]             ", 4, 8, pruning_margin},
634
  {NULL, 0, 0, NULL},
635
  {NULL, 0, 0, NULL},
636
  {NULL, 0, 0, NULL},
637
  {NULL, 0, 0, NULL},
638
  {NULL, 0, 0, NULL},
639
  {NULL, 0, 0, NULL},
640
  {NULL, 0, 0, NULL},
33 pmbaty 641
};
642
/* *INDENT-ON* */
643
 
108 pmbaty 644