home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / game / uchess-2.89.lha / UChess / src / eval.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  55KB  |  2,071 lines

  1. #define WAY4PL64 1 // for K1PK code
  2. //#define PRE4PL67 1 // go back to 4pl63/64 stuff
  3. /*
  4.  * eval.c - C source for GNU CHESS
  5.  *
  6.  * Copyright (c) 1988,1989,1990 John Stanback
  7.  * Copyright (c) 1992 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. #include "gnuchess.h"
  26. #include "ataks.h"
  27. int __aligned EADD = 0;
  28. int __aligned EGET = 0;
  29. int __aligned PUTVAR = false;
  30. #ifdef CACHE
  31. struct etable __far __aligned etab[2][ETABLE];
  32. #endif
  33.  
  34. int ScoreKBNK (short winner, short king1, short king2);
  35. int ScoreKPK (short side,
  36.       short winner,
  37.       short loser,
  38.       short king1,
  39.       register short king2,
  40.       register short sq);
  41.  
  42.  
  43. extern short __aligned PCRASH,PCENTER;
  44. short __aligned QueenCheck[MAXDEPTH]; /* tom@izf.tno.nl */
  45. int __aligned myneweval=1;
  46. short int __aligned sscore[2];
  47. /* Backward pawn bonus indexed by # of attackers on the square */
  48. static const short __aligned BACKWARD[16] =
  49. {-6, -10, -15, -21, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28};
  50.  
  51. /* Bishop mobility bonus indexed by # reachable squares */
  52. static const short __aligned BMBLTY[14] =
  53. {-2, 0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16, 16, 16};
  54.  
  55. /* Rook mobility bonus indexed by # reachable squares */
  56. static const short __aligned RMBLTY[15] =
  57. {0, 2, 4, 6, 8, 10, 11, 12, 13, 14, 14, 14, 14, 14, 14};
  58.  
  59. /* Positional values for a dying king */
  60. static const short __aligned DyingKing[64] =
  61. {0, 8, 16, 24, 24, 16, 8, 0,
  62.  8, 32, 40, 48, 48, 40, 32, 8,
  63.  16, 40, 56, 64, 64, 56, 40, 16,
  64.  24, 48, 64, 72, 72, 64, 48, 24,
  65.  24, 48, 64, 72, 72, 64, 48, 24,
  66.  16, 40, 56, 64, 64, 56, 40, 16,
  67.  8, 32, 40, 48, 48, 40, 32, 8,
  68.  0, 8, 16, 24, 24, 16, 8, 0};
  69.  
  70. /* Isoloted pawn penalty by rank */
  71. static const short __aligned ISOLANI[8] =
  72. {-12, -16, -20, -24, -24, -20, -16, -12};
  73.  
  74. /* table for King Bishop Knight endings */
  75. static const short __aligned KBNK[64] =
  76. #ifdef PRE4PL67KBNK
  77. {99, 90, 80, 70, 60, 50, 40, 40,
  78.  90, 80, 60, 50, 40, 30, 20, 40,
  79.  80, 60, 40, 30, 20, 10, 30, 50,
  80.  70, 50, 30, 10, 0, 20, 40, 60,
  81.  60, 40, 20, 0, 10, 30, 50, 70,
  82.  50, 30, 10, 20, 30, 40, 60, 80,
  83.  40, 20, 30, 40, 50, 60, 80, 90,
  84.  40, 40, 50, 60, 70, 80, 90, 99};
  85. #else
  86. {620, 560, 500, 440, 380, 320, 260, 240,
  87.  560, 520, 460, 400, 340, 280, 230, 260,
  88.  500, 460, 320, 280, 260, 220, 280, 320,
  89.  440, 400, 280, 200, 200, 260, 340, 380,
  90.  380, 340, 260, 200, 200, 280, 400, 440,
  91.  320, 280, 220, 260, 280, 320, 460, 500,
  92.  260, 230, 280, 340, 400, 460, 520, 560,
  93.  240, 260, 320, 380, 440, 500, 560, 620};
  94. #endif
  95.  
  96. /* penalty for threats to king, indexed by number of such threats */
  97. static const short __aligned KTHRT[36] =
  98. {0, -8, -20, -36, -52, -68, -80, -80, -80, -80, -80, -80,
  99.  -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80,
  100.  -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80};
  101.  
  102. /* King positional bonus inopening stage */
  103. static const short __aligned KingOpening[64] =
  104. {0, 0, -4, -10, -10, -4, 0, 0,
  105.  -4, -4, -8, -12, -12, -8, -4, -4,
  106.  -12, -16, -20, -20, -20, -20, -16, -12,
  107.  -16, -20, -24, -24, -24, -24, -20, -16,
  108.  -16, -20, -24, -24, -24, -24, -20, -16,
  109.  -12, -16, -20, -20, -20, -20, -16, -12,
  110.  -4, -4, -8, -12, -12, -8, -4, -4,
  111.  0, 0, -4, -10, -10, -4, 0, 0};
  112.  
  113. /* King positional bonus in end stage */
  114. static const short __aligned KingEnding[64] =
  115. {0, 6, 12, 18, 18, 12, 6, 0,
  116.  6, 12, 18, 24, 24, 18, 12, 6,
  117.  12, 18, 24, 30, 30, 24, 18, 12,
  118.  18, 24, 30, 36, 36, 30, 24, 18,
  119.  18, 24, 30, 36, 36, 30, 24, 18,
  120.  12, 18, 24, 30, 30, 24, 18, 12,
  121.  6, 12, 18, 24, 24, 18, 12, 6,
  122.  0, 6, 12, 18, 18, 12, 6, 0};
  123.  
  124. /* Passed pawn positional bonus */
  125. static const short __aligned PassedPawn0[8] =
  126. {0, 60, 80, 120, 200, 360, 600, 800};
  127. static const short __aligned PassedPawn1[8] =
  128. {0, 30, 40, 60, 100, 180, 300, 800};
  129. static const short __aligned PassedPawn2[8] =
  130. {0, 15, 25, 35, 50, 90, 140, 800};
  131. static const short __aligned PassedPawn3[8] =
  132. {0, 5, 10, 15, 20, 30, 140, 800};
  133.  
  134. /* Knight positional bonus */
  135. static const short __aligned pknight[64] =
  136. {0, 4, 8, 10, 10, 8, 4, 0,
  137.  4, 8, 16, 20, 20, 16, 8, 4,
  138.  8, 16, 24, 28, 28, 24, 16, 8,
  139.  10, 20, 28, 32, 32, 28, 20, 10,
  140.  10, 20, 28, 32, 32, 28, 20, 10,
  141.  8, 16, 24, 28, 28, 24, 16, 8,
  142.  4, 8, 16, 20, 20, 16, 8, 4,
  143.  0, 4, 8, 10, 10, 8, 4, 0};
  144.  
  145. /* Bishop positional bonus */
  146. static const short __aligned pbishop[64] =
  147. {14, 14, 14, 14, 14, 14, 14, 14,
  148.  14, 22, 18, 18, 18, 18, 22, 14,
  149.  14, 18, 22, 22, 22, 22, 18, 14,
  150.  14, 18, 22, 22, 22, 22, 18, 14,
  151.  14, 18, 22, 22, 22, 22, 18, 14,
  152.  14, 18, 22, 22, 22, 22, 18, 14,
  153.  14, 22, 18, 18, 18, 18, 22, 14,
  154.  14, 14, 14, 14, 14, 14, 14, 14};
  155.  
  156. /* Pawn positional bonus */
  157. static const short __aligned PawnAdvance[64] =
  158. {0, 0, 0, 0, 0, 0, 0, 0,
  159.  4, 4, 4, 0, 0, 4, 4, 4,
  160.  6, 8, 2, 10, 10, 2, 8, 6,
  161.  6, 8, 12, 16, 16, 12, 8, 6,
  162.  8, 12, 16, 24, 24, 16, 12, 8,
  163.  12, 16, 24, 32, 32, 24, 16, 12,
  164.  12, 16, 24, 32, 32, 24, 16, 12,
  165.  0, 0, 0, 0, 0, 0, 0, 0};
  166.  
  167.  
  168. #define AHOPEN (-250)
  169.  
  170. short __aligned Mwpawn[64];
  171. short __aligned Mbpawn[64];
  172. short __aligned Mknight[2][64];
  173. short __aligned Mbishop[2][64];
  174. static short __aligned Mking[2][64];
  175. static short __aligned Kfield[2][64];
  176. static short __aligned c1, c2, *atk1, *atk2, *PC1, *PC2;
  177. static short __aligned atak[2][64];
  178. short __aligned emtl[2];
  179. static short __aligned PawnBonus, BishopBonus, RookBonus;
  180. static short __aligned KNIGHTPOST, KNIGHTSTRONG, BISHOPSTRONG, KATAK;
  181. static short __aligned PEDRNK2B, PWEAKH, PADVNCM, PADVNCI, PAWNSHIELD, PDOUBLED, PBLOK;
  182. static short __aligned RHOPN, RHOPNX, KHOPN, KHOPNX, KSFTY;
  183. static short __aligned ATAKD, HUNGP, HUNGX, KCASTLD, KMOVD, XRAY, PINVAL;
  184. short __aligned pscore[2];
  185. short __aligned tmtl;
  186.  
  187. #ifdef CACHE
  188. inline void
  189. PutInEETable (ARGSZ int side,int score)
  190.  
  191. /*
  192.  * Store the current eval position in the transposition table.
  193.  */
  194.  
  195. {
  196.     register struct etable *ptbl;
  197.     ptbl = &etab[side][hashkey % (ETABLE)];
  198. //    if (ptbl->ehashbd == hashbd) return;
  199.     ptbl->ehashbd = hashbd;
  200.     ptbl->escore[white] = pscore[white];
  201.     ptbl->escore[black] = pscore[black];
  202.     ptbl->hung[white] = hung[white];
  203.     ptbl->hung[black] = hung[black];
  204.     ptbl->score = score;
  205. #ifndef AMIGA
  206.     memcpy ( &(ptbl->sscore), svalue, sizeof (svalue));
  207. #else
  208.     MoveMem128(svalue,&(ptbl->sscore));
  209.    /* MoveMem(svalue,&(ptbl->sscore),sizeof (svalue));*/
  210. #endif
  211. /*    bcopy (&(ptbl->sscore), svalue, sizeof (svalue)); */
  212. #if !defined CHESSTOOL && !defined XBOARD
  213.     EADD++;
  214. #endif
  215.     return;
  216. }
  217.  
  218. inline int
  219. CheckEETable (ARGSZ int side)
  220.  
  221. /* Get an evaluation from the transposition table */
  222. {
  223.     register struct etable *ptbl;
  224.     ptbl = &etab[side][hashkey % (ETABLE)];
  225.     if (hashbd == ptbl->ehashbd) return true;
  226.     return false;
  227. }
  228.  
  229. inline int
  230. ProbeEETable (short int side, short int *score)
  231.  
  232. /* Get an evaluation from the transposition table */
  233. {
  234.     register struct etable *ptbl;
  235.     ptbl = &etab[side][hashkey % (ETABLE)];
  236.     if (hashbd == ptbl->ehashbd)
  237.       {
  238.       pscore[white] = ptbl->escore[white];
  239.       pscore[black] = ptbl->escore[black];
  240. #ifndef AMIGA
  241.       memcpy (svalue, &(ptbl->sscore), sizeof (svalue));
  242. #else
  243.       MoveMem128(&(ptbl->sscore),svalue);
  244.      /* MoveMem (&(ptbl->sscore),svalue, sizeof (svalue));*/
  245. #endif
  246.       *score = ptbl->score;
  247.           hung[white] = ptbl->hung[white];
  248.           hung[black] = ptbl->hung[black];
  249. #if !defined CHESSTOOL && !defined XBOARD
  250.       EGET++;
  251. #endif
  252.       return true;
  253.       }
  254.     return false;
  255.  
  256. }
  257.  
  258. #endif
  259.  
  260.  
  261.  
  262. short dist_ (short, short, short, short);
  263. short kpkwv_ (short, short, short, short, short, short);
  264.  
  265. #ifndef PRE4PL67
  266.  
  267. short 
  268. kpkwv_ (short pf, short pr, short wf, short wr, short bf, short br)
  269. {
  270.  
  271.   /*
  272.    *  Don B