home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuch40.zip / gnuchess-4.0.pl79 / src / ttable.h < prev    next >
C/C++ Source or Header  |  1998-09-28  |  5KB  |  188 lines

  1. /*
  2.  * ttable.h - Transposition Table for GNU Chess
  3.  *
  4.  * Copyright (c) 1985-1996 Stuart Cracraft, John Stanback,
  5.  *                         Daryl Baker, Conor McCarthy,
  6.  *                         Mike McGann, Chua Kong Sian
  7.  * Copyright (c) 1985-1996 Free Software Foundation
  8.  *
  9.  * This file is part of GNU CHESS.
  10.  *
  11.  * GNU Chess is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  *
  16.  * GNU Chess is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GNU Chess; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25. /************************* Tuning parameters ****************************/
  26.  
  27. /*
  28.  * ttblsz can be a any size. #undef ttblsz to remove the transposition
  29.  * tables.
  30.  */
  31. #ifndef ttblsz
  32. #if defined(MSDOS) 
  33. #define ttblsz 8001
  34. #else
  35. #define ttblsz 150001
  36. #endif /* MSDOS */
  37. #endif /* ttblsz*/
  38.  
  39. #define MINTTABLE (8000)    /* min ttable size -1 */
  40. #define MAXrehash (7)
  41.  
  42. #if defined MORESTATS
  43. #if !defined HASHSTATS
  44. #define HASHSTATS            /* Enable hash statistics */  
  45. #endif
  46. #endif
  47. #if defined AGING
  48. #define NEWAGE (8)
  49. #endif
  50.  
  51. #ifdef BAREBONES /* Remove all stats for RAW speed */
  52. #undef   HASHSTATS
  53. #endif /* BAREBONES */
  54.  
  55. /************************* Hash table stuf ****************************/
  56. extern /*unsigned*/ SHORT rehash;  /* main.c */ /* -1 is used as a flag --tpm */
  57. extern unsigned long ttblsize; /* main.c */
  58. extern UTSHORT  newage;
  59.  
  60. #ifdef ttblsz
  61. extern void Initialize_ttable (void);
  62. extern void ZeroTTable (int iop); /* iop: 0= clear any, 1= clear agged */
  63. extern int
  64.       ProbeTTable (SHORT side,
  65.         SHORT depth,
  66.         SHORT ply,
  67.         SHORT *alpha,
  68.         SHORT *beta,
  69.         SHORT *score);
  70. extern int
  71.       PutInTTable (SHORT side,
  72.         SHORT score,
  73.         SHORT depth,
  74.         SHORT ply,
  75.         SHORT alpha,
  76.         SHORT beta,
  77.         UTSHORT mv);
  78. #else
  79. #define Initialize_ttable(void)
  80. #define ZeroTTable(iop)
  81. #define ProbeTTable(side,depth,ply,alpha,beta,score) (false)
  82. #define PutInTTable(side,score,depth,ply,alpha,beta,mv) (false)
  83. #endif /* ttblsz */
  84.  
  85. /************************* Hash File Stuf ****************************/
  86.  
  87. #ifdef HASHFILE
  88. extern FILE *hashfile;  /* search.c: test if hashfile is opened */
  89.  
  90. extern int
  91.       ProbeFTable (SHORT side,
  92.             SHORT depth,
  93.             SHORT ply,
  94.             SHORT *alpha,
  95.             SHORT *beta,
  96.             SHORT *score);
  97. extern void
  98.       PutInFTable (SHORT side,
  99.             SHORT score,
  100.             SHORT depth,
  101.             SHORT ply,
  102.             SHORT alpha,
  103.             SHORT beta,
  104.             UTSHORT f,
  105.             UTSHORT t);
  106.  
  107.  
  108. extern void TestHashFile();
  109. extern void CreateHashFile(long sz);
  110. extern void OpenHashFile();
  111. extern void CloseHashFile();
  112. #else /* Define null ops so we dont need ifdefs */
  113. #define hashfile (NULL)
  114. #define OpenHashFile()
  115. #define CloseHashFile()
  116. #define ProbeFTable(side,depth,ply,alpha,beta,score) (0)
  117. #define PutInFTable(side,score,depth,ply,alpha,beta,f,t)
  118. #endif /* HASHFILE */
  119.  
  120.  
  121. /************************hash code stuff **************************/
  122. struct hashval
  123.   {
  124.      unsigned long key, bd;
  125.   };
  126.  
  127. extern struct hashval hashcode[2][7][64];
  128. extern void InitHashCode(unsigned int seed);
  129.  
  130. /*
  131.  * hashbd contains a 32 bit "signature" of the board position. hashkey
  132.  * contains a 16 bit code used to address the hash table. When a move is
  133.  * made, XOR'ing the hashcode of moved piece on the from and to squares with
  134.  * the hashbd and hashkey values keeps things current.
  135.  */
  136. extern unsigned long hashkey, hashbd;
  137.  
  138. #define UpdateHashbd(side, piece, f, t) \
  139. {\
  140.   if ((f) >= 0)\
  141.     {\
  142.       hashbd ^= hashcode[side][piece][f].bd;\
  143.       hashkey ^= hashcode[side][piece][f].key;\
  144.     }\
  145.   if ((t) >= 0)\
  146.     {\
  147.       hashbd ^= hashcode[side][piece][t].bd;\
  148.       hashkey ^= hashcode[side][piece][t].key;\
  149.     }\
  150. }
  151.  
  152. extern void gsrand (unsigned int);
  153. extern unsigned int urand (void);
  154.  
  155. /************************* Repitition hash table ****************************/
  156.  
  157. extern SHORT rpthash[2][256];
  158. extern void ZeroRPT (void);
  159. #define ProbeRPThash(side,hashkey) (rpthash[side][hashkey & 0xFF] > 0)
  160. #define IncrementRPThash(side,hashkey) {rpthash[side][hashkey & 0xFF]++;}
  161. #define DecrementRPThash(side,hashkey) {rpthash[side][hashkey & 0xFF]--;}
  162.  
  163. /************************* Evaluation cache ********************************/
  164.  
  165. #ifdef CACHE
  166.     struct etable
  167.     { unsigned long ehashbd;
  168.         tshort escore[2];
  169.         tshort sscore[64];
  170.         tshort score;
  171.         tshort hung[2];
  172.     } ;
  173. extern struct etable *etab[2];
  174. extern UTSHORT ETABLE;
  175. #endif
  176.  
  177. /************************* Hash table statistice ****************************/
  178.  
  179. #ifdef HASHSTATS
  180. void ClearHashStats();    /* initialize the stats */
  181. void ShowHashStats();    /* print the stats */
  182. extern long EADD, EGET; /* Evaluation cache stats counters */
  183. extern unsigned long HashCnt, HashAdd, FHashCnt, FHashAdd, HashCol, THashCol;
  184. #else
  185. #define ClearHashStats()        /* stats calls ignored */
  186. #define ShowHashStats()
  187. #endif
  188.