Check in Bonanza Feliz 0.0
[bonanza.git] / data.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "shogi.h"
4
5 FILE *pf_book;
6 FILE *pf_hash;
7 uint64_t ehash_tbl[ EHASH_MASK + 1 ];
8 unsigned char hash_rejections_parent[ REJEC_MASK+1 ];
9 rejections_t  hash_rejections[ REJEC_MASK+1 ];
10 trans_table_t *ptrans_table_orig;
11 SHARE trans_table_t *ptrans_table;
12 history_book_learn_t history_book_learn[ HASH_REG_HIST_LEN ];
13 record_t record_problems;
14 record_t record_game;
15 rand_work_t rand_work;
16 root_move_t root_move_list[ MAX_LEGAL_MOVES ];
17 pv_t last_pv;
18 pv_t last_pv_save;
19 slide_tbl_t aslide[ nsquare ];
20 bitboard_t abb_b_knight_attacks[ nsquare ];
21 bitboard_t abb_b_silver_attacks[ nsquare ];
22 bitboard_t abb_b_gold_attacks[ nsquare ];
23 bitboard_t abb_w_knight_attacks[ nsquare ];
24 bitboard_t abb_w_silver_attacks[ nsquare ];
25 bitboard_t abb_w_gold_attacks[ nsquare ];
26 bitboard_t abb_king_attacks[ nsquare ];
27 bitboard_t abb_bishop_attacks_rl45[ nsquare ][ 128 ];
28 bitboard_t abb_bishop_attacks_rr45[ nsquare ][ 128 ];
29 bitboard_t abb_file_attacks[ nsquare ][ 128 ];
30 bitboard_t abb_obstacle[ nsquare ][ nsquare ];
31 bitboard_t abb_mask[ nsquare ];
32 bitboard_t abb_mask_rl90[ nsquare ];
33 bitboard_t abb_mask_rl45[ nsquare ];
34 bitboard_t abb_mask_rr45[ nsquare ];
35 bitboard_t abb_plus_rays[ nsquare ];
36 bitboard_t abb_minus_rays[ nsquare ];
37 uint64_t b_pawn_rand[ nsquare ];
38 uint64_t b_lance_rand[ nsquare ];
39 uint64_t b_knight_rand[ nsquare ];
40 uint64_t b_silver_rand[ nsquare ];
41 uint64_t b_gold_rand[ nsquare ];
42 uint64_t b_bishop_rand[ nsquare ];
43 uint64_t b_rook_rand[ nsquare ];
44 uint64_t b_king_rand[ nsquare ];
45 uint64_t b_pro_pawn_rand[ nsquare ];
46 uint64_t b_pro_lance_rand[ nsquare ];
47 uint64_t b_pro_knight_rand[ nsquare ];
48 uint64_t b_pro_silver_rand[ nsquare ];
49 uint64_t b_horse_rand[ nsquare ];
50 uint64_t b_dragon_rand[ nsquare ];
51 uint64_t b_hand_pawn_rand[ npawn_max ];
52 uint64_t b_hand_lance_rand[ nlance_max ];
53 uint64_t b_hand_knight_rand[ nknight_max ];
54 uint64_t b_hand_silver_rand[ nsilver_max ];
55 uint64_t b_hand_gold_rand[ ngold_max ];
56 uint64_t b_hand_bishop_rand[ nbishop_max ];
57 uint64_t b_hand_rook_rand[ nrook_max ];
58 uint64_t w_pawn_rand[ nsquare ];
59 uint64_t w_lance_rand[ nsquare ];
60 uint64_t w_knight_rand[ nsquare ];
61 uint64_t w_silver_rand[ nsquare ];
62 uint64_t w_gold_rand[ nsquare ];
63 uint64_t w_bishop_rand[ nsquare ];
64 uint64_t w_rook_rand[ nsquare ];
65 uint64_t w_king_rand[ nsquare ];
66 uint64_t w_pro_pawn_rand[ nsquare ];
67 uint64_t w_pro_lance_rand[ nsquare ];
68 uint64_t w_pro_knight_rand[ nsquare ];
69 uint64_t w_pro_silver_rand[ nsquare ];
70 uint64_t w_horse_rand[ nsquare ];
71 uint64_t w_dragon_rand[ nsquare ];
72 uint64_t w_hand_pawn_rand[ npawn_max ];
73 uint64_t w_hand_lance_rand[ nlance_max ];
74 uint64_t w_hand_knight_rand[ nknight_max ];
75 uint64_t w_hand_silver_rand[ nsilver_max ];
76 uint64_t w_hand_gold_rand[ ngold_max ];
77 uint64_t w_hand_bishop_rand[ nbishop_max ];
78 uint64_t w_hand_rook_rand[ nrook_max ];
79 uint64_t node_limit;
80 SHARE unsigned int game_status;
81 unsigned int move_evasion_pchk;
82 unsigned int node_per_second;
83 unsigned int node_next_signal;
84 unsigned int node_last_check;
85 unsigned int hash_mask;
86 unsigned int sec_elapsed;
87 unsigned int sec_b_total;
88 unsigned int sec_w_total;
89 unsigned int sec_limit;
90 unsigned int sec_limit_up;
91 unsigned int sec_limit_depth;
92 unsigned int time_last_result;
93 unsigned int time_last_check;
94 unsigned int time_start;
95 unsigned int time_turn_start;
96 unsigned int time_limit;
97 unsigned int time_max_limit;
98 unsigned int time_last_search;
99 unsigned int time_last_eff_search;
100 unsigned int time_response;
101 unsigned int ai_rook_attacks_r0[ nsquare ][ 128 ];
102 unsigned int ponder_move;
103 int p_value_ex[31];
104 int benefit2promo[15];
105 int easy_abs;
106 int easy_min;
107 int easy_max;
108 int easy_value;
109 SHARE int fmg_misc;
110 SHARE int fmg_cap;
111 SHARE int fmg_drop;
112 SHARE int fmg_mt;
113 SHARE int fmg_misc_king;
114 SHARE int fmg_cap_king;
115 unsigned int ponder_move_list[ MAX_LEGAL_MOVES ];
116 int ponder_nmove;
117 SHARE int root_abort;
118 int root_nrep;
119 int root_nmove;
120 int root_alpha;
121 int root_beta;
122 int root_value;
123 int root_turn;
124 int root_move_cap;
125 int root_nfail_high;
126 int root_nfail_low;
127 int trans_table_age;
128 int log2_ntrans_table;
129 int n_nobook_move;
130 int last_root_value;
131 int last_root_value_save;
132 int iteration_depth;
133 int depth_limit;
134 int irecord_game;
135 int npawn_box;
136 int nlance_box;
137 int nknight_box;
138 int nsilver_box;
139 int ngold_box;
140 int nbishop_box;
141 int nrook_box;
142 int resign_threshold;
143 short p_value[31];
144 short pc_on_sq[nsquare][pos_n];
145 short kkp[nsquare][nsquare][kkp_end];
146 unsigned char book_section[ MAX_SIZE_SECTION+1 ];
147 unsigned char adirec[ nsquare ][ nsquare ];
148 unsigned char is_same[ 16 ][ 16 ];
149 char str_cmdline[ SIZE_CMDLINE ];
150 char str_message[ SIZE_MESSAGE ];
151 char str_buffer_cmdline[ SIZE_CMDBUFFER ];
152 const char *str_error;
153
154 #if defined(MPV)
155 int root_mpv;
156 int mpv_num;
157 int mpv_width;
158 pv_t mpv_pv[ MPV_MAX_PV*2 + 1 ];
159 #endif
160
161 #if defined(TLP)
162 #  if !defined(_WIN32)
163 pthread_attr_t pthread_attr;
164 #  endif
165 lock_t tlp_lock;
166 tree_t tlp_atree_work[ TLP_NUM_WORK ];
167 tree_t * volatile tlp_ptrees[ TLP_MAX_THREADS ];
168 volatile int tlp_abort;
169 volatile int tlp_idle;
170 volatile int tlp_num;
171 int tlp_max;
172 int tlp_nsplit;
173 int tlp_nabort;
174 int tlp_nslot;
175 volatile unsigned short tlp_rejections_slot[ REJEC_MASK+1 ];
176 #else
177 tree_t tree;
178 #endif
179
180 #if ! defined(_WIN32)
181 clock_t clk_tck;
182 #endif
183
184 #if ! defined(NO_LOGGING)
185 FILE *pf_log;
186 const char *str_dir_logs = "log";
187 #endif
188
189 #if defined(CSA_LAN) || defined(MNJ_LAN)
190 unsigned int time_last_send;
191 #endif
192
193 #if defined(CSA_LAN)
194 int client_turn;
195 int client_ngame;
196 int client_max_game;
197 long client_port;
198 char client_str_addr[256];
199 char client_str_id[256];
200 char client_str_pwd[256];
201 sckt_t sckt_csa;
202 #endif
203
204 #if defined(MNJ_LAN)
205 short mnj_tbl[ MNJ_MASK + 1 ];
206 sckt_t sckt_mnj;
207 int mnj_posi_id;
208 unsigned int mnj_move_last;
209 #endif
210
211 #if defined(DEKUNOBOU)
212 SOCKET dek_socket_in;
213 SOCKET dek_s_accept;
214 u_long dek_ul_addr;
215 unsigned int dek_ngame;
216 unsigned int dek_lost;
217 unsigned int dek_win;
218 int dek_turn;
219 u_short dek_ns;
220 #endif
221
222 check_table_t b_chk_tbl[nsquare];
223 check_table_t w_chk_tbl[nsquare];
224
225 #if defined(_MSC_VER)
226 #elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
227 #else
228 unsigned char aifirst_one[512];
229 unsigned char ailast_one[512];
230 #endif
231
232 #if defined(NDEBUG)
233 #  if ! defined(CSASHOGI)
234 const char *str_myname = ( "Bonanza " BNZ_VER );
235 #  else
236 const char *str_myname = ( "Bonanza " BNZ_VER );
237 #  endif
238 #else
239 const char *str_myname = ( "Bonanza " BNZ_VER " Debug Build ("
240                            __TIME__ " " __DATE__ ")" );
241 #endif
242
243 #if defined(DBG_EASY)
244 unsigned int easy_move;
245 #endif
246
247 const char *str_resign       = "%TORYO";
248 const char *str_repetition   = "%SENNICHITE";
249 const char *str_jishogi      = "%JISHOGI";
250 const char *str_record_error = "%ERROR";
251 const char *str_delimiters   = " \t,";
252 const char *str_fmt_line     = "Line %u: %s";
253 const char *str_on           = "on";
254 const char *str_off          = "off";
255 const char *str_book         = "book.bin";
256 const char *str_hash         = "hash.bin";
257 const char *str_fv           = "fv.bin";
258 const char *str_book_error   = "invalid opening book";
259 const char *str_io_error     = "I/O error";
260 const char *str_perpet_check = "perpetual check";
261 const char *str_bad_cmdline  = "invalid command line";
262 const char *str_busy_think   = "I'm busy in thinking now";
263 const char *str_bad_record   = "invalid record of game";
264 const char *str_bad_board    = "invalid board representation";
265 const char *str_illegal_move = "illegal move";
266 const char *str_double_pawn  = "double pawn";
267 const char *str_mate_drppawn = "mated by a droped pawn";
268 const char *str_unexpect_eof = "unexpected end of file";
269 const char *str_king_hang    = "The king is hang.";
270 const char *str_game_ended   = "move after a game was concluded";
271 const char *str_fopen_error  = "Can't open a file";
272 const char *str_ovrflw_line  = "Too many characters in a line.";
273 const char *str_warning      = "WARNING: ";
274 #if defined(CSA_LAN)
275 const char *str_server_err   = "received invalid message from the server";
276 #endif
277
278 const char *astr_table_piece[16]  = { "* ", "FU", "KY", "KE", "GI", "KI",
279                                       "KA", "HI", "OU", "TO", "NY", "NK",
280                                       "NG", "##", "UM", "RY" };
281
282 const char ach_turn[2] = { '+', '-' };
283
284 const char ashell_h[ SHELL_H_LEN ] = { 1, 3, 7, 15, 31, 63, 127 };
285
286 const short aipos[31] = { e_dragon, e_horse,  0,        e_gold,
287                           e_gold,   e_gold,   e_gold,   0,
288                           e_rook,   e_bishop, e_gold,   e_silver,
289                           e_knight, e_lance,  e_pawn,   0,
290                           f_pawn,   f_lance,  f_knight,
291                           f_silver, f_gold,   f_bishop, f_rook,
292                           0,        f_gold,   f_gold,   f_gold,
293                           f_gold,   0,        f_horse,  f_dragon };
294
295 const unsigned char aifile[ nsquare ]= {
296   file1, file2, file3, file4, file5, file6, file7, file8, file9,
297   file1, file2, file3, file4, file5, file6, file7, file8, file9,
298   file1, file2, file3, file4, file5, file6, file7, file8, file9,
299   file1, file2, file3, file4, file5, file6, file7, file8, file9,
300   file1, file2, file3, file4, file5, file6, file7, file8, file9,
301   file1, file2, file3, file4, file5, file6, file7, file8, file9,
302   file1, file2, file3, file4, file5, file6, file7, file8, file9,
303   file1, file2, file3, file4, file5, file6, file7, file8, file9,
304   file1, file2, file3, file4, file5, file6, file7, file8, file9 };
305
306 const unsigned char airank[ nsquare ]= {
307   rank1, rank1, rank1, rank1, rank1, rank1, rank1, rank1, rank1,
308   rank2, rank2, rank2, rank2, rank2, rank2, rank2, rank2, rank2,
309   rank3, rank3, rank3, rank3, rank3, rank3, rank3, rank3, rank3,
310   rank4, rank4, rank4, rank4, rank4, rank4, rank4, rank4, rank4,
311   rank5, rank5, rank5, rank5, rank5, rank5, rank5, rank5, rank5,
312   rank6, rank6, rank6, rank6, rank6, rank6, rank6, rank6, rank6,
313   rank7, rank7, rank7, rank7, rank7, rank7, rank7, rank7, rank7,
314   rank8, rank8, rank8, rank8, rank8, rank8, rank8, rank8, rank8,
315   rank9, rank9, rank9, rank9, rank9, rank9, rank9, rank9, rank9 };
316
317 const min_posi_t min_posi_no_handicap = {
318   0,0,0,
319   { -lance, -knight, -silver, -gold, -king, -gold, -silver, -knight, -lance,
320     empty, -rook, empty, empty, empty, empty, empty, -bishop, empty,
321     -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn, -pawn,
322     empty, empty, empty, empty, empty, empty, empty, empty, empty,
323     empty, empty, empty, empty, empty, empty, empty, empty, empty,
324     empty, empty, empty, empty, empty, empty, empty, empty, empty,
325     pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
326     empty, bishop, empty, empty, empty, empty, empty, rook, empty,
327     lance, knight, silver, gold, king, gold, silver, knight, lance } };