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