GNU Shogi 1.2p01
[gnushogi.git] / src / gnushogi.h
blob7631209fae4e6acb06a97a0db3849664e600a85b
1 /*
2 * gnushogi.h - Header file for GNU SHOGI
4 * Copyright (c) 1993, 1994 Matthias Mutz
6 * GNU SHOGI is based on GNU CHESS
8 * Copyright (c) 1988,1989,1990 John Stanback
9 * Copyright (c) 1992 Free Software Foundation
11 * This file is part of GNU SHOGI.
13 * GNU Shogi is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation.
17 * GNU Shogi is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with GNU Shogi; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 #if defined THINK_C
30 /* OPT */
31 /* #define XSHOGI */
32 /* #define BAREBONES */
33 #define SMALL_MEMORY
34 #define SLOW_CPU
35 /* #define SAVE_SSCORE */
36 #if !defined EXTRA_2MB
37 #define SAVE_PTYPE_DISTDATA
38 /* #define SAVE_DISTDATA */
39 #define SAVE_NEXTPOS
40 #endif
41 #define HARDTIMELIMIT
42 #define DEEPSEARCHCUT
43 #define NULLMOVE
44 #define VERYBUGGY
45 #define QUIETBACKGROUND
46 /* #define HASGETTIMEOFDAY */
47 /* #define clocktime() (100l * clock() / CLOCKS_PER_SEC) */
48 #define clocktime() (100l * time(0))
49 #if defined NOTABLES
50 #define NOTTABLE
51 #else
52 #if !defined DEBUG_TTABLE
53 #define HISTORY
54 /* #define EXACTHISTORY */
55 #define CACHE
56 #endif
57 /* #define NOTTABLE */
58 #endif
59 #define SEMIQUIETBOOKGEN
60 /* GENOPT */
61 #define CHECKBONUS
62 /* #define DROPBONUS */
63 /* #define FIELDBONUS */
64 /* #define TESUJIBONUS */
65 #define EASY_OPENINGS
66 /* FILES */
67 #define LANGFILE "gnushogi.lng"
68 #define BOOK "gnushogi.tbk"
69 #define BINBOOK "gnushogi.bbk"
70 /* #define HASHFILE "gnushogi.hsh" */
71 #define PATTERNFILE "gnushogi.pat"
72 /* #define DEBUG */
74 #define NOBYTEOPS
75 #include <string.h>
77 #define small_short char
78 #define small_ushort unsigned char
80 #elif defined MSDOS
82 /* OPT */
83 /* #define XSHOGI */
84 /* #define BAREBONES */
85 #define SMALL_MEMORY
86 #define SLOW_CPU
87 /* #define SAVE_SSCORE */
88 #define SAVE_PTYPE_DISTDATA
89 /* #define SAVE_DISTDATA */
90 #define SAVE_NEXTPOS
91 #define HARDTIMELIMIT
92 #define DEEPSEARCHCUT
93 #define NULLMOVE
94 #define VERYBUGGY
95 /* #define QUIETBACKGROUND */
96 /* #define HASGETTIMEOFDAY */
97 #define clocktime() (100l * time(0))
98 #define HISTORY
99 /* #define EXACTHISTORY */
100 #define CACHE
101 #define SEMIQUIETBOOKGEN
102 /* #define NOTTABLE */
103 /* GENOPT */
104 #define CHECKBONUS
105 /* #define DROPBONUS */
106 /* #define FIELDBONUS */
107 /* #define TESUJIBONUS */
108 #define EASY_OPENINGS
109 /* FILES */
110 #define LANGFILE "gnushogi.lng"
111 #define BOOK "gnushogi.tbk"
112 #define BINBOOK "gnushogi.bbk"
113 /* #define HASHFILE "gnushogi.hsh" */
114 #define PATTERNFILE "gnushogi.pat"
115 /* #define DEBUG */
117 #define NOBYTEOPS
118 /* #define NOMEMOPS */
119 /* #include <mem.h> */
121 #define small_short char
122 #define small_ushort unsigned char
124 #else
126 * type small_short must cover -128..127. In case of trouble,
127 * try to uncommend "signed". If this doesn't help, use short.
129 #define signed /* signed */
131 #define small_short signed char
132 #define small_ushort unsigned char
134 #endif
138 #ifdef MSDOS
139 #define HEAP_ALLOC(n) _fmalloc(n)
140 #define HEAP_FREE(p) _ffree(p)
141 #else
142 #define far
143 #define HEAP_ALLOC(n) malloc(n)
144 #define HEAP_FREE(p) free(p)
145 #endif
149 #if defined NOBYTEOPS && defined NOMEMOPS
150 #define array_copy(src,dst,len) \
151 { long i; char far *psrc=(char far *)src, *pdst=(char far *)dst;\
152 for (i=len; i; pdst[--i] = psrc[i]);\
154 #define array_zero(dst,len) \
155 { long i; char far *pdst=(char far *)dst;\
156 for (i=len; i; pdst[--i] = 0);\
158 #elif defined NOBYTEOPS
159 #ifdef MSDOS
160 #define array_copy(src,dst,len) _fmemcpy(dst,src,len)
161 #define array_zero(dst,len) _fmemset(dst,0,len)
162 #else
163 #define array_copy(src,dst,len) memcpy(dst,src,len)
164 #define array_zero(dst,len) memset(dst,0,len)
165 #endif
166 #else
167 #define array_copy(src,dst,len) bcopy(src,dst,len)
168 #define array_zero(dst,len) bzero(dst,len)
169 #endif
172 #if !defined(__STDC__) && !defined(MSDOS)
173 #define const
174 #endif
176 #ifndef __GNUC__
177 #define inline
178 #endif
180 #include <stdio.h>
182 #ifdef BINBOOK
183 extern char *binbookfile;
184 #endif
185 extern char *bookfile;
186 extern short int ahead;
187 extern char far *xwin;
188 extern char far *Lang;
192 #define SEEK_SET 0
193 #define SEEK_END 2
194 #if defined DEBUG || defined DEBUG_EVAL
195 extern void ShowDBLine (char *, short int, short int,
196 short int, short int, short int,
197 short unsigned int *);
198 extern FILE *debugfd;
199 extern short int debuglevel;
201 extern void debug_position (FILE *D);
202 extern void debug_ataks (FILE *D, long *atk);
203 #endif /* DEBUG */
205 #include <ctype.h>
206 #if !defined NO_STRING_INCLUDE
207 #include <string.h>
208 #endif
209 #include <stdlib.h>
211 #ifdef THINK_C
212 #define RWA_ACC "r+b"
213 #define WA_ACC "w+b"
214 #elif defined MSDOS
215 #include <time.h>
216 #include <malloc.h>
217 #define malloc(size) farmalloc(size)
218 #define RWA_ACC "r+b"
219 #define WA_ACC "w+b"
220 #ifdef timeout
221 #undef timeout
222 #endif
223 #define printz printf
224 #define scanz scanf
225 #else
226 #define RWA_ACC "r+"
227 #define WA_ACC "w+"
228 #include <sys/param.h>
229 #include <sys/types.h>
230 #include <sys/times.h>
231 #endif /* MSDOS */
232 #if defined NONDSP || defined THINK_C || defined MSDOS
233 #define printz printf
234 #define scanz scanf
235 #else
236 #include <curses.h>
237 #define scanz fflush(stdout),scanw
238 #define printz printw
239 #endif
241 #ifdef notdef
242 #if defined(__STDC__) || defined(MSDOS)
243 /* <stdio.h> */
244 extern int fclose (FILE *);
245 #ifndef __ultrix /* work around bug in c89 compiler --t.mann */
246 extern int fscanf (FILE *, const char *, ...);
247 extern int fprintf (FILE *, const char *, ...);
248 #endif /*__ultrix*/
249 extern int fflush (FILE *);
251 /* <stdlib.h> */
252 extern int abs (int);
253 extern int atoi (const char *);
255 /* <time.h> */
256 extern long int time (long int *);
258 /* <string.h> */
259 extern void *memset (void *, int, size_t);
260 #endif
261 #endif
263 #define NO_PIECES 15
264 #define MAX_CAPTURED 19
265 #define NO_PTYPE_PIECES 15
266 #define NO_SQUARES 81
267 #define NO_SQUARES_1 80
268 #define NO_COLS 9
269 #define NO_ROWS 9
271 #if defined DEBUG || defined HASHFILE || defined CACHE
272 #define PTBLBDSIZE (NO_SQUARES+NO_PIECES)
273 #endif
275 #include "eval.h"
277 #define SCORE_LIMIT 12000
279 /* masks into upper 16 bits of ataks array */
280 /* observe order of relative piece values */
281 #define CNT_MASK 0x000000FF
282 #define ctlP 0x00200000
283 #define ctlPp 0x00100000
284 #define ctlL 0x00080000
285 #define ctlN 0x00040000
286 #define ctlLp 0x00020000
287 #define ctlNp 0x00010000
288 #define ctlS 0x00008000
289 #define ctlSp 0x00004000
290 #define ctlG 0x00002000
291 #define ctlB 0x00001000
292 #define ctlBp 0x00000800
293 #define ctlR 0x00000400
294 #define ctlRp 0x00000200
295 #define ctlK 0x00000100
297 /* attack functions */
298 #define Patak(c, u) (atak[c][u] > ctlP)
299 #define Anyatak(c, u) (atak[c][u] != 0)
301 /* hashtable flags */
302 #define truescore 0x0001
303 #define lowerbound 0x0002
304 #define upperbound 0x0004
305 #define kingcastle 0x0008
306 #define queencastle 0x0010
307 #define evalflag 0x0020
309 /* king positions */
310 #define BlackKing PieceList[black][0]
311 #define WhiteKing PieceList[white][0]
312 #define OwnKing PieceList[c1][0]
313 #define EnemyKing PieceList[c2][0]
316 /* board properties */
317 #define InBlackCamp(sq) ((sq) < 27)
318 #define InWhiteCamp(sq) ((sq) > 53)
319 #define InPromotionZone(side,sq) (((side)==black)?InWhiteCamp(sq):InBlackCamp(sq))
321 /* constants */
323 #define OPENING_HINT 0x141d /* P7g-7f (20->29) */
325 /* truth values */
326 #define false 0
327 #define true 1
329 /* colors */
330 #define black 0
331 #define white 1
332 #define neutral 2
334 /* piece code defines */
335 #define no_piece 0
336 #define pawn 1
337 #define lance 2
338 #define knight 3
339 #define silver 4
340 #define gold 5
341 #define bishop 6
342 #define rook 7
343 #define ppawn 8
344 #define plance 9
345 #define pknight 10
346 #define psilver 11
347 #define pbishop 12
348 #define prook 13
349 #define king 14
351 #define ptype_no_piece 0
352 #define ptype_pawn 0
353 #define ptype_lance 1
354 #define ptype_knight 2
355 #define ptype_silver 3
356 #define ptype_gold 4
357 #define ptype_bishop 5
358 #define ptype_rook 6
359 #define ptype_pbishop 7
360 #define ptype_prook 8
361 #define ptype_king 9
362 #define ptype_wpawn 10
363 #define ptype_wlance 11
364 #define ptype_wknight 12
365 #define ptype_wsilver 13
366 #define ptype_wgold 14
368 /* node flags */
369 #define pmask 0x000f /* 15 */
370 #define promote 0x0010 /* 16 */
371 #define dropmask 0x0020 /* 32 */
372 #define exact 0x0040 /* 64 */
373 #define tesuji 0x0080 /* 128 */
374 #define check 0x0100 /* 256 */
375 #define capture 0x0200 /* 512 */
376 #define draw 0x0400 /* 1024 */
377 #define stupid 0x0800 /* 2048 */
378 #define questionable 0x1000 /* 4096 */
379 #define kingattack 0x2000 /* 8192 */
380 #define book 0x4000 /* 16384 */
382 /* move quality flags */
383 #define goodmove tesuji
384 #define badmove stupid
385 #ifdef EASY_OPENINGS
386 #define difficult questionable
387 #endif
389 /* move symbols */
390 #define pxx (CP[2])
391 #define qxx (CP[1])
392 #define rxx (CP[4])
393 #define cxx (CP[3])
394 /***************************************************************************/
395 /***************** Table limits ********************************************/
397 * ttblsz must be a power of 2. Setting ttblsz 0 removes the transposition
398 * tables.
400 #if defined NOTTABLE
401 #define vttblsz 0
402 #elif defined SMALL_MEMORY
403 #if defined SAVE_SSCORE
404 #define vttblsz (1 << 12)
405 #else
406 #if defined EXTRA_2MB
407 #define vttblsz (1 << 12)
408 #else
409 #define vttblsz (1 << 10)
410 #endif
411 #endif
412 #else
413 #ifdef DEBUG
414 #define vttblsz (8001)
415 #else /* !DEBUG */
416 #define vttblsz (100001)
417 #endif
418 #endif
420 #if defined SMALL_MEMORY
421 #define MINTTABLE (0)
422 #else
423 #ifdef DEBUG
424 #define MINTTABLE (2000) /* min ttable size -1 */
425 #else
426 #define MINTTABLE (8000) /* min ttable size -1 */
427 #endif
428 #endif
430 #define ttblsz vttblsz
432 #if defined SMALL_MEMORY
433 #if !defined SAVE_SSCORE
434 #define TREE 1500 /* max number of tree entries */
435 #else
436 #define TREE 2500 /* max number of tree entries */
437 #endif
438 #else
439 #define TREE 4000 /* max number of tree entries */
440 #endif
442 #define MAXDEPTH 40 /* max depth a search can be carried */
443 #define MINDEPTH 2 /* min search depth =1 (no hint), >1 hint */
444 #define MAXMOVES 300 /* max number of half moves in a game */
445 #define CPSIZE 235 /* size of lang file max */
446 #if defined THINK_C || defined MSDOS || defined SMALL_MEMORY
447 #if defined SAVE_SSCORE
448 #define ETABLE (1<<10) /* static eval cache */
449 #else
450 #if defined EXTRA_2MB
451 #define ETABLE (1<<10) /* static eval cache */
452 #else
453 #define ETABLE (1<<8) /* static eval cache */
454 #endif
455 #endif
456 #else
457 #ifdef DEBUG
458 #define ETABLE (1001)
459 #else
460 #define ETABLE (10001) /* static eval cache */
461 #endif
462 #endif
463 /***************** tuning paramaters **********************************************/
464 #if defined VERY_SLOW_CPU
465 #define MINRESPONSETIME 300
466 #elif defined SLOW_CPU
467 #define MINRESPONSETIME 200
468 #else
469 #define MINRESPONSETIME 100 /* 1 s */
470 #endif
471 #define MINGAMEIN 4
472 #define MINMOVES 15
473 #define CHKDEPTH 1 /* always look forward CHKDEPTH half-moves if in check */
474 #if defined SLOW_CPU || defined VERY_SLOW_CPU
475 #define DEPTHBEYOND 7 /* Max to go beyond Sdepth */
476 #else
477 #define DEPTHBEYOND 11 /* Max to go beyond Sdepth */
478 #endif
479 #define HASHDEPTH 4 /* depth above which to use HashFile */
480 #define HASHMOVELIMIT 40 /* Use HashFile only for this many moves */
481 #define PTVALUE 0 /* material value below which pawn threats at 5 & 3 are used */
482 #define ZDEPTH 3 /* depth beyond which to check ZDELTA for extra time */
483 #define ZDELTA 10 /* score delta per ply to cause extra time to be given */
484 #define BESTDELTA 90
485 /* about 1/2 second worth of nodes for your machine */
486 #if defined VERY_SLOW_CPU
487 #define ZNODES (flag.tsume ? 20 : 50) /* check the time every ZNODES positions */
488 #elif defined SLOW_CPU
489 #define ZNODES (flag.tsume ? 40 : 100) /* check the time every ZNODES positions */
490 #else
491 #define ZNODES (flag.tsume ? 400 : 1000) /* check the time every ZNODES positions */
492 #endif
493 #define MAXTCCOUNTX 10 /* max number of time clicks per search to complete ply */
494 #define MAXTCCOUNTR 4 /* max number of time clicks per search extensions*/
495 #define SCORESPLIM 8 /* Score space doesn't apply after this stage */
496 #define SDEPTHLIM (Sdepth+1)
497 #define HISTORYLIM 4096 /* Max value of history killer */
498 #ifdef EXACTHISTORY
499 #if defined SMALL_MEMORY
500 #define HISTORY_MASK 0x8000 /* mask to MSB of history index */
501 #define HISTORY_SIZE 0x10000 /* size of history table */
502 #else
503 #define HISTORY_MASK (1 << 15) /* mask to MSB of history index */
504 #define HISTORY_SIZE (1 << 16) /* size of history table */
505 #endif
506 #else
507 /* smaller history table, but dangerous because of collisions */
508 #define HISTORY_MASK 0x3fff /* mask to significant bits of history index */
509 #if defined SMALL_MEMORY
510 #define HISTORY_SIZE 0x4000 /* size of history table */
511 #else
512 #define HISTORY_SIZE (1 << 14) /* size of history table */
513 #endif
514 #endif
516 #define sizeof_history (sizeof(unsigned short) * (size_t)HISTORY_SIZE)
518 #ifdef EXACTHISTORY
519 /* Map from.to (8bit.8bit) to from.to (0.7bit.8bit) */
520 #define khmove(mv) (mv & 0x7fff)
521 #define hmove(mv) ((mv & 0x7fff) ^ 0x5555)
522 #else
523 /* Map from.to (8bit.8bit) to from.to (00.7bit.7bit) */
524 /* Swap bits of ToSquare in case of promotions, hoping that
525 no catastrophic collision occur. */
526 #define khmove(mv) (((mv & 0x7f00) >> 1) | \
527 ((mv & 0x0080) ? ((mv & 0x007f) ^ 0x007f) : (mv & 0x007f)))
528 #define hmove(mv) (khmove(mv) ^ 0x2aaa)
529 #endif
531 /* mask color to 15th bit */
532 #ifdef EXACTHISTORY
533 #define hindex(c,mv) ((c ? HISTORY_MASK : 0) | hmove(mv))
534 #else
535 /* for white, swap bits, hoping that no catastrophic collision occur. */
536 #define hindex(c,mv) (c ? ((~hmove(mv)) & HISTORY_MASK) : hmove(mv))
537 #endif
539 #define EWNDW 10 /* Eval window to force position scoring at depth greater than Sdepth + 2 */
540 #define WAWNDW 90 /* alpha window when computer black*/
541 #define WBWNDW 90 /* beta window when computer black*/
542 #define BAWNDW 90 /* alpha window when computer white*/
543 #define BBWNDW 90 /* beta window when computer white*/
544 #define BXWNDW 90 /* window to force position scoring at lower */
545 #define WXWNDW 90 /* window to force position scoring at lower */
547 #define DITHER 5 /* max amount random can alter a pos value */
548 #define LBONUS 1 /* points per stage value of L increases */
549 #define BBONUS 2 /* points per stage value of B increases */
550 #define RBONUS 2 /* points per stage value of R increases */
552 #define QUESTIONABLE (valueK) /* malus for questionable moves */
554 #if defined STUPID
555 #undef STUPID
556 #endif
558 #define STUPID (valueR<<1) /* malus for stupid moves */
560 #define KINGPOSLIMIT ( -1) /* King positional scoring limit */
561 #define KINGSAFETY 32
562 #define MAXrehash (7)
564 /************************* parameters for Opening Book *********************************/
565 #define BOOKSIZE 6000 /* Number of unique position/move combinations allowed */
566 #define BOOKMAXPLY 40 /* Max plys to keep in book database */
567 #define BOOKFAIL (BOOKMAXPLY/2) /* if no book move found for BOOKFAIL turns stop using book */
568 #define BOOKPOCKET 64
569 #define BOOKRAND 1000 /* used to select an opening move from a list */
570 #define BOOKENDPCT 950 /* 5 % chance a BOOKEND will stop the book */
571 #define DONTUSE -32760 /* flag move as don't use */
572 #define ILLEGAL_TRAPPED -32761 /* flag move as illegal: no move from this square */
573 #define ILLEGAL_DOUBLED -32762 /* flag move as illegal: two pawns on one column */
574 #define ILLEGAL_MATE -32763 /* flag move as illegal: pawn drop with mate */
575 /*************************** Book access defines ****************************************/
576 #define SIDEMASK 0x1
577 #define LASTMOVE 0x4000 /* means this is the last move of an opening */
578 #define BADMOVE 0x8000 /* means this is a bad move in this position */
579 /****************************************************************************************/
580 struct hashval
582 unsigned long key, bd;
584 struct hashentry
586 unsigned long hashbd;
587 unsigned short mv;
588 unsigned char depth; /* unsigned char saves some space */
589 unsigned char flags;
590 #ifdef notdef
591 unsigned short age;
592 #endif
593 short score;
594 #ifdef HASHTEST
595 unsigned char bd[PTBLBDSIZE];
596 #endif /* HASHTEST */
600 #if defined HASHFILE || defined CACHE
601 struct etable
603 unsigned long ehashbd;
604 short int escore[2];
605 #if !defined SAVE_SSCORE
606 short int sscore[NO_SQUARES];
607 #endif
608 short int score;
609 small_short hung[2];
610 #ifdef CACHETEST
611 unsigned char bd[PTBLBDSIZE];
612 #endif /* CACHETEST */
615 #if defined CACHE
616 extern short use_etable;
617 typedef struct etable etable_field[ETABLE];
618 extern etable_field far *etab[2];
619 #endif
622 * persistent transposition table. By default, the size is (1 << vfilesz). If you
623 * change the size, be sure to run gnuchess -c [vfilesz] before anything else.
625 #define frehash 6
626 #if defined SMALL_MEMORY
627 #define vfilesz 10
628 #else
629 #define vfilesz 14
630 #endif
631 struct fileentry
633 unsigned char bd[PTBLBDSIZE];
634 unsigned char f, t, flags, depth, sh, sl;
637 #endif /* HASHFILE */
640 struct leaf
642 small_ushort f, t;
643 short score, reply, width;
644 short INCscore;
645 unsigned short flags;
647 struct GameRec
649 unsigned short gmove; /* this move */
650 short score; /* score after this move */
651 short depth; /* search depth this move */
652 long time; /* search time this move */
653 short fpiece; /* moved or dropped piece */
654 short piece; /* piece captured */
655 short color; /* color */
656 short flags; /* move flags capture, promote, castle */
657 short Game50; /* flag for repetition */
658 long nodes; /* nodes searched for this move */
659 unsigned long hashkey, hashbd; /* board key before this move */
660 #ifdef DEBUG40
661 int d1;
662 int d2;
663 int d3;
664 int d4;
665 int d5;
666 int d6;
667 int d7;
668 #endif
670 struct TimeControlRec
672 short moves[2];
673 long clock[2];
676 struct flags
678 short mate; /* the game is over */
679 short post; /* show principle variation */
680 short quit; /* quit/exit */
681 short regularstart; /* did the game start from standard
682 * initial board ? */
683 short reverse; /* reverse board display */
684 short bothsides; /* computer plays both sides */
685 short hash; /* enable/disable transposition table */
686 short force; /* enter moves */
687 short easy; /* disable thinking on opponents time */
688 short beep; /* enable/disable beep */
689 short timeout; /* time to make a move */
690 short musttimeout; /* time to make a move */
691 short back; /* time to make a move */
692 short rcptr; /* enable/disable recapture heuristics */
693 short rv; /* reverse video */
694 short stars; /* add stars to uxdsp screen */
695 short coords; /* add coords to visual screen */
696 short shade;
697 short material; /* draw on lack of material */
698 short illegal; /* illegal position */
699 short onemove; /* timing is onemove */
700 short gamein; /* timing is gamein */
701 short tsume; /* first consider checks */
704 extern FILE *debugfile;
706 #ifndef EVALFILE
707 #ifdef THINK_C
708 #define EVALFILE "EVAL"
709 #else
710 #define EVALFILE "/tmp/EVAL"
711 #endif
712 #endif
714 extern FILE *debug_eval_file;
715 extern short debug_eval;
716 extern short debug_moves;
719 #ifdef HISTORY
720 extern short use_history;
721 extern unsigned short far *history;
722 #endif
723 extern long znodes;
725 extern char ColorStr[2][10];
726 #ifdef DEBUG_EVAL
727 extern char *PieceStr[NO_PIECES];
728 #endif
729 extern char mvstr[4][6];
730 extern unsigned short int MV[MAXDEPTH];
731 extern int MSCORE;
732 extern int mycnt1, mycnt2;
733 extern short int ahead;
734 extern short int xshogi;
735 extern struct leaf rootnode;
736 extern struct leaf far *Tree;
737 extern struct leaf far *root;
738 extern char savefile[], listfile[];
739 extern short TrPnt[];
740 extern small_short board[], color[];
741 extern const small_short sweep[NO_PIECES];
742 extern small_short PieceList[2][NO_SQUARES], PawnCnt[2][NO_COLS];
743 extern small_short Captured[2][NO_PIECES];
745 #ifdef NOMEMSET
746 #define ClearCaptured() \
747 { short piece, color;\
748 for (color = black; color <= white; color++)\
749 for (piece = 0; piece < NO_PIECES; piece++)\
750 Captured[color][piece] = 0;\
752 #else
753 #define ClearCaptured() \
754 memset ((char *)Captured, 0,(unsigned long)sizeof(Captured))
755 #endif /* NOMEMSET */
757 extern small_short Mvboard[];
759 #if !defined SAVE_SVALUE
760 extern short svalue[NO_SQUARES];
761 #endif
762 extern short pscore[2]; /* eval.c */
763 extern int EADD; /* eval.c */
764 extern int EGET; /* eval.c */
765 extern struct flags flag;
766 extern short opponent, computer, INCscore;
767 extern short WAwindow, BAwindow, WBwindow, BBwindow;
768 extern short dither, player;
769 extern short xwndw, contempt;
770 extern long ResponseTime, ExtraTime, TCleft, MaxResponseTime, et, et0, time0, ft;
771 extern int TCcount;
772 #ifdef INTERRUPT_TEST
773 extern long itime0, it;
774 #endif
775 extern long reminus, replus;
776 extern long GenCnt, NodeCnt, ETnodes, EvalNodes, HashAdd, HashCnt, HashCol, THashCol,
777 FHashCnt, FHashAdd;
778 extern short HashDepth, HashMoveLimit;
779 extern struct GameRec far *GameList;
780 extern short GameCnt, Game50;
781 extern short Sdepth, MaxSearchDepth;
782 extern int Book;
783 extern struct TimeControlRec TimeControl;
784 extern int TCadd;
785 extern short TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
786 extern int timecomp[MINGAMEIN], timeopp[MINGAMEIN];
787 extern int compptr,oppptr;
788 extern short XCmore, XCmoves[], XCminutes[], XCseconds[], XC;
789 extern const short otherside[];
790 extern const small_short Stboard[];
791 extern const small_short Stcolor[];
792 extern unsigned short hint;
793 extern short int TOflag;
794 extern short stage, stage2;
796 #define in_opening_stage (!flag.tsume && (stage < 33))
797 #define in_middlegame_stage (!flag.tsume && (stage >= 33) && (stage <= 66))
798 #define in_endgame_stage (flag.tsume || (stage > 66))
800 extern short int ahead, hash;
801 extern short balance[2];
802 extern small_short ChkFlag[], CptrFlag[], TesujiFlag[];
803 extern short Pscore[], Tscore[];
804 extern /*unsigned*/ short rehash; /* -1 is used as a flag --tpm */
805 extern char version[], patchlevel[];
806 extern unsigned int ttbllimit;
807 extern unsigned int TTadd;
808 extern unsigned int ttblsize;
809 extern short mtl[], hung[];
810 extern small_short Pindex[];
811 extern small_short PieceCnt[];
812 extern short FROMsquare, TOsquare;
813 extern small_short HasPiece[2][NO_PIECES];
814 extern const short kingP[];
815 extern unsigned short killr0[], killr1[];
816 extern unsigned short killr2[], killr3[];
817 extern unsigned short int PrVar[MAXDEPTH];
818 extern unsigned short PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4, sidebit;
819 extern short mtl[2], pmtl[2], hung[2];
820 extern const small_short relative_value[];
821 extern const long control[];
822 extern small_short diagonal(short delta);
823 extern const small_short promoted[NO_PIECES],unpromoted[NO_PIECES];
824 extern const small_short is_promoted[NO_PIECES];
826 typedef unsigned char next_array[NO_SQUARES][NO_SQUARES];
827 typedef small_short distdata_array[NO_SQUARES][NO_SQUARES];
829 extern const small_short inunmap[NO_SQUARES];
830 extern const small_short nunmap[(NO_COLS+2)*(NO_ROWS+4)];
831 #if defined SAVE_NEXTPOS
832 extern const small_short direc[NO_PTYPE_PIECES][8];
833 extern short first_direction(short ptyp, short *d, short sq);
834 extern short next_direction(short ptyp, short *d, short sq);
835 extern short next_position(short ptyp, short *d, short sq, short u);
836 #else
837 extern short use_nextpos;
838 extern next_array far *nextpos[NO_PTYPE_PIECES];
839 extern next_array far *nextdir[NO_PTYPE_PIECES];
840 #endif
842 extern value_array far *value;
843 extern fscore_array far *fscore;
845 #ifndef SAVE_DISTDATA
846 extern short use_distdata;
847 extern distdata_array far *distdata;
848 #endif
850 #ifndef SAVE_PTYPE_DISTDATA
851 extern short use_ptype_distdata;
852 extern distdata_array far *ptype_distdata[NO_PTYPE_PIECES];
853 #endif
855 extern const small_short ptype[2][NO_PIECES];
857 extern long filesz,hashmask,hashbase;
858 extern FILE *hashfile;
859 extern unsigned int starttime;
861 /* eval.c */
862 typedef small_short Mpiece_array[2][NO_SQUARES];
863 extern Mpiece_array *Mpiece[NO_PIECES];
864 extern short ADVNCM[NO_PIECES];
866 #define computed_distance(a,b) \
867 ((abs(column (a) - column (b)) > abs (row (a) - row (b)))\
868 ? abs(column (a) - column (b)) : abs (row (a) - row (b)))
870 extern short distance (short a, short b);
871 extern short ptype_distance (short ptyp, short f, short t);
872 extern short piece_distance(short side,short piece,short f,short t);
874 #if defined UNKNOWN
875 #undef UNKNOWN
876 #endif
878 #define UNKNOWN 'U'
879 #define STATIC_ROOK 'S'
880 #define RANGING_ROOK 'R'
882 extern char GameType[2];
883 void ShowGameType(void);
885 extern short unsigned bookmaxply;
886 extern int unsigned bookcount;
887 extern int unsigned booksize;
888 extern unsigned long hashkey, hashbd;
890 typedef struct hashval hashcode_array[2][NO_PIECES][NO_SQUARES];
891 typedef struct hashval drop_hashcode_array[2][NO_PIECES][NO_SQUARES];
893 extern hashcode_array far *hashcode;
894 extern drop_hashcode_array far *drop_hashcode;
895 extern char far *CP[];
896 #ifdef QUIETBACKGROUND
897 extern short background;
898 #endif /* QUIETBACKGROUND */
900 #if ttblsz
901 extern short use_ttable;
902 extern struct hashentry far *ttable[2];
903 #endif
906 * hashbd contains a 32 bit "signature" of the board position. hashkey
907 * contains a 16 bit code used to address the hash table. When a move is
908 * made, XOR'ing the hashcode of moved piece on the from and to squares with
909 * the hashbd and hashkey values keeps things current.
911 #define UpdateHashbd(side, piece, f, t) \
913 if ((f) >= 0)\
915 hashbd ^= (*hashcode)[side][piece][f].bd;\
916 hashkey ^= (*hashcode)[side][piece][f].key;\
918 if ((t) >= 0)\
920 hashbd ^= (*hashcode)[side][piece][t].bd;\
921 hashkey ^= (*hashcode)[side][piece][t].key;\
925 #define UpdateDropHashbd(side, piece, count) \
927 hashbd ^= (*drop_hashcode)[side][piece][count].bd;\
928 hashkey ^= (*drop_hashcode)[side][piece][count].key;\
931 extern short rpthash[2][256];
932 extern char *DRAW;
934 #define row(a) ((a) / 9)
935 #define column(a) ((a) % 9)
937 #define locn(a,b) (((a)*9)+b)
939 /* init external functions */
940 extern void InitConst (char *lang); /* init.c */
941 extern int Initialize_data (void); /* init.c */
942 extern void Initialize_dist (void); /* init.c */
943 extern void Initialize_eval (void); /* eval.c */
944 extern void NewGame (void);
945 extern int parse (FILE * fd, short unsigned int *mv, short int side, char *opening);
946 extern void GetOpenings (void);
947 extern int OpeningBook (unsigned short int *hint, short int side);
949 typedef enum { REMOVE_PIECE = 1, ADD_PIECE } UpdatePieceList_mode;
951 extern void UpdatePieceList (short int side, short int sq, UpdatePieceList_mode iop);
953 typedef enum { FOREGROUND_MODE = 1, BACKGROUND_MODE } SelectMove_mode;
955 extern void SelectMove (short int side, SelectMove_mode iop);
956 extern int
957 search (short int side,
958 short int ply,
959 short int depth,
960 short int alpha,
961 short int beta,
962 short unsigned int *bstline,
963 short int *rpt);
964 #ifdef CACHE
965 void
966 PutInEETable (short int side,int score);
968 CheckEETable (short int side);
970 ProbeEETable (short int side, short int *score);
971 #endif
972 #if ttblsz
973 extern int
974 ProbeTTable (short int side,
975 short int depth,
976 short int ply,
977 short int *alpha,
978 short int *beta,
979 short int *score);
980 extern int
981 PutInTTable (short int side,
982 short int score,
983 short int depth,
984 short int ply,
985 short int alpha,
986 short int beta,
987 short unsigned int mv);
988 extern void ZeroTTable (void);
989 extern void ZeroRPT (void);
990 extern void Initialize_ttable (void);
991 extern unsigned int urand (void);
992 #ifdef HASHFILE
993 extern void gsrand (unsigned int);
994 extern int
995 ProbeFTable (short int side,
996 short int depth,
997 short int ply,
998 short int *alpha,
999 short int *beta,
1000 short int *score);
1001 extern void
1002 PutInFTable (short int side,
1003 short int score,
1004 short int depth,
1005 short int ply,
1006 short int alpha,
1007 short int beta,
1008 short unsigned int f,
1009 short unsigned int t);
1011 #endif /* HASHFILE */
1012 #endif /* ttblsz */
1013 #if !defined SAVE_NEXTPOS
1014 extern void Initialize_moves (void);
1015 #endif
1017 extern short generate_move_flags;
1019 extern void MoveList (short int side, short int ply,
1020 short int in_check, short int blockable);
1021 extern void CaptureList (short int side, short int ply,
1022 short int in_check, short int blockable);
1024 /* from ataks.c */
1025 extern int SqAtakd (short int square, short int side, short int *blockable);
1027 extern void
1028 MakeMove (short int side,
1029 struct leaf far *node,
1030 short int *tempb,
1031 short int *tempc,
1032 short int *tempsf,
1033 short int *tempst,
1034 short int *INCscore);
1035 extern void
1036 UnmakeMove (short int side,
1037 struct leaf far *node,
1038 short int *tempb,
1039 short int *tempc,
1040 short int *tempsf,
1041 short int *tempst);
1042 extern void InitializeStats (void);
1043 extern int
1044 evaluate (short int side,
1045 short int ply,
1046 short int alpha,
1047 short int beta,
1048 short int INCscore,
1049 short int *InChk,
1050 short int *blockable);
1051 extern short int ScorePosition (short int side);
1052 extern void ExaminePosition (short side);
1053 extern short ScorePatternDistance(short side);
1054 extern void DetermineStage (short side);
1055 extern void UpdateWeights (short side);
1056 extern int InitMain (void);
1057 extern void ExitMain (void);
1058 extern void Initialize (void);
1059 extern void InputCommand (char *command);
1060 extern void ExitChess (void);
1061 extern void ClrScreen (void);
1062 extern void SetTimeControl (void);
1063 extern void SelectLevel (char *sx);
1064 extern void
1065 UpdateDisplay (short int f,
1066 short int t,
1067 short int flag,
1068 short int iscastle);
1070 typedef enum { COMPUTE_AND_INIT_MODE = 1, COMPUTE_MODE
1071 #ifdef INTERRUPT_TEST
1072 , INIT_INTERRUPT_MODE, COMPUTE_INTERRUPT_MODE
1073 #endif
1074 } ElapsedTime_mode;
1076 extern void ElapsedTime (ElapsedTime_mode iop);
1077 extern void SetResponseTime (short int side);
1078 extern void CheckForTimeout (int score, int globalscore, int Jscore, int zwndw);
1080 extern void ShowSidetoMove (void);
1081 extern void ShowResponseTime (void);
1082 extern void ShowPatternCount (short side, short n);
1083 extern void SearchStartStuff (short int side);
1084 extern void ShowDepth (char ch);
1085 extern void TerminateSearch (int);
1086 extern void
1087 ShowResults (short int score,
1088 short unsigned int *bstline,
1089 char ch);
1090 extern void PromptForMove (void);
1091 extern void SetupBoard (void);
1092 extern void algbr (short int f, short int t, short int flag);
1093 extern void OutputMove (void);
1094 extern void ShowCurrentMove (short int pnt, short int f, short int t);
1095 extern void ListGame (void);
1096 extern void ShowMessage (char *s);
1097 extern void ClrScreen (void);
1098 extern void gotoXY (short int x, short int y);
1099 extern void ClrEoln (void);
1100 extern void DrawPiece (short int sq);
1101 extern void UpdateClocks (void);
1102 extern void DoDebug (void);
1103 extern void DoTable (short table[NO_SQUARES]);
1104 extern void ShowPostnValues (void);
1105 extern void ChangeXwindow (void);
1106 extern void SetContempt (void);
1107 extern void ChangeHashDepth (void);
1108 extern void ChangeBetaWindow (void);
1109 extern void ChangeAlphaWindow (void);
1110 extern void GiveHint (void);
1111 extern void ShowPrompt (void);
1112 extern void EditBoard (void);
1113 extern void help (void);
1114 extern void ChangeSearchDepth (void);
1115 extern void skip (void);
1116 extern void skipb (void);
1117 extern void EnPassant (short int xside, short int f, short int t, short int iop);
1118 extern void ShowNodeCnt (long int NodeCnt);
1119 extern void ShowLine (short unsigned int *bstline);
1120 extern int pick (short int p1, short int p2);
1121 extern short int repetition (void);
1122 extern void TimeCalc (void);
1123 extern short DropPossible (short int piece, short int side, short int sq); /* genmoves.c */
1124 extern short IsCheckmate (short int side, short int in_check, short int blockable); /* genmoves.c */
1127 typedef enum { VERIFY_AND_MAKE_MODE, VERIFY_AND_TRY_MODE, UNMAKE_MODE } VerifyMove_mode;
1129 extern int VerifyMove (char *s, VerifyMove_mode iop, unsigned short *mv);
1130 extern void AgeTT();
1131 extern unsigned short TTage;
1133 struct gdxadmin
1135 unsigned int bookcount;
1136 unsigned int booksize;
1137 unsigned long maxoffset;
1140 extern struct gdxadmin B;