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.
32 /* #define BAREBONES */
35 /* #define SAVE_SSCORE */
36 #if !defined EXTRA_2MB
37 #define SAVE_PTYPE_DISTDATA
38 /* #define SAVE_DISTDATA */
45 #define QUIETBACKGROUND
46 /* #define HASGETTIMEOFDAY */
47 /* #define clocktime() (100l * clock() / CLOCKS_PER_SEC) */
48 #define clocktime() (100l * time(0))
52 #if !defined DEBUG_TTABLE
54 /* #define EXACTHISTORY */
57 /* #define NOTTABLE */
59 #define SEMIQUIETBOOKGEN
62 /* #define DROPBONUS */
63 /* #define FIELDBONUS */
64 /* #define TESUJIBONUS */
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"
77 #define small_short char
78 #define small_ushort unsigned char
84 /* #define BAREBONES */
87 /* #define SAVE_SSCORE */
88 #define SAVE_PTYPE_DISTDATA
89 /* #define SAVE_DISTDATA */
95 /* #define QUIETBACKGROUND */
96 /* #define HASGETTIMEOFDAY */
97 #define clocktime() (100l * time(0))
99 /* #define EXACTHISTORY */
101 #define SEMIQUIETBOOKGEN
102 /* #define NOTTABLE */
105 /* #define DROPBONUS */
106 /* #define FIELDBONUS */
107 /* #define TESUJIBONUS */
108 #define EASY_OPENINGS
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"
118 /* #define NOMEMOPS */
119 /* #include <mem.h> */
121 #define small_short char
122 #define small_ushort unsigned char
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
139 #define HEAP_ALLOC(n) _fmalloc(n)
140 #define HEAP_FREE(p) _ffree(p)
143 #define HEAP_ALLOC(n) malloc(n)
144 #define HEAP_FREE(p) free(p)
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
160 #define array_copy(src,dst,len) _fmemcpy(dst,src,len)
161 #define array_zero(dst,len) _fmemset(dst,0,len)
163 #define array_copy(src,dst,len) memcpy(dst,src,len)
164 #define array_zero(dst,len) memset(dst,0,len)
167 #define array_copy(src,dst,len) bcopy(src,dst,len)
168 #define array_zero(dst,len) bzero(dst,len)
172 #if !defined(__STDC__) && !defined(MSDOS)
183 extern char *binbookfile
;
185 extern char *bookfile
;
186 extern short int ahead
;
187 extern char far
*xwin
;
188 extern char far
*Lang
;
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
);
206 #if !defined NO_STRING_INCLUDE
212 #define RWA_ACC "r+b"
217 #define malloc(size) farmalloc(size)
218 #define RWA_ACC "r+b"
223 #define printz printf
228 #include <sys/param.h>
229 #include <sys/types.h>
230 #include <sys/times.h>
232 #if defined NONDSP || defined THINK_C || defined MSDOS
233 #define printz printf
237 #define scanz fflush(stdout),scanw
238 #define printz printw
242 #if defined(__STDC__) || defined(MSDOS)
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 *, ...);
249 extern int fflush (FILE *);
252 extern int abs (int);
253 extern int atoi (const char *);
256 extern long int time (long int *);
259 extern void *memset (void *, int, size_t);
264 #define MAX_CAPTURED 19
265 #define NO_PTYPE_PIECES 15
266 #define NO_SQUARES 81
267 #define NO_SQUARES_1 80
271 #if defined DEBUG || defined HASHFILE || defined CACHE
272 #define PTBLBDSIZE (NO_SQUARES+NO_PIECES)
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
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))
323 #define OPENING_HINT 0x141d /* P7g-7f (20->29) */
334 /* piece code defines */
351 #define ptype_no_piece 0
353 #define ptype_lance 1
354 #define ptype_knight 2
355 #define ptype_silver 3
357 #define ptype_bishop 5
359 #define ptype_pbishop 7
360 #define ptype_prook 8
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
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
386 #define difficult questionable
394 /***************************************************************************/
395 /***************** Table limits ********************************************/
397 * ttblsz must be a power of 2. Setting ttblsz 0 removes the transposition
402 #elif defined SMALL_MEMORY
403 #if defined SAVE_SSCORE
404 #define vttblsz (1 << 12)
406 #if defined EXTRA_2MB
407 #define vttblsz (1 << 12)
409 #define vttblsz (1 << 10)
414 #define vttblsz (8001)
416 #define vttblsz (100001)
420 #if defined SMALL_MEMORY
421 #define MINTTABLE (0)
424 #define MINTTABLE (2000) /* min ttable size -1 */
426 #define MINTTABLE (8000) /* min ttable size -1 */
430 #define ttblsz vttblsz
432 #if defined SMALL_MEMORY
433 #if !defined SAVE_SSCORE
434 #define TREE 1500 /* max number of tree entries */
436 #define TREE 2500 /* max number of tree entries */
439 #define TREE 4000 /* max number of tree entries */
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 */
450 #if defined EXTRA_2MB
451 #define ETABLE (1<<10) /* static eval cache */
453 #define ETABLE (1<<8) /* static eval cache */
458 #define ETABLE (1001)
460 #define ETABLE (10001) /* static eval cache */
463 /***************** tuning paramaters **********************************************/
464 #if defined VERY_SLOW_CPU
465 #define MINRESPONSETIME 300
466 #elif defined SLOW_CPU
467 #define MINRESPONSETIME 200
469 #define MINRESPONSETIME 100 /* 1 s */
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 */
477 #define DEPTHBEYOND 11 /* Max to go beyond Sdepth */
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 */
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 */
491 #define ZNODES (flag.tsume ? 400 : 1000) /* check the time every ZNODES positions */
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 */
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 */
503 #define HISTORY_MASK (1 << 15) /* mask to MSB of history index */
504 #define HISTORY_SIZE (1 << 16) /* size of history table */
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 */
512 #define HISTORY_SIZE (1 << 14) /* size of history table */
516 #define sizeof_history (sizeof(unsigned short) * (size_t)HISTORY_SIZE)
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)
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)
531 /* mask color to 15th bit */
533 #define hindex(c,mv) ((c ? HISTORY_MASK : 0) | hmove(mv))
535 /* for white, swap bits, hoping that no catastrophic collision occur. */
536 #define hindex(c,mv) (c ? ((~hmove(mv)) & HISTORY_MASK) : hmove(mv))
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 */
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 ****************************************/
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 /****************************************************************************************/
582 unsigned long key
, bd
;
586 unsigned long hashbd
;
588 unsigned char depth
; /* unsigned char saves some space */
595 unsigned char bd
[PTBLBDSIZE
];
596 #endif /* HASHTEST */
600 #if defined HASHFILE || defined CACHE
603 unsigned long ehashbd
;
605 #if !defined SAVE_SSCORE
606 short int sscore
[NO_SQUARES
];
611 unsigned char bd
[PTBLBDSIZE
];
612 #endif /* CACHETEST */
616 extern short use_etable
;
617 typedef struct etable etable_field
[ETABLE
];
618 extern etable_field far
*etab
[2];
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.
626 #if defined SMALL_MEMORY
633 unsigned char bd
[PTBLBDSIZE
];
634 unsigned char f
, t
, flags
, depth
, sh
, sl
;
637 #endif /* HASHFILE */
643 short score
, reply
, width
;
645 unsigned short flags
;
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 */
670 struct TimeControlRec
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
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 */
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
;
708 #define EVALFILE "EVAL"
710 #define EVALFILE "/tmp/EVAL"
714 extern FILE *debug_eval_file
;
715 extern short debug_eval
;
716 extern short debug_moves
;
720 extern short use_history
;
721 extern unsigned short far
*history
;
725 extern char ColorStr
[2][10];
727 extern char *PieceStr
[NO_PIECES
];
729 extern char mvstr
[4][6];
730 extern unsigned short int MV
[MAXDEPTH
];
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
];
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;\
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
];
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
;
772 #ifdef INTERRUPT_TEST
773 extern long itime0
, it
;
775 extern long reminus
, replus
;
776 extern long GenCnt
, NodeCnt
, ETnodes
, EvalNodes
, HashAdd
, HashCnt
, HashCol
, THashCol
,
778 extern short HashDepth
, HashMoveLimit
;
779 extern struct GameRec far
*GameList
;
780 extern short GameCnt
, Game50
;
781 extern short Sdepth
, MaxSearchDepth
;
783 extern struct TimeControlRec TimeControl
;
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
);
837 extern short use_nextpos
;
838 extern next_array far
*nextpos
[NO_PTYPE_PIECES
];
839 extern next_array far
*nextdir
[NO_PTYPE_PIECES
];
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
;
850 #ifndef SAVE_PTYPE_DISTDATA
851 extern short use_ptype_distdata
;
852 extern distdata_array far
*ptype_distdata
[NO_PTYPE_PIECES
];
855 extern const small_short ptype
[2][NO_PIECES
];
857 extern long filesz
,hashmask
,hashbase
;
858 extern FILE *hashfile
;
859 extern unsigned int starttime
;
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
);
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 */
901 extern short use_ttable
;
902 extern struct hashentry far
*ttable
[2];
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) \
915 hashbd ^= (*hashcode)[side][piece][f].bd;\
916 hashkey ^= (*hashcode)[side][piece][f].key;\
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];
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
);
957 search (short int side
,
962 short unsigned int *bstline
,
966 PutInEETable (short int side
,int score
);
968 CheckEETable (short int side
);
970 ProbeEETable (short int side
, short int *score
);
974 ProbeTTable (short int side
,
981 PutInTTable (short int side
,
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);
993 extern void gsrand (unsigned int);
995 ProbeFTable (short int side
,
1002 PutInFTable (short int side
,
1008 short unsigned int f
,
1009 short unsigned int t
);
1011 #endif /* HASHFILE */
1013 #if !defined SAVE_NEXTPOS
1014 extern void Initialize_moves (void);
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
);
1025 extern int SqAtakd (short int square
, short int side
, short int *blockable
);
1028 MakeMove (short int side
,
1029 struct leaf far
*node
,
1034 short int *INCscore
);
1036 UnmakeMove (short int side
,
1037 struct leaf far
*node
,
1042 extern void InitializeStats (void);
1044 evaluate (short int side
,
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
);
1065 UpdateDisplay (short int f
,
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
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);
1087 ShowResults (short int score
,
1088 short unsigned int *bstline
,
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
;
1135 unsigned int bookcount
;
1136 unsigned int booksize
;
1137 unsigned long maxoffset
;
1140 extern struct gdxadmin B
;