home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / useful / game / think / uchess.lha / UChess / src / init.c < prev    next >
C/C++ Source or Header  |  1994-02-23  |  20KB  |  797 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 AMIGA
  26. #define __USE_SYSBASE
  27. #define MOVENOWMENUNUM 0x42
  28. #define THINKMENUNUM 0x82
  29. #define SHOWMENUNUM 0xa2
  30. #define BOOKMENUNUM 0xc2
  31. #define SUPERMENUNUM 0xe2
  32. #define ADVANCEDMENUNUM 0x102
  33. #define INTERMEDIATEMENUNUM 0x122
  34. #define EASYMENUNUM 0x142
  35. #include <proto/exec.h>
  36. #include <proto/dos.h>
  37. #include <proto/intuition.h>
  38. extern int procpri;
  39. extern struct Process *myproc;
  40. extern int __far ResignOffered;
  41. #endif
  42.  
  43. extern struct Menu Menu1;
  44. #define MenuList1 Menu1
  45. extern int MenuStripSet;
  46. extern struct MenuItem MenuItem8ab;
  47. extern struct Window __aligned *wG;
  48. unsigned int urand (void);
  49.  
  50.  
  51. /* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
  52.  
  53.  
  54. short __aligned PCRASH,PCENTER;
  55. extern int PlayMode;
  56. extern unsigned int TTadd;
  57.  
  58. #ifdef NULLMOVE
  59. extern short int __aligned no_null;
  60. extern short int __aligned null;         /* Null-move already made or not */
  61. extern short int __aligned PVari;        /* Is this the PV */
  62. #endif
  63. extern short __aligned Threat[MAXDEPTH];
  64. extern unsigned short int __aligned PrVar[MAXDEPTH];
  65. extern short __aligned PawnStorm;
  66. extern short __aligned start_stage;
  67. extern short __aligned thrashing_tt; /* must we recycle slots at random. TomV */
  68. extern short int ISZERO;
  69. extern int __aligned global_tmp_score;
  70. extern int __aligned previous_score;
  71. int __aligned FirstTime=1;
  72. extern int SupervisorMode;
  73. extern int IllegalMove;
  74. extern int CheckIllegal;
  75. #ifdef LONGINTS2
  76. INTSIZE  __far distdata[64][64];
  77. INTSIZE  __far taxidata[64][64];
  78. #else
  79. INTSIZE  __aligned distdata[64][64];
  80. INTSIZE  __aligned taxidata[64][64];
  81. #endif
  82.  
  83. #ifdef KILLT
  84. /* put moves to the center first */
  85. void
  86. Initialize_killt (void)
  87. {
  88.   REG unsigned INTSIZE f, t, s;
  89.   REG INTSIZE d;
  90.   for (f = 64; f--;)
  91.     for (t = 64; t--;)
  92.       {
  93.     d = taxidata[f][0x1b];
  94.     if (taxidata[f][0x1c] < d)
  95.       d = taxidata[f][0x1c];
  96.     if (taxidata[f][0x23] < d)
  97.       d = taxidata[f][0x23];
  98.     if (taxidata[f][0x24] < d)
  99.       d = taxidata[f][0x24];
  100.     s = d;
  101.     d = taxidata[t][0x1b];
  102.     if (taxidata[t][0x1c] < d)
  103.       d = taxidata[t][0x1c];
  104.     if (taxidata[t][0x23] < d)
  105.       d = taxidata[t][0x23];
  106.     if (taxidata[t][0x24] < d)
  107.       d = taxidata[t][0x24];
  108.     s -= d;
  109.     killt[(f << 8) | t] = s;
  110.     killt[(f << 8) | t | 0x80] = s;
  111.       }
  112. }
  113. #endif
  114. void
  115. Initialize_dist (void)
  116. {
  117.   REG INTSIZE a, b, d, di;
  118.  
  119.   for (a = 0; a < 64; a++)
  120.     for (b = 0; b < 64; b++)
  121.       {
  122.     d = abs (column (a) - column (b));
  123.     di = abs (row (a) - row (b));
  124.     taxidata[a][b] = d + di;
  125.     distdata[a][b] = (d > di ? d : di);
  126.       }
  127. #ifdef KILLT
  128.   Initialize_killt ();
  129. #endif
  130. }
  131.  
  132. const INTSIZE __aligned Stboard[64] =
  133. {rook, knight, bishop, queen, king, bishop, knight, rook,
  134.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  135.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  136.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  137.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  138.  rook, knight, bishop, queen, king, bishop, knight, rook};
  139. const INTSIZE __aligned Stcolor[64] =
  140. {white, white, white, white, white, white, white, white,
  141.  white, white, white, white, white, white, white, white,
  142.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  143.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  144.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  145.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  146.  black, black, black, black, black, black, black, black,
  147.  black, black, black, black, black, black, black, black};
  148. INTSIZE board[64], color[64];
  149.  
  150. /* given epsquare, from where can a pawn be taken? */
  151. const INTSIZE __aligned epmove1[64] =
  152. {0, 1, 2, 3, 4, 5, 6, 7,
  153.  8, 9, 10, 11, 12, 13, 14, 15,
  154.  16, 24, 25, 26, 27, 28, 29, 30,
  155.  24, 25, 26, 27, 28, 29, 30, 31,
  156.  32, 33, 34, 35, 36, 37, 38, 39,
  157.  40, 32, 33, 34, 35, 36, 37, 38,
  158.  48, 49, 50, 51, 52, 53, 54, 55,
  159.  56, 57, 58, 59, 60, 61, 62, 63};
  160. const INTSIZE __aligned epmove2[64] =
  161. {0, 1, 2, 3, 4, 5, 6, 7,
  162.  8, 9, 10, 11, 12, 13, 14, 15,
  163.  25, 26, 27, 28, 29, 30, 31, 23,
  164.  24, 25, 26, 27, 28, 29, 30, 31,
  165.  32, 33, 34, 35, 36, 37, 38, 39,
  166.  33, 34, 35, 36, 37, 38, 39, 47,
  167.  48, 49, 50, 51, 52, 53, 54, 55,
  168.  56, 57, 58, 59, 60, 61, 62, 63};
  169.  
  170.  
  171. /*
  172.  * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
  173.  * positions reachable from from-square in ppos with piece such that the
  174.  * sequence    ppos = nextpos[piece][from-square]; pdir =
  175.  * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
  176.  * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
  177.  * all squares reachable from sq.
  178.  *
  179.  * If the path is blocked u = pdir[sq] will generate the continuation of the
  180.  * sequence in other directions.
  181.  */
  182.  
  183. unsigned char __far __aligned nextpos[8][64][64];
  184. unsigned char __far __aligned nextdir[8][64][64];
  185.  
  186. /*
  187.  * ptype is used to separate white and black pawns, like this; ptyp =
  188.  * ptype[side][piece] piece can be used directly in nextpos/nextdir when
  189.  * generating moves for pieces that are not black pawns.
  190.  */
  191. const INTSIZE __aligned ptype[2][8] =
  192. {
  193.   no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
  194.   no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
  195.  
  196. /* data used to generate nextpos/nextdir */
  197. static const INTSIZE __aligned direc[8][8] =
  198. {
  199.   0, 0, 0, 0, 0, 0, 0, 0,
  200.   10, 9, 11, 0, 0, 0, 0, 0,
  201.   8, -8, 12, -12, 19, -19, 21, -21,
  202.   9, 11, -9, -11, 0, 0, 0, 0,
  203.   1, 10, -1, -10, 0, 0, 0, 0,
  204.   1, 10, -1, -10, 9, 11, -9, -11,
  205.   1, 10, -1, -10, 9, 11, -9, -11,
  206.   -10, -9, -11, 0, 0, 0, 0, 0};
  207. static const INTSIZE __aligned max_steps[8] =
  208. {0, 2, 1, 7, 7, 7, 1, 2};
  209. static const INTSIZE __aligned nunmap[120] =
  210. {
  211.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  212.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  213.   -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
  214.   -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
  215.   -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
  216.   -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
  217.   -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
  218.   -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
  219.   -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
  220.   -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
  221.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  222.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  223.  
  224. int __aligned InitFlag = false;
  225. void
  226. Initialize_moves (void)
  227.  
  228. /*
  229.  * This procedure pre-calculates all moves for every piece from every square.
  230.  * This data is stored in nextpos/nextdir and used later in the move
  231.  * generation routines.
  232.  */
  233.  
  234. {
  235.   INTSIZE ptyp, po, p0, d, di, s, delta;
  236.   unsigned char *ppos, *pdir;
  237.   INTSIZE dest[8][8];
  238.   INTSIZE steps[8];
  239.   INTSIZE sorted[8];
  240.  
  241.   for (ptyp = 0; ptyp < 8; ptyp++)
  242.     for (po = 0; po < 64; po++)
  243.       for (p0 = 0; p0 < 64; p0++)
  244.     {
  245.       nextpos[ptyp][po][p0] = (unsigned char) po;
  246.       nextdir[ptyp][po][p0] = (unsigned char) po;
  247.     }
  248.   for (ptyp = 1; ptyp < 8; ptyp++)
  249.     for (po = 21; po < 99; po++)
  250.       if (nunmap[po] >= 0)
  251.     {
  252.       ppos = nextpos[ptyp][nunmap[po]];
  253.       pdir = nextdir[ptyp][nunmap[po]];
  254.       /* dest is a function of direction and steps */
  255.       for (d = 0; d < 8; d++)
  256.         {
  257.           dest[d][0] = nunmap[po];
  258.           delta = direc[ptyp][d];
  259.           if (delta != 0)
  260.         {
  261.           p0 = po;
  262.           for (s = 0; s < max_steps[ptyp]; s++)
  263.             {
  264.               p0 = p0 + delta;
  265.  
  266.               /*
  267.                * break if (off board) or (pawns only move two
  268.                * steps from home square)
  269.                */
  270.               if ((nunmap[p0] < 0) || (((ptyp == pawn) || (ptyp == bpawn))
  271.                            && ((s > 0) && ((d > 0) || (Stboard[nunmap[po]] != pawn)))))
  272.             break;
  273.               else
  274.             dest[d][s] = nunmap[p0];
  275.             }
  276.         }
  277.           else
  278.         s = 0;
  279.  
  280.           /*
  281.            * sort dest in number of steps order currently no sort
  282.            * is done due to compability with the move generation
  283.            * order in old gnu chess
  284.            */
  285.           steps[d] = s;
  286.           for (di = d; s > 0 && di > 0; di--)
  287.         if (steps[sorted[di - 1]] == 0)    /* should be: < s */
  288.           sorted[di] = sorted[di - 1];
  289.         else
  290.           break;
  291.           sorted[di] = d;
  292.         }
  293.  
  294.       /*
  295.        * update nextpos/nextdir, pawns have two threads (capture
  296.        * and no capture)
  297.        */
  298.       p0 = nunmap[po];
  299.       if (ptyp == pawn || ptyp == bpawn)
  300.         {
  301.           for (s = 0; s < steps[0]; s++)
  302.         {
  303.           ppos[p0] = (unsigned char) dest[0][s];
  304.           p0 = dest[0][s];
  305.         }
  306.           p0 = nunmap[po];
  307.           for (d = 1; d < 3; d++)
  308.         {
  309.           pdir[p0] = (unsigned char) dest[d][0];
  310.           p0 = dest[d][0];
  311.         }
  312.         }
  313.       else
  314.         {
  315.           pdir[p0] = (unsigned char) dest[sorted[0]][0];
  316.           for (d = 0; d < 8; d++)
  317.         for (s = 0; s < steps[sorted[d]]; s++)
  318.           {
  319.             ppos[p0] = (unsigned char) dest[sorted[d]][s];
  320.             p0 = dest[sorted[d]][s];
  321.             if (d < 7)
  322.               pdir[p0] = (unsigned char) dest[sorted[d + 1]][0];
  323.  
  324.             /*
  325.              * else is already initialized
  326.              */
  327.           }
  328.         }
  329.     }
  330. }
  331.  
  332. void
  333. NewGame (void)
  334.  
  335. /*
  336.  * Reset the board and other variables to start a new game.
  337.  */
  338.  
  339. {
  340.   INTSIZE l, p;
  341.   int tmp;
  342.   char tstr[32];
  343.   INTSIZE a, r, c, sq, i, found;
  344.   int tmpcolor;
  345.   char s[16];
  346.  
  347.  TTadd = ISZERO = 1;
  348.  if (AmigaStarted)
  349.   {
  350.    if (FirstTime)
  351.     {
  352.      FirstTime = 0;
  353.     }
  354.    else
  355.     {
  356.      if (!LoadFullBitMap())
  357.       {
  358.        ExitChess();
  359.       }
  360.      (void)SetTaskPri((struct Task *)myproc,procpri);
  361.     }
  362.   }
  363. /* SupervisorMode = 0;*/
  364.  previous_score = 0;
  365.  global_tmp_score = 0;
  366.  CheckIllegal = IllegalMove = 0;
  367.   Mate = 0;
  368.  ResignOffered = 0;
  369.  ThinkAheadDepth = ThinkAheadWorked = 0;
  370.  DrawnGame = 0;
  371.  MateString[0] = '\0';
  372.   compptr = oppptr = 0; // was -1 in 2.35
  373.   stage = stage2 = -1;        /* the game is not yet started */
  374.   flag.illegal = flag.mate = flag.quit = flag.reverse = flag.bothsides = flag.onemove = flag.force = false;
  375.   flag.material = flag.coords = flag.hash = flag.beep = flag.rcptr = true;
  376.   flag.threat = true;
  377.   flag.stars = flag.shade = flag.back = flag.musttimeout = false;
  378. #ifdef CLIENT
  379.   flag.gamein = true;
  380. #else 
  381.   flag.gamein = false;
  382. #endif
  383. #if defined(MSDOS) && !defined(SEVENBIT)
  384.   flag.rv = false;
  385. #else
  386.   flag.rv = true;
  387. #endif /* MSDOS && !SEVENBIT */
  388.  
  389.   mycnt1 = mycnt2 = 0;
  390.   GenCnt = NodeCnt = et0 = epsquare = XCmore = 0;
  391.   dither = 0;
  392.   WAwindow = WAWNDW;
  393.   WBwindow = WBWNDW;
  394.   BAwindow = BAWNDW;
  395.   BBwindow = BBWNDW;
  396.   xwndw = BXWNDW;
  397.   if (!MaxSearchDepth)
  398.     MaxSearchDepth = MAXDEPTH - 1;
  399.   contempt = 0;
  400.   GameCnt = 0;
  401.   Game50 = 1;
  402.   hint = 0x0C14;
  403.   ISZERO = 1;
  404.   ZeroRPT ();
  405.   Developed[white] = Developed[black] = false;
  406.   MouseDropped = 0;
  407.   Castled[white] = Castled[black] = 0;
  408.   myEnPassant[white] = myEnPassant[black] = 0;
  409.   castld[white] = castld[black] = false;
  410. #ifdef NULLMOVE
  411.   no_null=0;
  412.   null = 0;         /* Null-move already made or not */
  413.   PVari = 0;        /* Is this the PV */
  414. #endif
  415.   PawnStorm = start_stage = 0;
  416.   thrashing_tt = 0; /* must we recycle slots at random. TomV */
  417.   ClearMem(QueenCheck,MAXDEPTH*sizeof(short));
  418.   ClearMem(PrVar,MAXDEPTH*sizeof(short));
  419.   ClearMem(Threat,MAXDEPTH*sizeof(short));
  420.   ClearMem(ThreatSave,MAXDEPTH*sizeof(short));
  421.   ClearMem(Pscore,MAXDEPTH*sizeof(short));
  422.   ClearMem(Tscore,MAXDEPTH*sizeof(short));
  423.   ClearMem(ChkFlag,MAXDEPTH*sizeof(short));
  424.   ClearMem(CptrFlag,MAXDEPTH*sizeof(short));
  425.   ClearMem(PawnThreat,MAXDEPTH*sizeof(short));
  426.   PawnThreat[0] = CptrFlag[0] = false;
  427.   Pscore[0] = 12000;
  428.   Tscore[0] = 12000;
  429.   opponent = white;
  430.   computer = black;
  431.   for (l = 0; l < TREE; l++)
  432.     Tree[l].f = Tree[l].t = 0;
  433.  gsrand ((unsigned int) 1);
  434.   if (!InitFlag)
  435.     {
  436.       for (c = white; c <= black; c++)
  437.     for (p = pawn; p <= king; p++)
  438.       for (l = 0; l < 64; l++)
  439.         {
  440.           hashcode[c][p][l].key = (((unsigned long) urand ()));
  441.           hashcode[c][p][l].key += (((unsigned long) urand ()) << 16);
  442.           hashcode[c][p][l].bd = (((unsigned long) urand ()));
  443.           hashcode[c][p][l].bd += (((unsigned long) urand ()) << 16);
  444. #ifdef LONG64
  445.           hashcode[c][p][l].key += (((unsigned long) urand ()) << 32);
  446.           hashcode[c][p][l].key += (((unsigned long) urand ()) << 48);
  447.           hashcode[c][p][l].bd += (((unsigned long) urand ()) << 32);
  448.           hashcode[c][p][l].bd += (((unsigned long) urand ()) << 48);
  449. #endif
  450.         }
  451.     }
  452.   for (l = 0; l < 64; l++)
  453.     {
  454.       board[l] = Stboard[l];
  455.       color[l] = Stcolor[l];
  456.       Mvboard[l] = 0;
  457.     }
  458.   InitializeStats ();
  459.   time0 = time ((long *) 0);
  460.   ElapsedTime (1);
  461.   flag.regularstart = true;
  462.   if (MenuStripSet)
  463.    {
  464.     MenuItem8ab.Flags |= CHECKED;
  465.     SetMenuStrip(wG,&MenuList1);    /* attach any Menu */
  466.    }
  467.   Book = BOOKFAIL;
  468.   if (!InitFlag)
  469.     {
  470.       if (TCflag)
  471.        {
  472.         strcpy(tstr,"60 10");
  473.     SelectLevel (tstr);
  474.     SetTimeControl ();
  475.        }
  476.       else if (MaxResponseTime == 0)
  477.        {
  478.         strcpy(tstr,"60 10");
  479.     SelectLevel (tstr);
  480.     SetTimeControl ();
  481.        }
  482.       UpdateDisplay (0, 0, 1, 0);
  483. /*    GetOpenings(black);*/
  484. #ifdef CACHE
  485.       Initialize_ttable();
  486. #endif
  487.       InitFlag = true;
  488.     }
  489.    else
  490.     {
  491.       if (TCflag)
  492.        {
  493.         sprintf(tstr,"%d %d",TCmoves,TCminutes);
  494.     SelectLevel (tstr);
  495.     SetTimeControl ();
  496.        }
  497.     }
  498.   GetOpenings(black);
  499.   hashbd = hashkey = 0;
  500. #ifdef AMIGA
  501.   tmp = player;
  502.   player = white;
  503.   UpdateClocks();
  504.   player = black;
  505.   UpdateClocks();
  506.   player = tmp;
  507. #endif
  508. #ifdef CACHE
  509. #if ttblsz
  510.   ZeroTTable ();
  511.   TTadd = 0;
  512. #endif /* ttblsz */
  513. #endif
  514.  if (PlayMode == 1)
  515.   {
  516.     flag.regularstart = false;
  517.     Book = 0;
  518.  
  519.       strcpy(s," g8");
  520.       a = tmpcolor = black;
  521.       c = s[1] - 'a';
  522.       r = s[2] - '1';
  523.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  524.     {
  525.       sq = locn (r, c);
  526.       color[sq] = a;
  527.       board[sq] = no_piece;
  528.       for (i = no_piece; i <= king; i++)
  529.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  530.           {
  531.         board[sq] = i;
  532.         found=1;
  533.         break;
  534.           }
  535.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  536.     }
  537.       strcpy(s," b8");
  538.       a = tmpcolor = black;
  539.       c = s[1] - 'a';
  540.       r = s[2] - '1';
  541.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  542.     {
  543.       sq = locn (r, c);
  544.       color[sq] = a;
  545.       board[sq] = no_piece;
  546.       for (i = no_piece; i <= king; i++)
  547.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  548.           {
  549.         board[sq] = i;
  550.         found=1;
  551.         break;
  552.           }
  553.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  554.     }
  555.  
  556.     if (MenuStripSet)
  557.      {
  558.       OnMenu(wG,ADVANCEDMENUNUM);
  559.       OffMenu(wG,BOOKMENUNUM);
  560.       OffMenu(wG,INTERMEDIATEMENUNUM); 
  561.       OnMenu(wG,EASYMENUNUM); 
  562.      }
  563.     GameCnt = 0;
  564.     Game50 = 1;
  565.     ISZERO = 1;
  566.     ZeroRPT ();
  567.     Sdepth = 0;
  568.     InitializeStats ();
  569.     DrawAmigaBoard();
  570.   }
  571.  else if (PlayMode == 0)
  572.   {
  573.     flag.regularstart = false;
  574.     Book = 0;
  575.  
  576.       strcpy(s," d8");
  577.       a = tmpcolor = black;
  578.       c = s[1] - 'a';
  579.       r = s[2] - '1';
  580.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  581.     {
  582.       sq = locn (r, c);
  583.       color[sq] = a;
  584.       board[sq] = no_piece;
  585.       for (i = no_piece; i <= king; i++)
  586.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  587.           {
  588.         board[sq] = i;
  589.         found=1;
  590.         break;
  591.           }
  592.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  593.     }
  594.       strcpy(s," g8");
  595.       a = tmpcolor = black;
  596.       c = s[1] - 'a';
  597.       r = s[2] - '1';
  598.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  599.     {
  600.       sq = locn (r, c);
  601.       color[sq] = a;
  602.       board[sq] = no_piece;
  603.       for (i = no_piece; i <= king; i++)
  604.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  605.           {
  606.         board[sq] = i;
  607.         found=1;
  608.         break;
  609.           }
  610.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  611.     }
  612.       strcpy(s," b8");
  613.       a = tmpcolor = black;
  614.       c = s[1] - 'a';
  615.       r = s[2] - '1';
  616.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  617.     {
  618.       sq = locn (r, c);
  619.       color[sq] = a;
  620.       board[sq] = no_piece;
  621.       for (i = no_piece; i <= king; i++)
  622.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  623.           {
  624.         board[sq] = i;
  625.         found=1;
  626.         break;
  627.           }
  628.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  629.     }
  630.  
  631.    if (MenuStripSet)
  632.     {
  633.      OnMenu(wG,ADVANCEDMENUNUM); 
  634.      OnMenu(wG,INTERMEDIATEMENUNUM); 
  635.      OffMenu(wG,EASYMENUNUM);
  636.      OffMenu(wG,BOOKMENUNUM);
  637.     }
  638.     GameCnt = 0;
  639.     Game50 = 1;
  640.     ISZERO = 1;
  641.     ZeroRPT ();
  642.     Sdepth = 0;
  643.     InitializeStats ();
  644.     DrawAmigaBoard();
  645.   }
  646.  else if (PlayMode == 2)
  647.   {
  648.     if (MenuStripSet)
  649.      {
  650.       OnMenu(wG,BOOKMENUNUM);
  651.       OffMenu(wG,ADVANCEDMENUNUM); 
  652.       OnMenu(wG,INTERMEDIATEMENUNUM); 
  653.       OnMenu(wG,EASYMENUNUM); 
  654.      }
  655.   }
  656. #ifdef KILLT
  657.  ClearMem(killt,sizeof(killt));
  658.  Initialize_dist ();
  659. #endif
  660. #ifdef HISTORY
  661. #ifdef AMIGA
  662.  ClearMem(history,sizeof(history));
  663. #else
  664.  memset(history,0,sizeof(history));
  665. #endif
  666. #endif
  667. #ifdef NODITHER
  668.   PCRASH = PCRASHS;
  669.   PCENTER = PCENTERS;
  670. #else
  671.   PCRASH = PCRASHS + dither?(rand() % PCRASHV):0;
  672.   PCENTER = PCENTERS + dither?(rand() % PCENTERV):0;
  673. #endif
  674. }
  675.  
  676. void
  677. InitConst (char *lang)
  678. {
  679.   FILE *constfile;
  680.   char s[256];
  681.   char sl[5];
  682.   int len, entry;
  683.   char *p, *q;
  684.  
  685.   constfile = fopen (LANGFILE, "r");
  686.   if (!constfile)
  687.     {
  688.      /* printf ("NO LANGFILE\n");*/
  689.       exit (1);
  690.     }
  691.   while (fgets (s, sizeof (s), constfile))
  692.     {
  693.       if (s[0] == '!')
  694.     continue;
  695.       len = strlen (s);
  696.       for (q = &s[len]; q > &s[8]; q--)
  697.     if (*q == '}')
  698.       break;
  699.       if (q == &s[8])
  700.     {
  701. /*      printf ("{ error in cinstfile\n");*/
  702.       exit (1);
  703.     }
  704.       *q = '\0';
  705.       if (s[3] != ':' || s[7] != ':' || s[8] != '{')
  706.     {
  707.     /*  printf ("Langfile format error %s\n", s);*/
  708.       exit (1);
  709.     }
  710.       s[3] = s[7] = '\0';
  711.       if (lang == NULL)
  712.     {
  713.       lang = sl;
  714.       strcpy (sl, &s[4]);
  715.     }
  716.       if (strcmp (&s[4], lang))
  717.     continue;
  718.       entry = atoi (s);
  719.       if (entry < 0 || entry >= CPSIZE)
  720.     {
  721.      /* printf ("Langfile number error\n");*/
  722.       exit (1);
  723.     }
  724.       for (q = p = &s[9]; *p; p++)
  725.     {
  726.       if (*p != '\\')
  727.         {
  728.           *q++ = *p;
  729.         }
  730.       else if (*(p + 1) == 'n')
  731.         {
  732.           *q++ = '\n';
  733.           p++;
  734.         }
  735.     }
  736.       *q = '\0';
  737.       if (entry < 0 || entry > 255)
  738.     {
  739.      /* printf ("Langfile error %d\n", entry);*/
  740.       exit (0);
  741.     }
  742.       CP[entry] = (char *) malloc ((unsigned) strlen (&s[9]) + 1);
  743.       if (CP[entry] == NULL)
  744.     {
  745.       ShowMessage("malloc");
  746.       exit (0);
  747.     }
  748.       strcpy (CP[entry], &s[9]);
  749.  
  750.     }
  751.   fclose (constfile);
  752. }
  753.  
  754. #ifndef CACHE
  755. #ifdef ttblsz
  756. void
  757. Initialize_ttable ()
  758. {
  759.   if (rehash < 0)
  760.     rehash = MAXrehash - 1;
  761. }
  762.  
  763. #endif /* ttblsz */
  764.  
  765. #else
  766.  
  767. #ifdef ttblsz
  768. void
  769.  
  770. Initialize_ttable ()
  771. {
  772.   char astr[32];
  773.   int doit = true;
  774.   if (rehash < 0)
  775.     rehash = MAXrehash;
  776. while(doit && ttblsize >= (1<<13)){
  777.   ttable[0] = (struct hashentry *)malloc((unsigned)(sizeof(struct hashentry))*(ttblsize+rehash));
  778.   ttable[1] = (struct hashentry *)malloc((unsigned)(sizeof(struct hashentry))*(ttblsize+rehash));
  779.   if(ttable[0] == NULL || ttable[1] == NULL){
  780.   if(ttable[0] != NULL)free(ttable[0]);
  781.   ttblsize = ttblsize>>1;
  782.   } else doit = false;
  783. }
  784.   if(ttable[0] == NULL || ttable[1] == NULL)
  785.    {
  786.     ShowMessage("Critical Mem Failure");
  787.     Delay(100L);
  788.     AmigaShutDown();
  789.     exit(1);
  790.    }
  791.   sprintf(astr,"transposition tbl is %d\n",ttblsize);
  792.   ShowMessage(astr);
  793. }
  794.  
  795. #endif /* ttblsz */
  796. #endif
  797.