home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / game / uchess-2.89.lha / UChess / src / init.c < prev    next >
C/C++ Source or Header  |  1994-06-15  |  20KB  |  825 lines

  1. /*
  2.  * init.c - C source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23. #include "gnuchess.h"
  24.  
  25. #ifdef CACHE
  26. extern struct etable __far __aligned etab[2][ETABLE];
  27. #endif
  28.  
  29. extern int __aligned ThinkInARow;
  30. extern int __aligned bookflag;
  31. extern int __aligned Sdepth2;
  32.  
  33. #ifdef AMIGA
  34. #define __USE_SYSBASE
  35. #define MOVENOWMENUNUM 0x42
  36. #define THINKMENUNUM 0x82
  37. #define SHOWMENUNUM 0xa2
  38. #define BOOKMENUNUM 0xc2
  39. #define SUPERMENUNUM 0xe2
  40. #define ADVANCEDMENUNUM 0x102
  41. #define INTERMEDIATEMENUNUM 0x122
  42. #define EASYMENUNUM 0x142
  43. #include <proto/exec.h>
  44. #include <proto/dos.h>
  45. #include <proto/intuition.h>
  46. extern int __aligned cmptr_sec,cmptr_min,hum_sec,hum_min;
  47. extern int procpri;
  48. extern struct Process *myproc;
  49. extern int __far ResignOffered;
  50. #endif
  51.  
  52. extern struct Menu Menu1;
  53. #define MenuList1 Menu1
  54. extern int MenuStripSet;
  55. extern struct MenuItem MenuItem8ab;
  56. extern struct Window __aligned *wG;
  57. unsigned int urand (void);
  58.  
  59.  
  60. /* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
  61.  
  62.  
  63. void InitHashCode(unsigned int);
  64. short __aligned PCRASH,PCENTER;
  65. extern int PlayMode;
  66. extern unsigned int TTadd;
  67.  
  68. #if defined NULLMOVE || defined DEEPNULL
  69. extern short int __aligned no_null;
  70. extern short int __aligned null;         /* Null-move already made or not */
  71. extern short int __aligned PVari;        /* Is this the PV */
  72. #endif
  73. extern short __aligned Threat[MAXDEPTH];
  74. extern unsigned short int __aligned PrVar[MAXDEPTH];
  75. extern short __aligned PawnStorm;
  76. extern short __aligned start_stage;
  77. extern short __aligned thrashing_tt; /* must we recycle slots at random. TomV */
  78. extern short int ISZERO;
  79. extern int __aligned global_tmp_score;
  80. extern int __aligned previous_score;
  81. int __aligned FirstTime=1;
  82. extern int SupervisorMode;
  83. extern int IllegalMove;
  84. extern int CheckIllegal;
  85. #ifdef LONGINTS2
  86. INTSIZE  __far distdata[64][64];
  87. INTSIZE  __far taxidata[64][64];
  88. #else
  89. INTSIZE  __aligned distdata[64][64];
  90. INTSIZE  __aligned taxidata[64][64];
  91. #endif
  92.  
  93. #ifdef KILLT
  94. /* put moves to the center first */
  95. void
  96. Initialize_killt (void)
  97. {
  98.   REG unsigned INTSIZE f, t, s;
  99.   REG INTSIZE d;
  100.   for (f = 64; f--;)
  101.     for (t = 64; t--;)
  102.       {
  103.     d = taxidata[f][0x1b];
  104.     if (taxidata[f][0x1c] < d)
  105.       d = taxidata[f][0x1c];
  106.     if (taxidata[f][0x23] < d)
  107.       d = taxidata[f][0x23];
  108.     if (taxidata[f][0x24] < d)
  109.       d = taxidata[f][0x24];
  110.     s = d;
  111.     d = taxidata[t][0x1b];
  112.     if (taxidata[t][0x1c] < d)
  113.       d = taxidata[t][0x1c];
  114.     if (taxidata[t][0x23] < d)
  115.       d = taxidata[t][0x23];
  116.     if (taxidata[t][0x24] < d)
  117.       d = taxidata[t][0x24];
  118.     s -= d;
  119.     killt[(f << 8) | t] = s;
  120.     killt[(f << 8) | t | 0x80] = s;
  121.       }
  122. }
  123. #endif
  124. void
  125. Initialize_dist (void)
  126. {
  127.   REG INTSIZE a, b, d, di;
  128.  
  129.   for (a = 0; a < 64; a++)
  130.     for (b = 0; b < 64; b++)
  131.       {
  132.     d = abs (column (a) - column (b));
  133.     di = abs (row (a) - row (b));
  134.     taxidata[a][b] = d + di;
  135.     distdata[a][b] = (d > di ? d : di);
  136.       }
  137. #ifdef KILLT
  138.   Initialize_killt ();
  139. #endif
  140. }
  141.  
  142. const INTSIZE __aligned Stboard[64] =
  143. {rook, knight, bishop, queen, king, bishop, knight, rook,
  144.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  145.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  146.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  147.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  148.  rook, knight, bishop, queen, king, bishop, knight, rook};
  149. const INTSIZE __aligned Stcolor[64] =
  150. {white, white, white, white, white, white, white, white,
  151.  white, white, white, white, white, white, white, white,
  152.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  153.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  154.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  155.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  156.  black, black, black, black, black, black, black, black,
  157.  black, black, black, black, black, black, black, black};
  158. INTSIZE __aligned board[64], color[64];
  159. INTSIZE __aligned amigaboard[64],amigacolor[64];
  160.  
  161. /* given epsquare, from where can a pawn be taken? */
  162. const INTSIZE __aligned epmove1[64] =
  163. {0, 1, 2, 3, 4, 5, 6, 7,
  164.  8, 9, 10, 11, 12, 13, 14, 15,
  165.  16, 24, 25, 26, 27, 28, 29, 30,
  166.  24, 25, 26, 27, 28, 29, 30, 31,
  167.  32, 33, 34, 35, 36, 37, 38, 39,
  168.  40, 32, 33, 34, 35, 36, 37, 38,
  169.  48, 49, 50, 51, 52, 53, 54, 55,
  170.  56, 57, 58, 59, 60, 61, 62, 63};
  171. const INTSIZE __aligned epmove2[64] =
  172. {0, 1, 2, 3, 4, 5, 6, 7,
  173.  8, 9, 10, 11, 12, 13, 14, 15,
  174.  25, 26, 27, 28, 29, 30, 31, 23,
  175.  24, 25, 26, 27, 28, 29, 30, 31,
  176.  32, 33, 34, 35, 36, 37, 38, 39,
  177.  33, 34, 35, 36, 37, 38, 39, 47,
  178.  48, 49, 50, 51, 52, 53, 54, 55,
  179.  56, 57, 58, 59, 60, 61, 62, 63};
  180.  
  181.  
  182. /*
  183.  * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
  184.  * positions reachable from from-square in ppos with piece such that the
  185.  * sequence    ppos = nextpos[piece][from-square]; pdir =
  186.  * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
  187.  * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
  188.  * all squares reachable from sq.
  189.  *
  190.  * If the path is blocked u = pdir[sq] will generate the continuation of the
  191.  * sequence in other directions.
  192.  */
  193.  
  194. unsigned char __far __aligned nextpos[8][64][64];
  195. unsigned char __far __aligned nextdir[8][64][64];
  196.  
  197. /*
  198.  * ptype is used to separate white and black pawns, like this; ptyp =
  199.  * ptype[side][piece] piece can be used directly in nextpos/nextdir when
  200.  * generating moves for pieces that are not black pawns.
  201.  */
  202. const INTSIZE __aligned ptype[2][8] =
  203. {
  204.   no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
  205.   no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
  206.  
  207. /* data used to generate nextpos/nextdir */
  208. static const INTSIZE __aligned direc[8][8] =
  209. {
  210.   0, 0, 0, 0, 0, 0, 0, 0,
  211.   10, 9, 11, 0, 0, 0, 0, 0,
  212.   8, -8, 12, -12, 19, -19, 21, -21,
  213.   9, 11, -9, -11, 0, 0, 0, 0,
  214.   1, 10, -1, -10, 0, 0, 0, 0,
  215.   1, 10, -1, -10, 9, 11, -9, -11,
  216.   1, 10, -1, -10, 9, 11, -9, -11,
  217.   -10, -9, -11, 0, 0, 0, 0, 0};
  218. static const INTSIZE __aligned max_steps[8] =
  219. {0, 2, 1, 7, 7, 7, 1, 2};
  220. static const INTSIZE __aligned nunmap[120] =
  221. {
  222.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  223.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  224.   -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
  225.   -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
  226.   -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
  227.   -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
  228.   -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
  229.   -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
  230.   -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
  231.   -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
  232.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  233.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  234.  
  235. int __aligned InitFlag = false;
  236. void
  237. Initialize_moves (void)
  238.  
  239. /*
  240.  * This procedure pre-calculates all moves for every piece from every square.
  241.  * This data is stored in nextpos/nextdir and used later in the move
  242.  * generation routines.
  243.  */
  244.  
  245. {
  246.   INTSIZE ptyp, po, p0, d, di, s, delta;
  247.   unsigned char *ppos, *pdir;
  248.   INTSIZE dest[8][8];
  249.   INTSIZE steps[8];
  250.   INTSIZE sorted[8];
  251.  
  252.   for (ptyp = 0; ptyp < 8; ptyp++)
  253.     for (po = 0; po < 64; po++)
  254.       for (p0 = 0; p0 < 64; p0++)
  255.     {
  256.       nextpos[ptyp][po][p0] = (unsigned char) po;
  257.       nextdir[ptyp][po][p0] = (unsigned char) po;
  258.     }
  259.   for (ptyp = 1; ptyp < 8; ptyp++)
  260.     for (po = 21; po < 99; po++)
  261.       if (nunmap[po] >= 0)
  262.     {
  263.       ppos = nextpos[ptyp][nunmap[po]];
  264.       pdir = nextdir[ptyp][nunmap[po]];
  265.       /* dest is a function of direction and steps */
  266.       for (d = 0; d < 8; d++)
  267.         {
  268.           dest[d][0] = nunmap[po];
  269.           delta = direc[ptyp][d];
  270.           if (de