home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / OS2 / SPEL / UCHESS / UCHESSRC / DSPCOM.C < prev    next >
Text File  |  1994-11-01  |  50KB  |  2,030 lines

  1. #define CLEARHISTBETWEENMOVES // old way to handle hist table
  2. /*
  3.  * dspcom.c - C source for GNU CHESS
  4.  *
  5.  * Copyright (c) 1988,1989,1990 John Stanback
  6.  * Copyright (c) 1992 Free Software Foundation
  7.  *
  8.  * This file is part of GNU CHESS.
  9.  *
  10.  * GNU Chess is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * GNU Chess is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with GNU Chess; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24. #define INCL_WIN
  25. #include "gnuchess.h"
  26.  
  27. extern char globaltitle[32];
  28. extern int myGameCnt;
  29. void calc_pgm_rating(void);
  30. void DoEasy(void);
  31. void DoIntermediate(void);
  32. void DoAdvanced(void);
  33. void PutPieceBack(void);
  34. void AnimCastle(char *);
  35. void AnimEnPassant(char *);
  36.  
  37. extern int global_promote_char;
  38. extern int GlobalFilType;
  39. extern int MainThreadStarted;
  40. extern int CheckIllegal;
  41. #ifdef AMIGA
  42. #define PTRHEIGHT 55
  43. extern UWORD chip myPointer[];
  44. #define MYREPLY (1<<InputReply->mp_SigBit)
  45. extern struct MsgPort *InputReply;
  46. extern struct MsgPort *InThreadPort;
  47. extern struct myMsgStruct Global_Message;
  48. #else
  49. extern HEV semhandle,replyhandle;
  50. extern ULONG Global_Message;
  51. #endif
  52.  
  53.  
  54.  
  55. extern int OrigComputer,OrigOpponent;
  56. #if defined NULLMOVE || defined DEEPNULL
  57. extern short int __aligned no_null;
  58. extern short int __aligned null;         /* Null-move already made or not */
  59. extern short int __aligned PVari;        /* Is this the PV */
  60. #endif
  61. extern short __aligned Threat[MAXDEPTH];
  62. extern unsigned short int __aligned PrVar[MAXDEPTH];
  63. extern short __aligned PawnStorm;
  64. extern short __aligned start_stage;
  65. extern short __aligned thrashing_tt; /* must we recycle slots at random. TomV */
  66. extern INTSIZE __aligned amigaboard[64],amigacolor[64];
  67. int __aligned GetEntryDone;
  68.  
  69.  
  70. extern int OpEntryRecvd;
  71. extern char __aligned OpEntryStr[64];
  72. extern INTSIZE Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
  73. extern char *version, *patchlevel;
  74. char __aligned mvstr[8][8];
  75. char __aligned mvstrhint[8][8];
  76. char __aligned *InPtr;
  77. //#define BOOKMENUNUM 0xc2
  78.  
  79. #ifdef CACHE
  80. //extern struct etable __far __aligned etab[2][ETABLE];
  81. extern int etblsize;
  82. extern struct etable *etab[2];
  83. #endif
  84.  
  85.  
  86. void algbr2 (SHORT f, SHORT t, SHORT flag);
  87. extern unsigned int TTadd;
  88.  
  89. int __aligned SecsPerMove=10;
  90. extern int IllegalMove;
  91. int __aligned func_num=0;
  92. int __aligned thinkahead=0;
  93. int __aligned ThinkInARow=0;
  94. int __aligned ThinkAheadWorked=0;
  95. int __aligned ThinkAheadDepth=0;
  96.  
  97. extern int backsrchaborted;
  98. extern short int ISZERO;
  99. extern short __aligned background;
  100. int __aligned verifyquiet=0;
  101. int __aligned MouseDropped=0;
  102.  
  103. #include <ctype.h>
  104. #include <signal.h>
  105.  
  106. #ifdef AMIGA
  107. #define __USE_SYSBASE
  108. #include <exec/types.h>
  109. #include <exec/exec.h>
  110. #include <proto/exec.h>
  111. #include <proto/dos.h>
  112. #include <proto/graphics.h>
  113. #include <proto/intuition.h>
  114. struct IntuiMessage __aligned globalmessage;
  115. int __aligned globalmessage_valid=0;
  116. extern struct Window __aligned *wG;
  117. extern int procpri;
  118. extern struct Process *myproc;
  119. extern struct MenuItem MenuItem6;
  120. extern struct Menu Menu1;
  121. extern unsigned char __far cookedchar[128];
  122. extern struct Menu __aligned Menu1;
  123. #define MenuList1 Menu1
  124. extern struct MenuItem __aligned MenuItem8ab;
  125. extern int __aligned MenuStripSet;
  126. #endif
  127.  
  128. #define SIGQUIT SIGINT
  129.  
  130. #ifdef MSDOSREAL
  131. #include <dos.h>
  132. #include <conio.h>
  133. #include <stdlib.h>
  134. #include <string.h>
  135. #include <time.h>
  136. #else
  137. #include <dos.h>
  138. #include <stdlib.h>
  139. #include <string.h>
  140. #include <time.h>
  141. /*
  142. #include <sys/param.h>
  143. #include <sys/types.h>
  144. #include <sys/file.h>
  145. #include <sys/ioctl.h>
  146. */
  147. #endif
  148.  
  149.  
  150. /*
  151.  * ataks.h - Header source for GNU CHESS
  152.  *
  153.  * Copyright (c) 1988,1989,1990 John Stanback
  154.  * Copyright (c) 1992 Free Software Foundation
  155.  *
  156.  * This file is part of GNU CHESS.
  157.  *
  158.  * GNU Chess is free software; you can redistribute it and/or modify
  159.  * it under the terms of the GNU General Public License as published by
  160.  * the Free Software Foundation; either version 2, or (at your option)
  161.  * any later version.
  162.  *
  163.  * GNU Chess is distributed in the hope that it will be useful,
  164.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  165.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  166.  * GNU General Public License for more details.
  167.  *
  168.  * You should have received a copy of the GNU General Public License
  169.  * along with GNU Chess; see the file COPYING.  If not, write to
  170.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  171.  */
  172. inline int
  173. SqAtakd2 (ARGSZ int sq, ARGSZ int side)
  174.  
  175. /*
  176.  * See if any piece with color 'side' ataks sq.  First check pawns then
  177.  * Queen, Bishop, Rook and King and last Knight.
  178.  */
  179.  
  180. {
  181.   register INTSIZE u;
  182.   register unsigned char *ppos, *pdir;
  183.   INTSIZE xside;
  184.  
  185.   xside = side ^ 1;
  186.   pdir = nextdir[ptype[xside][pawn]][sq];
  187.   u = pdir[sq];                 /* follow captures thread */
  188.   if (u != sq)
  189.     {
  190.       if (board[u] == pawn && color[u] == side)
  191.     return (true);
  192.       u = pdir[u];
  193.       if (u != sq && board[u] == pawn && color[u] == side)
  194.     return (true);
  195.     }
  196.   /* king capture */
  197.   if (distance (sq, PieceList[side][0]) == 1)
  198.     return (true);
  199.   /* try a queen bishop capture */
  200.   ppos = nextpos[bishop][sq];
  201.   pdir = nextdir[bishop][sq];
  202.   u = ppos[sq];
  203.   do
  204.     {
  205.       if (color[u] == neutral)
  206.     u = ppos[u];
  207.       else
  208.     {
  209.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  210.         return (true);
  211.       u = pdir[u];
  212.     }
  213.   } while (u != sq);
  214.   /* try a queen rook capture */
  215.   ppos = nextpos[rook][sq];
  216.   pdir = nextdir[rook][sq];
  217.   u = ppos[sq];
  218.   do
  219.     {
  220.       if (color[u] == neutral)
  221.     u = ppos[u];
  222.       else
  223.     {
  224.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  225.         return (true);
  226.       u = pdir[u];
  227.     }
  228.   } while (u != sq);
  229.   /* try a knight capture */
  230.   pdir = nextdir[knight][sq];
  231.   u = pdir[sq];
  232.   do
  233.     {
  234.       if (color[u] == side && board[u] == knight)
  235.     return (true);
  236.       u = pdir[u];
  237.   } while (u != sq);
  238.   return (false);
  239. }
  240.  
  241.  
  242. #ifndef OLD_ALGBR
  243. void
  244. algbr (SHORT f, SHORT t, SHORT flag)
  245.  
  246.  
  247. /*
  248.  * Generate move strings in different formats.
  249.  */
  250.  
  251. {
  252.   int m3p;
  253.  
  254.   if (f != t)
  255.     {
  256.       /* algebraic notation */
  257.       mvstr[0][0] = cxx[column (f)];
  258.       mvstr[0][1] = rxx[row (f)];
  259.       mvstr[0][2] = cxx[column (t)];
  260.       mvstr[0][3] = rxx[row (t)];
  261.       mvstr[4][0] = mvstr[0][4] = mvstr[3][0] = '\0';
  262.       if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  263.     {
  264.       if (mvstr[0][0] == mvstr[0][2])       /* pawn did not eat */
  265.         {
  266.           mvstr[2][0] = mvstr[1][0] = mvstr[0][2];  /* to column */
  267.           mvstr[2][1] = mvstr[1][1] = mvstr[0][3];  /* to row */
  268.           m3p = 2;
  269.         }
  270.       else
  271.         /* pawn ate */
  272.         {
  273.           mvstr[2][0] = mvstr[1][0] = mvstr[0][0];  /* column */
  274.           mvstr[2][1] = mvstr[1][1] = mvstr[0][2];  /* to column */
  275.           mvstr[2][2] = mvstr[0][3];
  276.           m3p = 3;          /* to row */
  277.         }
  278.       if (flag & promote)
  279.         {
  280.           mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  281.           mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
  282. #ifdef CHESSTOOL 
  283.           mvstr[3][0] = mvstr[0][0];        /* Allow e7e8 for chesstool */
  284.           mvstr[3][1] = mvstr[0][1];
  285.           mvstr[3][2] = mvstr[0][2];
  286.           mvstr[3][3] = mvstr[0][3];
  287.           mvstr[3][4] = '\0';
  288. #endif
  289.         } else mvstr[2][m3p] = mvstr[1][2] = '\0';
  290.     }
  291.       else
  292.     /* not a pawn */
  293.     {
  294.       mvstr[2][0] = mvstr[1][0];
  295.       mvstr[2][1] = mvstr[0][1];
  296.       mvstr[2][2] = mvstr[1][1] = mvstr[0][2];      /* to column */
  297.       mvstr[2][3] = mvstr[1][2] = mvstr[0][3];      /* to row */
  298.       mvstr[2][4] = mvstr[1][3] = '\0';
  299.       strcpy (mvstr[3], mvstr[2]);
  300.       mvstr[3][1] = mvstr[0][0];
  301.       mvstr[4][0] = mvstr[1][0]; strcpy(&mvstr[4][1],mvstr[0]);
  302.       if (flag & cstlmask)
  303.         {
  304.           if (t > f)
  305.         {
  306.           //strcpy (mvstr[1], mvstr[0]);
  307.           strcpy (mvstr[1], CP[5]);
  308.           strcpy (mvstr[2], CP[7]);
  309.         }
  310.           else
  311.         {
  312.           //strcpy (mvstr[1], mvstr[0]);
  313.           strcpy (mvstr[1], CP[6]);
  314.           strcpy (mvstr[2], CP[8]);
  315.         }
  316.         }
  317.     }
  318.     }
  319.   else
  320.     mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = mvstr[4][0] = '\0';
  321. }
  322.  
  323. void
  324. algbr2 (SHORT f, SHORT t, SHORT flag)
  325.  
  326.  
  327. /*
  328.  * Generate move strings in different formats.
  329.  */
  330.  
  331. {
  332.   int m3p;
  333.  
  334.   if (f != t)
  335.     {
  336.       /* algebraic notation */
  337.       mvstrhint[0][0] = cxx[column (f)];
  338.       mvstrhint[0][1] = rxx[row (f)];
  339.       mvstrhint[0][2] = cxx[column (t)];
  340.       mvstrhint[0][3] = rxx[row (t)];
  341.       mvstrhint[4][0] = mvstrhint[0][4] = mvstrhint[3][0] = '\0';
  342.       if (((mvstrhint[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  343.     {
  344.       if (mvstrhint[0][0] == mvstrhint[0][2])       /* pawn did not eat */
  345.         {
  346.           mvstrhint[2][0] = mvstrhint[1][0] = mvstrhint[0][2];      /* to column */
  347.           mvstrhint[2][1] = mvstrhint[1][1] = mvstrhint[0][3];      /* to row */
  348.           m3p = 2;
  349.         }
  350.       else
  351.         /* pawn ate */
  352.         {
  353.           mvstrhint[2][0] = mvstrhint[1][0] = mvstrhint[0][0];      /* column */
  354.           mvstrhint[2][1] = mvstrhint[1][1] = mvstrhint[0][2];      /* to column */
  355.           mvstrhint[2][2] = mvstrhint[0][3];
  356.           m3p = 3;          /* to row */
  357.         }
  358.       if (flag & promote)
  359.         {
  360.           mvstrhint[0][4] = mvstrhint[1][2] = mvstrhint[2][m3p] = qxx[flag & pmask];
  361.           mvstrhint[0][5] = mvstrhint[1][3] = mvstrhint[2][m3p + 1] = mvstrhint[3][0] = '\0';
  362.         } else mvstrhint[2][m3p] = mvstrhint[1][2] = '\0';
  363.     }
  364.       else
  365.     /* not a pawn */
  366.     {
  367.       mvstrhint[2][0] = mvstrhint[1][0];
  368.       mvstrhint[2][1] = mvstrhint[0][1];
  369.       mvstrhint[2][2] = mvstrhint[1][1] = mvstrhint[0][2];  /* to column */
  370.       mvstrhint[2][3] = mvstrhint[1][2] = mvstrhint[0][3];  /* to row */
  371.       mvstrhint[2][4] = mvstrhint[1][3] = '\0';
  372.       strcpy (mvstrhint[3], mvstrhint[2]);
  373.       mvstrhint[3][1] = mvstrhint[0][0];
  374.       mvstrhint[4][0] = mvstrhint[1][0]; strcpy(&mvstrhint[4][1],mvstrhint[0]);
  375.       if (flag & cstlmask)
  376.         {
  377.           if (t > f)
  378.         {
  379.           strcpy (mvstrhint[1], CP[5]);
  380.           strcpy (mvstrhint[2], CP[7]);
  381.         }
  382.           else
  383.         {
  384.           strcpy (mvstrhint[1], CP[6]);
  385.           strcpy (mvstrhint[2], CP[8]);
  386.         }
  387.         }
  388.     }
  389.     }
  390.   else
  391.     mvstrhint[0][0] = mvstrhint[1][0] = mvstrhint[2][0] = mvstrhint[3][0] = mvstrhint[4][0] = '\0';
  392. }
  393.  
  394.  
  395. #endif // not OLD_ALGBR
  396.  
  397. #ifndef OLD_VERIFY
  398.  
  399. int
  400. VerifyMove (char *s, int iop, unsigned short *mv)
  401.  
  402. /*
  403.  * Compare the string 's' to the list of legal moves available for the
  404.  * opponent. If a match is found, make the move on the board.
  405.  */
  406.  
  407. {
  408.   static SHORT pnt, tempb, tempc, tempsf, tempst, cnt;
  409.   static struct leaf xnode;
  410.   struct leaf *node;
  411.   char piece;
  412.   int r,c,l;
  413.   char mystr[80];
  414.  
  415.   *mv = 0;
  416.  
  417.   if ((s[1] >= 'a') && (s[1] <= 'h'))
  418.    {
  419.     if ((s[0] == 'n') || (s[0] == 'p') || (s[0] == 'b') ||
  420.     (s[0] == 'k') || (s[0] == 'r') || (s[0] == 'q'))
  421.      {
  422.       s[0] = toupper(s[0]);
  423.      }
  424.    }
  425.   if (iop == 2)
  426.     {
  427.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  428.       return (false);
  429.     }
  430.   cnt = 0;
  431.   MoveList (opponent, 2);
  432.   pnt = TrPnt[2];
  433.   while (pnt < TrPnt[3])
  434.     {
  435.       node = &Tree[pnt++];
  436.       algbr (node->f, node->t, (SHORT) node->flags);
  437.       if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  438.       strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0
  439.         || strcmp (s, mvstr[4]) == 0)
  440.     {
  441.       cnt++;
  442.       xnode = *node;
  443.     }
  444.     }
  445.   if (cnt == 1)
  446.     {
  447.       MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  448.       if (SqAtakd2 (PieceList[opponent][0], computer))
  449.     {
  450.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  451. #if defined CHESSTOOL
  452.       printz (CP[78]);
  453. #else
  454. #ifdef NONDSP
  455.       DisplayComputerMove(CP[77]);
  456. #else // not nondsp
  457. /* Illegal move in check */
  458.       if (!verifyquiet)
  459.        ShowMessage (CP[77]);
  460. #endif
  461. #endif /* CHESSTOOL */
  462.       return (false);
  463.     }
  464.       else
  465.     {
  466.       if (iop == 1)
  467.         return (true);
  468.       UpdateDisplay (xnode.f, xnode.t, 0, (SHORT) xnode.flags);
  469.       if ((board[xnode.t] == pawn)
  470.           || (xnode.flags & capture)
  471.           || (xnode.flags & cstlmask))
  472.         {
  473.           Game50 = GameCnt;
  474.           ZeroRPT ();
  475.         }
  476.       GameList[GameCnt].depth = GameList[GameCnt].score = 0;
  477.       GameList[GameCnt].nodes = 0;
  478.       ElapsedTime (1);
  479.       GameList[GameCnt].time = (SHORT) (et+50)/100;
  480.       if (TCflag)
  481.         {
  482.           TimeControl.clock[opponent] -= (et-TCadd);
  483.           timeopp[oppptr] = et;
  484.           --TimeControl.moves[opponent];
  485.         }
  486.       *mv = (xnode.f << 8) | xnode.t;
  487.       algbr (xnode.f, xnode.t, false);
  488. #ifdef OS2_PM
  489.       strcpy(mystr,mvstr[0]);
  490.       r = mystr[3] - '1';
  491.       c = mystr[2] - 'a';
  492.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  493.       if (color[l] == neutral)
  494.        {
  495.     piece = ' ';
  496.        }
  497.       else if (color[l] == white)
  498.     piece = qxx[board[l]]; /* white are lower case pieces */
  499.       else
  500.     piece = pxx[board[l]]; /* black are upper case pieces */
  501.       if (piece != ' ')
  502.        AnimateAmigaMove(mystr,piece);
  503. #endif
  504.       return (true);
  505.     }
  506.     }
  507. #if defined CHESSTOOL
  508.   printz (CP[78]);
  509. #else
  510. #ifdef NONDSP
  511. /* Illegal move */
  512.   if (!verifyquiet)
  513.    {
  514.     //sprintf(mystr,CP[75],s);
  515.     strcpy(mystr,"Illegal move (no match):");
  516.     strcat(mystr,s);
  517.     DisplayComputerMove(mystr);
  518.    }
  519. #else
  520. /* Illegal move */
  521.   if (!verifyquiet)
  522.    ShowMessage (CP[76]);
  523. #endif
  524. #endif /* CHESSTOOL */
  525. #if !defined CHESSTOOL && !defined XBOARD
  526.   if (cnt > 1)
  527.     ShowMessage (CP[32]);
  528. #endif /* CHESSTOOL */
  529.   return (false);
  530. }
  531. #endif // not old verify
  532.  
  533.  
  534.  
  535.  
  536. #ifdef OLD_ALGBR
  537. void
  538. algbr (INTSIZE int f, INTSIZE int t, INTSIZE int flag)
  539.  
  540.  
  541. /*
  542.  * Generate move strings in different formats.
  543.  */
  544.  
  545. {
  546.   int m3p;
  547.  
  548.   if (f != t)
  549.     {
  550.       /* algebraic notation */
  551.       mvstr[0][0] = cxx[column (f)];
  552.       mvstr[0][1] = rxx[row (f)];
  553.       mvstr[0][2] = cxx[column (t)];
  554.       mvstr[0][3] = rxx[row (t)];
  555.       mvstr[0][4] = mvstr[3][0] = '\0';
  556.       if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  557.     {
  558.       if (mvstr[0][0] == mvstr[0][2])       /* pawn did not eat */
  559.         {
  560.           mvstr[2][0] = mvstr[1][0] = mvstr[0][2];  /* to column */
  561.           mvstr[2][1] = mvstr[1][1] = mvstr[0][3];  /* to row */
  562.           m3p = 2;
  563.         }
  564.       else
  565.         /* pawn ate */
  566.         {
  567.           mvstr[2][0] = mvstr[1][0] = mvstr[0][0];  /* column */
  568.           mvstr[2][1] = mvstr[1][1] = mvstr[0][2];  /* to column */
  569.           mvstr[2][2] = mvstr[0][3];
  570.           m3p = 3;          /* to row */
  571.         }
  572.       if (flag & promote)
  573.         {
  574.           mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  575.           mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
  576. #ifdef CHESSTOOL
  577.           mvstr[3][0] = mvstr[0][0];        /* Allow e7e8 for chesstool */
  578.           mvstr[3][1] = mvstr[0][1];
  579.           mvstr[3][2] = mvstr[0][2];
  580.           mvstr[3][3] = mvstr[0][3];
  581.           mvstr[3][4] = '\0';
  582. #endif
  583.         }
  584.       mvstr[2][m3p] = mvstr[1][2] = '\0';
  585.     }
  586.       else
  587.     /* not a pawn */
  588.     {
  589.       mvstr[2][0] = mvstr[1][0];
  590.       mvstr[2][1] = mvstr[0][1];
  591.       mvstr[2][2] = mvstr[1][1] = mvstr[0][2];      /* to column */
  592.       mvstr[2][3] = mvstr[1][2] = mvstr[0][3];      /* to row */
  593.       mvstr[2][4] = mvstr[1][3] = '\0';
  594.       strcpy (mvstr[3], mvstr[2]);
  595.       mvstr[3][1] = mvstr[0][0];
  596.       if (flag & cstlmask)
  597.         {
  598.           if (t > f)
  599.         {
  600.           strcpy (mvstr[1], CP[5]);
  601.           strcpy (mvstr[2], CP[7]);
  602.         }
  603.           else
  604.         {
  605.           strcpy (mvstr[1], CP[6]);
  606.           strcpy (mvstr[2], CP[8]);
  607.         }
  608.         }
  609.     }
  610.     }
  611.   else
  612.     mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
  613. }
  614. #endif // old_algbr
  615.  
  616. #ifdef OLD_VERIFY
  617. int
  618. VerifyMove (char *s, INTSIZE int iop, INTSIZE unsigned int *mv)
  619.  
  620. /*
  621.  * Compare the string 's' to the list of legal moves available for the
  622.  * opponent. If a match is found, make the move on the board.
  623.  */
  624.  
  625. {
  626.   static INTSIZE pnt, tempb, tempc, tempsf, tempst, cnt;
  627.   int r,c,l;
  628.   char mystr[80];
  629.   char piece;
  630.   static struct leaf xnode;
  631.   struct leaf *node;
  632.  
  633.   if ((s[1] >= 'a') && (s[1] <= 'h'))
  634.    {
  635.     if ((s[0] == 'n') || (s[0] == 'p') || (s[0] == 'b') ||
  636.     (s[0] == 'k') || (s[0] == 'r') || (s[0] == 'q'))
  637.      {
  638.       s[0] = toupper(s[0]);
  639.      }
  640.    }
  641.   *mv = 0;
  642.   if (iop == 2)
  643.     {
  644.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  645.       return (false);
  646.     }
  647.   cnt = 0;
  648.   MoveList (opponent, 2);
  649.   pnt = TrPnt[2];
  650.   while (pnt < TrPnt[3])
  651.     {
  652.       node = &Tree[pnt++];
  653.       algbr (node->f, node->t, (INTSIZE) node->flags);
  654.       if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  655.       strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
  656.     {
  657.       cnt++;
  658.       xnode = *node;
  659.     }
  660.     }
  661.   if (cnt == 1)
  662.     {
  663.       MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  664.       if (SqAtakd2 (PieceList[opponent][0], computer))
  665.     {
  666.       UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  667. #if defined CHESSTOOL
  668.       printz (CP[15]);
  669. #else
  670. #ifdef NONDSP
  671. /* Illegal move in check */
  672.      if (!verifyquiet) 
  673.       DisplayComputerMove(CP[77]);
  674. #else
  675. /* Illegal move in check */
  676.       if (!verifyquiet)
  677.        ShowMessage (CP[77]);
  678. #endif // nondsp
  679. #endif /* CHESSTOOL */
  680.       return (false);
  681.     }
  682.       else
  683.     {
  684.       if (iop == 1)
  685.         return (true);
  686.       UpdateDisplay (xnode.f, xnode.t, 0, (INTSIZE) xnode.flags);
  687.       if ((board[xnode.t] == pawn)
  688.           || (xnode.flags & capture)
  689.           || (xnode.flags & cstlmask))
  690.         {
  691.           Game50 = GameCnt;
  692.           ZeroRPT ();
  693.         }
  694.       GameList[GameCnt].depth = GameList[GameCnt].score = 0;
  695.       GameList[GameCnt].nodes = 0;
  696.       ElapsedTime (1);
  697.       GameList[GameCnt].time = (INTSIZE) et;
  698.       if (TCflag)
  699.         {
  700.           TimeControl.clock[opponent] -= et;
  701.           timeopp[oppptr] = et;
  702.           --TimeControl.moves[opponent];
  703.         }
  704.       *mv = (xnode.f << 8) | xnode.t;
  705.       algbr (xnode.f, xnode.t, false);
  706. #ifdef OS2_PM
  707.       strcpy(mystr,mvstr[0]);
  708.       r = mystr[3] - '1';
  709.       c = mystr[2] - 'a';
  710.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  711.       if (color[l] == neutral)
  712.        {
  713.     //DisplayBeep(0L);
  714.     //Delay(25L);
  715.     //DisplayBeep(0L);
  716.     //Delay(25L);
  717.     //DisplayBeep(0L);
  718.     //Delay(25L);
  719.     piece = ' ';
  720.        }
  721.       else if (color[l] == white)
  722.     piece = qxx[board[l]]; /* white are lower case pieces */
  723.       else
  724.     piece = pxx[board[l]]; /* black are upper case pieces */
  725.       if (piece != ' ')
  726.        AnimateAmigaMove(mystr,piece);
  727. #endif
  728.       return (true);
  729.     }
  730.     }
  731. #if defined CHESSTOOL
  732.   printz (CP[78]);
  733. #else
  734. #ifdef NONDSP
  735. /* Illegal move */
  736.   //sprintf(mystr,CP[75],s);
  737.   strcpy(mystr,"Illegal move (no match):");
  738.   strcat(mystr,s);
  739.   if (!verifyquiet)
  740.    DisplayComputerMove(mystr);
  741. #else
  742. /* Illegal move */
  743.  if (!verifyquiet)
  744.   ShowMessage (CP[76]);
  745. #endif // NONDSP
  746. #endif /* CHESSTOOL */
  747. #if !defined CHESSTOOL && !defined XBOARD
  748.   if (cnt > 1)
  749.     ShowMessage (CP[32]);
  750. #endif /* CHESSTOOL */
  751.   return (false);
  752. }
  753.  
  754. #endif // OLD_VERIFY
  755.  
  756.  
  757.  
  758. int
  759. parser (char *f, int side)
  760. {
  761.   int c1, r1, c2, r2;
  762.  
  763.   if (f[4] == 'o')
  764.     if (side == black)
  765.       return 0x3C3A;
  766.     else
  767.       return 0x0402;
  768.   else if (f[0] == 'o')
  769.     if (side == black)
  770.       return 0x3C3E;
  771.     else
  772.       return 0x0406;
  773.   else
  774.     {
  775.       c1 = f[0] - 'a';
  776.       r1 = f[1] - '1';
  777.       c2 = f[2] - 'a';
  778.       r2 = f[3] - '1';
  779.       return (locn (r1, c1) << 8) | locn (r2, c2);
  780.     }
  781.   /*NOTREACHED*/
  782. }
  783.  
  784. void
  785. GetGame (void)
  786. {
  787.   int filefmt;
  788.   int side = black; // was side = computer in 2.51
  789.   char checkstr[8];
  790.   FILE *fd;
  791.   int eps;
  792.   char fname[256], *p;
  793.   int c, i, j;
  794.   INTSIZE sq;
  795.  
  796. /* enter file name */
  797.  strcpy(globaltitle,"Load Game");
  798.  GlobalFilType = FDS_OPEN_DIALOG;
  799.  if (!GetFileName(fname))
  800.   {
  801.    return;
  802.   }
  803.  if (fname[0] == 0)
  804.   ShowMessage (CP[63]);
  805. /* chess.000 */
  806.   if (fname[0] == '\0')
  807.     strcpy (fname, CP[137]);
  808.   if ((fd = fopen (fname, "r")) != NULL)
  809.     {
  810.       fgets (fname, 256, fd);
  811.       for(i=0;i<5;i++)
  812.        checkstr[i] = fname[i];
  813.       checkstr[5] = 0;
  814.       if (stricmp(checkstr,"Black"))
  815.        {
  816.         DosBeep(1280,175);
  817.         ShowMessage("Load err");
  818.     fclose(fd);
  819.     return;
  820.        }
  821.       ShowMessage("please wait");
  822.       ShowMessage("load game");
  823.       NewGame();
  824.       OrigComputer = OrigOpponent = computer = opponent = white;
  825.       InPtr = fname;
  826.       if (strlen(fname) < 34)
  827.        {
  828.     filefmt = 0;
  829.     DisplayError("   Old Save File format");
  830.        }
  831.       else
  832.        filefmt = 1;
  833.       skip ();
  834.       if (*InPtr == 'c')
  835.     OrigComputer = computer = black;
  836.       else
  837.     OrigOpponent = opponent = black;
  838.       skip ();
  839.       skip ();
  840.       skip ();
  841.       Game50 = atoi (InPtr);
  842.       if (filefmt)
  843.        {
  844.     skip();
  845.     skip();
  846.     eps = atoi(InPtr);
  847.        }
  848.       else
  849.        eps = -1;
  850.       fgets (fname, 256, fd);
  851.       InPtr = &fname[14];
  852.       castld[white] = ((*InPtr == CP[214][0]) ? true : false);
  853.       skip ();
  854.       skip ();
  855.       castld[black] = ((*InPtr == CP[214][0]) ? true : false);
  856.       fgets (fname, 256, fd);
  857.       InPtr = &fname[11];
  858.       skipb ();
  859.       TCflag = atoi (InPtr);
  860.       skip ();
  861.       InPtr += 14;
  862.       skipb ();
  863.       OperatorTime = atoi (InPtr);
  864.       fgets (fname, 256, fd);
  865.       InPtr = &fname[11];
  866.       skipb ();
  867.       TimeControl.clock[white] = atoi (InPtr);
  868.       skip ();
  869.       skip ();
  870.       TimeControl.moves[white] = atoi (InPtr);
  871.       fgets (fname, 256, fd);
  872.       InPtr = &fname[11];
  873.       skipb ();
  874.       TimeControl.clock[black] = atoi (InPtr);
  875.       skip ();
  876.       skip ();
  877.       TimeControl.moves[black] = atoi (InPtr);
  878.       fgets (fname, 256, fd);
  879.       for (i = 7; i > -1; i--)
  880.     {
  881.       fgets (fname, 256, fd);
  882.       p = &fname[2];
  883.       InPtr = &fname[11];
  884.       skipb ();
  885.       for (j = 0; j < 8; j++)
  886.         {
  887.           sq = i * 8 + j;
  888.           if (*p == '.')
  889.         {
  890.           board[sq] = no_piece;
  891.           color[sq] = neutral;
  892.         }
  893.           else
  894.         {
  895.           for (c = 0; c < 8; c++)
  896.             {
  897.               if (*p == pxx[c])
  898.             {
  899.               board[sq] = c;
  900.               color[sq] = black;
  901.             }
  902.             }
  903.           for (c = 0; c < 8; c++)
  904.             {
  905.               if (*p == qxx[c])
  906.             {
  907.               board[sq] = c;
  908.               color[sq] = white;
  909.             }
  910.             }
  911.         }
  912.           p++;
  913.           Mvboard[sq] = atoi (InPtr);
  914.           skip ();
  915.         }
  916.     }
  917.       GameCnt = 0;
  918.       flag.regularstart = false/*true*/;
  919.       fgets (fname, 256, fd);
  920.       fgets (fname, 256, fd);
  921.       fgets (fname, 256, fd);
  922.       while (fgets (fname, 256, fd))
  923.     {
  924.       struct GameRec *g;
  925.  
  926. /*printf("in while loop\n");*/
  927.       side = side ^ 1;
  928.       ++GameCnt;
  929.       InPtr = fname;
  930.       skipb ();
  931.       g = &GameList[GameCnt];
  932.       g->gmove = parser (InPtr, side);
  933.       skip ();
  934.       g->score = atoi (InPtr);
  935.       skip ();
  936.       g->depth = atoi (InPtr);
  937.       skip ();
  938.       g->nodes = atoi (InPtr);
  939.       skip ();
  940.       g->time = atoi (InPtr);
  941.       skip ();
  942.       g->flags = c = atoi (InPtr);
  943.       skip ();
  944.       g->hashkey = strtol (InPtr, (char **) NULL, 16);
  945.       skip ();
  946.       g->hashbd = strtol (InPtr, (char **) NULL, 16);
  947.       if (filefmt)
  948.        {
  949.         skip();
  950.         g->epssq = atoi(InPtr);
  951.        }
  952.       else
  953.        g->epssq = -1;
  954.       g->piece = no_piece;
  955.       g->color = neutral;
  956.       if (c & (capture | cstlmask))
  957.         {
  958.           if (c & capture)
  959.         {
  960.           skip ();
  961.           for (c = 0; c < 8; c++)
  962.             if (pxx[c] == *InPtr)
  963.               break;
  964.           g->piece = c;
  965.         }
  966.           skip ();
  967.           g->color = ((*InPtr == CP[119][0]) ? black : white);
  968.         }
  969.     }
  970.       /* GameCnt--; */
  971.       //if (TimeControl.clock[white] > 0)
  972.       //TCflag = true;
  973.       fclose (fd);
  974. //      TrPnt[1] = 0;
  975. //      root = &Tree[0];
  976. //      MoveList (side, 1);
  977.     }
  978.   ISZERO = 1;
  979.   ZeroRPT ();
  980.   epsquare = eps;
  981.   InitializeStats ();
  982.   UpdateDisplay (0, 0, 1, 0);
  983.   Sdepth = 0;
  984.   hint = 0;
  985. //  DisableMoveNow();
  986. //  if (!TCflag)
  987. //   {
  988.     //EnableMoveNow();
  989. //   }
  990. //  else
  991. //   {
  992. //    i = player;
  993. //    player = black;
  994. //    UpdateClocks();
  995. //    player = white;
  996.  //   UpdateClocks();
  997.  //   player = i;
  998.   //  if ((((TimeControl.clock[black])/TimeControl.moves[black]) > 5900) ||
  999.   //      (((TimeControl.clock[white])/TimeControl.moves[white]) > 5900))
  1000.  //    {
  1001.  //     EnableMoveNow();
  1002.  //    }
  1003.  //  }
  1004.   flag.regularstart = false;
  1005.   Book = 0;
  1006. //  if (MenuStripSet)
  1007. //   {
  1008. //    MenuItem8ab.Flags &= (0xffff ^ CHECKED);
  1009. //    SetMenuStrip(wG,&MenuList1);        /* attach any Menu */
  1010. //   }
  1011.   ZeroTTable(0);
  1012.   MoveMem128(board,amigaboard);
  1013.   MoveMem128(color,amigacolor);
  1014.   ClearMem(etab[0],sizeof(struct etable)*etblsize);
  1015.   ClearMem(etab[1],sizeof(struct etable)*etblsize);
  1016.   ShowMessage("Game Loaded");
  1017.   DrawAmigaBoard();
  1018. }
  1019.  
  1020. void
  1021. GetXGame (void)
  1022. {
  1023. }
  1024.  
  1025. void
  1026. SaveGame (void)
  1027. {
  1028.   FILE *fd;
  1029.   char fname[256];
  1030.   INTSIZE sq, i, c, f, t;
  1031.   char p;
  1032.  
  1033.   GlobalFilType = FDS_SAVEAS_DIALOG;
  1034.   strcpy(globaltitle,"Save Game");
  1035.   if (!(GetFileName(savefile)))   
  1036.    { 
  1037.     return;
  1038.    }
  1039.   if (savefile[0])
  1040.     strcpy (fname, savefile);
  1041.   else
  1042.     {
  1043. /* Enter file name*/
  1044.       ShowMessage (CP[63]);
  1045.     }
  1046.  
  1047.   if (fname[0] == '\0')
  1048. /* chess.000 */
  1049.     strcpy (fname, CP[137]);
  1050.   if ((fd = fopen (fname, "w")) != NULL)
  1051.     {
  1052.       char *b, *w;
  1053.  
  1054.       b = w = CP[74];
  1055.       if (computer == black)
  1056.     b = CP[141];
  1057.       if (computer == white)
  1058.     w = CP[141];
  1059.       fprintf (fd, CP[37], b, w, Game50,epsquare);
  1060.       fprintf (fd, CP[42], castld[white] ? CP[214] : CP[215], castld[black] ? CP[214] : CP[215]);
  1061.       fprintf (fd, CP[111], TCflag, OperatorTime);
  1062.       fprintf (fd, CP[117],
  1063.            TimeControl.clock[white], TimeControl.moves[white],
  1064.            TimeControl.clock[black], TimeControl.moves[black]);
  1065.       for (i = 7; i > -1; i--)
  1066.     {
  1067.       fprintf (fd, "%1d ", i + 1);
  1068.       for (c = 0; c < 8; c++)
  1069.         {
  1070.           sq = i * 8 + c;
  1071.           switch (color[sq])
  1072.         {
  1073.         case black:
  1074.           p = pxx[board[sq]];
  1075.           break;
  1076.         case white:
  1077.           p = qxx[board[sq]];
  1078.           break;
  1079.         default:
  1080.           p = '.';
  1081.         }
  1082.           fprintf (fd, "%c", p);
  1083.         }
  1084.       for (f = i * 8; f < i * 8 + 8; f++)
  1085.         fprintf (fd, " %d", Mvboard[f]);
  1086.       fprintf (fd, "\n");
  1087.     }
  1088.       fprintf (fd, "  %s\n", cxx);
  1089.       fprintf (fd, CP[126]);
  1090.       for (i = 1; i <= GameCnt; i++)
  1091.     {
  1092.       struct GameRec *g = &GameList[i];
  1093.  
  1094.       f = g->gmove >> 8;
  1095.       t = (g->gmove & 0xFF);
  1096.       algbr (f, t, g->flags);
  1097.       fprintf (fd, "%s %5d %5d %7ld %5d %5d  %#08lx %#08lx %d %c   %s\n",
  1098.            mvstr[0], g->score, g->depth,
  1099.            g->nodes, g->time, g->flags, g->hashkey, g->hashbd,g->epssq,
  1100.        pxx[g->piece], ((g->color == 2) ? "     " : ColorStr[g->color]));
  1101.     }
  1102.       fclose (fd);
  1103. /* Game saved */
  1104.       ShowMessage (CP[70]);
  1105.     }
  1106.   else
  1107.     /*ShowMessage ("Could not open file");*/
  1108.     ShowMessage (CP[48]);
  1109. }
  1110.  
  1111. void
  1112. ListGame (getstr)
  1113. int getstr;
  1114. {
  1115.   FILE *fd;
  1116.   INTSIZE i, f, t;
  1117.   char fname[256];
  1118. #ifdef AUTOLIST
  1119.   unsigned long when;
  1120.   char dbuf[256];
  1121. #endif // AUTOLIST
  1122.  
  1123.   if (listfile[0])
  1124.     strcpy (fname, listfile);
  1125.   else
  1126.     {
  1127. #ifdef MSDOSREAL
  1128.       sprintf (fname, "chess.lst");
  1129. #else
  1130.       if (!getstr)
  1131.        {
  1132. #ifndef AUTOLIST
  1133.     return;
  1134. #else // AUTOLIST
  1135.     time (&when);
  1136.     strncpy (dbuf, ctime (&when), 20);
  1137.     dbuf[7] = '\0';
  1138.     dbuf[10] = '\0';
  1139.     dbuf[13] = '\0';
  1140.     dbuf[16] = '\0';
  1141.     dbuf[19] = '\0';
  1142. /* use format "CLp16.Jan01-020304B" when patchlevel is 16,
  1143.    date is Jan 1
  1144.    time is 02:03:04
  1145.    program played black */
  1146.     sprintf (fname, "UC%s.%s%s-%s%s%s%c", patchlevel, dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14, dbuf + 17, ColorStr[computer][0]);
  1147.     /* replace space padding with 0 */
  1148.     for (i = 0; fname[i] != '\0'; i++)
  1149.       if (fname[i] == ' ')
  1150.         fname[i] = '0';
  1151. #endif // AUTOLIST
  1152.        }
  1153.       else
  1154.        {
  1155.         strcpy(globaltitle,"List Game");
  1156.         GlobalFilType = FDS_SAVEAS_DIALOG;
  1157.     if (!GetFileName(fname))
  1158.      {
  1159.       return;
  1160.      }
  1161.        }
  1162. #endif /* MSDOS */
  1163.     }
  1164.   fd = fopen (fname, "w");
  1165.   if (!fd)
  1166.     {
  1167.      return;
  1168.     }
  1169.   /*fprintf (fd, "gnuchess game %d\n", u);*/
  1170.   fprintf (fd, "%s\n", VERSTRING);
  1171.   fprintf (fd, CP[10]);
  1172.   fprintf (fd, CP[11]);
  1173.   for (i = 1; i <= GameCnt; i++)
  1174.     {
  1175.       f = GameList[i].gmove >> 8;
  1176.       t = (GameList[i].gmove & 0xFF);
  1177.       algbr (f, t, GameList[i].flags);
  1178.       if(GameList[i].flags & book)
  1179.       fprintf (fd, "%5s  %5d    Book%7ld %5d", mvstr[0],
  1180.            GameList[i].score, 
  1181.            GameList[i].nodes, GameList[i].time);
  1182.       else
  1183.       fprintf (fd, "%5s  %5d     %2d %7ld %5d", mvstr[0],
  1184.            GameList[i].score, GameList[i].depth,
  1185.            GameList[i].nodes, GameList[i].time);
  1186.       if ((i % 2) == 0)
  1187.     {
  1188.       fprintf (fd, "\n");
  1189.     }
  1190.       else
  1191.     fprintf (fd, "         ");
  1192.     }
  1193.   fprintf (fd, "\n\n");
  1194.   if (GameList[GameCnt].flags & draw)
  1195.     {
  1196.       fprintf (fd, CP[54], DRAW);
  1197.     }
  1198.   else if (GameList[GameCnt].score == -9999)
  1199.     {
  1200.       fprintf (fd, "%s\n", ColorStr[player ]);
  1201.     }
  1202.   else if (GameList[GameCnt].score == 9998)
  1203.     {
  1204.       fprintf (fd, "%s\n", ColorStr[player ^ 1]);
  1205.     }
  1206.   fclose (fd);
  1207. }
  1208.  
  1209. void
  1210. Undo (void)
  1211.  
  1212. /*
  1213.  * Undo the most recent half-move.
  1214.  */
  1215.  
  1216. {
  1217.   INTSIZE f, t;
  1218.   f = GameList[GameCnt].gmove >> 8;
  1219.   t = GameList[GameCnt].gmove & 0xFF;
  1220.   if (board[t] == king && distance (t, f) > 1)
  1221.     (void) castle (GameList[GameCnt].color, f, t, 2);
  1222.   else
  1223.     {
  1224.       /* Check for promotion: */
  1225.       if (GameList[GameCnt].flags & promote)
  1226.     {
  1227.       board[t] = pawn;
  1228.     }
  1229.       board[f] = board[t];
  1230.       color[f] = color[t];
  1231.       board[t] = GameList[GameCnt].piece;
  1232.       color[t] = GameList[GameCnt].color;
  1233.       if (color[t] != neutral)
  1234.     Mvboard[t]--;
  1235.       Mvboard[f]--;
  1236.     }
  1237.   if (GameList[GameCnt].flags & epmask)
  1238.     EnPassant (otherside[color[f]], f, t, 2);
  1239.   else
  1240.     InitializeStats ();
  1241.   epsquare = GameList[GameCnt].epssq;
  1242.   if (TCflag && (TCmoves>1))
  1243.     ++TimeControl.moves[color[f]];
  1244.   hashkey = GameList[GameCnt].hashkey;
  1245.   hashbd = GameList[GameCnt].hashbd;
  1246.   GameCnt--;
  1247.   computer = computer ^ 1;
  1248.   opponent = opponent ^ 1;
  1249.   OrigOpponent = opponent;
  1250.   OrigComputer = computer;
  1251.   Mate = flag.mate = false;
  1252.   Sdepth = 0;
  1253.   player = player ^ 1;
  1254.   ShowSidetoMove ();
  1255.   UpdateDisplay (0, 0, 1, 0);
  1256.  
  1257.   InitializeStats();
  1258.  
  1259. #if defined NULLMOVE || defined DEEPNULL
  1260.   no_null=0;
  1261.   null = 0;         /* Null-move already made or not */
  1262.   PVari = 0;        /* Is this the PV */
  1263. #endif
  1264.   dither = 0;
  1265.   PawnStorm = start_stage = 0;
  1266.   thrashing_tt = 0; /* must we recycle slots at random. TomV */
  1267.   ClearMem(QueenCheck,MAXDEPTH*sizeof(short));
  1268.   ClearMem(PrVar,MAXDEPTH*sizeof(short));
  1269.   ClearMem(Threat,MAXDEPTH*sizeof(short));
  1270.   ClearMem(ThreatSave,MAXDEPTH*sizeof(short));
  1271.   ClearMem(Pscore,MAXDEPTH*sizeof(short));
  1272.   ClearMem(Tscore,MAXDEPTH*sizeof(short));
  1273.   ClearMem(ChkFlag,MAXDEPTH*sizeof(short));
  1274.   ClearMem(CptrFlag,MAXDEPTH*sizeof(short));
  1275.   ClearMem(PawnThreat,MAXDEPTH*sizeof(short));
  1276.  
  1277.  
  1278.   //ZeroRPT();
  1279.   ZeroTTable(0);
  1280. //  ClearMem(etab,sizeof(etab));
  1281.   ClearMem(etab[0],sizeof(struct etable)*etblsize);
  1282.   ClearMem(etab[1],sizeof(struct etable)*etblsize);
  1283. #ifdef HISTORY
  1284.  ClearMem(history,sizeof(history));
  1285. #endif
  1286.  MoveMem128(board,amigaboard);
  1287.  MoveMem128(color,amigacolor);
  1288. /*  if (flag.regularstart)
  1289.     Book = BOOKFAIL;*/
  1290. }
  1291.  
  1292. void
  1293.  TestSpeed (void (*f) ( INTSIZE int side, INTSIZE int ply), unsigned j)
  1294. {
  1295.   char astr[256];
  1296.   INTSIZE i;
  1297.   unsigned long cnt, rate, t1, t2;
  1298.  
  1299.   t1 = clock();
  1300.   for (i = 0; i < j; i++)
  1301.     {
  1302.       f (opponent, 2);
  1303.     }
  1304.   t2 = clock();
  1305.   cnt = j * (TrPnt[3] - TrPnt[2]);
  1306.   if (t2 - t1)
  1307.     et = (t2 - t1) * 100;
  1308.   else
  1309.     et = 1;
  1310.   if (et)
  1311.    rate = cnt*CLOCKS_PER_SEC/et;
  1312.  else                       
  1313.    rate = 0;
  1314. //  rate = (et) ? (cnt / et) : 0;
  1315.   /*printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);*/
  1316. #ifdef NONDSP
  1317. if (!func_num)
  1318.  sprintf(astr,"Mlst=%dN/s",rate*100);
  1319. else if (func_num == 1)
  1320.  sprintf(astr,"Clst=%dN/s",rate*100);
  1321. ShowMessage(astr);
  1322. #else
  1323.   ShowNodeCnt (cnt);
  1324. #endif
  1325. }
  1326.  
  1327. void
  1328.  TestPSpeed (INTSIZE int (*f) (INTSIZE int side), unsigned j)
  1329. {
  1330.   char astr[256];
  1331.   INTSIZE i;
  1332.   long cnt, rate, t1, t2;
  1333.  
  1334.   t1 = clock();
  1335.   for (i = 0; i < j; i++)
  1336.     {
  1337.       (void) f (opponent);
  1338.     }
  1339.   t2 = clock();
  1340.   cnt = j;
  1341.   if (t2 - t1)
  1342.     et = (t2 - t1) * 100;
  1343.   else
  1344.     et = 1;
  1345.   if (et)
  1346.    rate = cnt*CLOCKS_PER_SEC/et;
  1347.   else
  1348.    rate = 0;
  1349. //  rate = (et) ? (cnt / et) : 0;
  1350.   /*printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);*/
  1351. #ifdef NONDSP
  1352. sprintf(astr,"Eval=%ldN/s",rate*100);
  1353. ShowMessage(astr);
  1354. #else
  1355.   ShowNodeCnt (cnt);
  1356. #endif
  1357. }
  1358.  
  1359.  
  1360. void
  1361. SetMachineTime (char *s)
  1362. {
  1363.   char *time;
  1364.   int m, t;
  1365.   time = &s[strlen (CP[197])];
  1366.   m = strtol (time, &time, 10);
  1367.   t = strtol (time, &time, 10);
  1368.   if (t)
  1369.     TimeControl.clock[computer] = t;
  1370.   if (m)
  1371.     TimeControl.moves[computer] = m;
  1372. #ifdef XBOARD
  1373.   printz (CP[222], m, t);
  1374. #endif
  1375. }
  1376.  
  1377.  
  1378. void
  1379. InputCommand ()
  1380.  
  1381. //char *cstring;
  1382.  
  1383. /*
  1384.  * Process the users command. If easy mode is OFF (the computer is thinking
  1385.  * on opponents time) and the program is out of book, then make the 'hint'
  1386.  * move on the board and call SelectMove() to find a response. The user
  1387.  * terminates the search by entering ^C (quit siqnal) before entering a
  1388.  * command. If the opponent does not make the hint move, then set Sdepth to
  1389.  * zero.
  1390.  */
  1391.  
  1392. {
  1393.   int tmpPawnStorm;
  1394.   int need_to_zero;
  1395.   //char tstr[40];
  1396.   ULONG postcnt;
  1397.   int i = 0;
  1398.   INTSIZE have_shown_prompt = false;
  1399.   INTSIZE ok, tmp;
  1400.   unsigned INTSIZE mv;
  1401.   char s[80];
  1402.   char *sx;
  1403.   APIRET rc;
  1404.  
  1405.   sx = OpEntryStr;
  1406.   tmpPawnStorm = PawnStorm;
  1407. #if defined CHESSTOOL
  1408.   INTSIZE normal = false;
  1409.  
  1410. #endif
  1411.  
  1412.   ok = flag.quit = false;
  1413.   MoveMem128(board,amigaboard);
  1414.   MoveMem128(color,amigacolor);
  1415.   player = opponent;
  1416.   ft = 0;
  1417.   thinkahead = 0;
  1418. #ifdef CACHE
  1419. //  if(TTadd > ttblsize) // want to zero out ttable each time
  1420.    ZeroTTable(1);
  1421. #endif
  1422.   if (hint > 0 && !flag.easy && !flag.force)
  1423.     if ((board[hint >> 8] != pawn) || ((row (hint & 0x3f) != 0) && (row (hint & 0x3f) != 7)))
  1424.       {
  1425.     s[0] = sx[0] = '\0';
  1426.     thinkahead = 1;
  1427.     ft = time0;
  1428.     algbr ((INTSIZE) hint >> 8, (INTSIZE) hint & 0x3F, false);
  1429.     strcpy (s, mvstr[0]);
  1430.     tmp = epsquare;
  1431.     verifyquiet = 1;
  1432.     if (VerifyMove (s, 1, &mv))
  1433.       {
  1434.         Sdepth = 0;
  1435. #ifdef QUIETBACKGROUND
  1436. #ifdef NONDSP
  1437.         PromptForMove ();
  1438. #else
  1439.         ShowSidetoMove ();
  1440.         ShowPrompt ();
  1441. #endif
  1442.         have_shown_prompt = true;
  1443. #endif /* QUIETBACKGROUND */
  1444.         backsrchaborted = 0;
  1445. //          if (!GetEntryDone)
  1446. //           {
  1447. //            Global_Message = 1L;
  1448. //            DosPostEventSem(semhandle);
  1449. //            GetEntryDone = 1;
  1450. //           }
  1451.         SelectMove (computer, 2);
  1452. #ifdef OLD_LOOKAHEAD
  1453.         VerifyMove (s, 2, &mv);
  1454.         Sdepth = 0;
  1455. #else // faster lookahead on predict
  1456.         VerifyMove (s, 2, &mv);
  1457.         if ((Sdepth > 0)&&(backsrchaborted))
  1458.           Sdepth--;
  1459. #endif
  1460.       }
  1461.      verifyquiet = 0;
  1462.     /*ft = (time ((long *) 0) - time0) * 100;*/
  1463.     epsquare = tmp;
  1464.     time0 = ft;
  1465.       }
  1466.   while (!(ok || flag.quit))
  1467.     {
  1468.       need_to_zero = 0;
  1469. #if defined CHESSTOOL
  1470.       normal = false;
  1471. #endif
  1472.       player = opponent;
  1473. #ifdef QUIETBACKGROUND
  1474.       if (!have_shown_prompt)
  1475.     {
  1476. #endif /* QUIETBACKGROUND */
  1477. #ifdef NONDSP
  1478.       PromptForMove ();
  1479. #else
  1480.       ShowSidetoMove ();
  1481.       ShowPrompt ();
  1482. #endif
  1483. #ifdef QUIETBACKGROUND
  1484.     }
  1485.       have_shown_prompt = false;
  1486. #endif /* QUIETBACKGROUND */
  1487. #ifdef NONDSP
  1488. // sx is Opentry is OpentryStr, which is filled in by other thread
  1489.       if (!GetEntryDone)
  1490.        s[0] = sx[0] = '\0';
  1491.        thinking2 = 0;
  1492.        i = 1;
  1493.        thinkahead = 0;
  1494. //       if (!GetEntryDone)
  1495. //      {
  1496. //       Global_Message = 1L;
  1497. //       DosPostEventSem(semhandle);
  1498. //      }
  1499.        GetEntryDone = 0;
  1500. // here is where we wait for reply port from other thread
  1501.        MainThreadStarted = 1;
  1502.        rc = DosWaitEventSem(replyhandle,SEM_INDEFINITE_WAIT);
  1503.        if (rc)
  1504.     {
  1505.      ShowMessage("ev wt err");
  1506.      DosSleep(3000);
  1507.      DosExit(1,0);
  1508.     }
  1509.        rc = DosResetEventSem(replyhandle,&postcnt);
  1510.        if (rc)
  1511.     {
  1512.      ShowMessage("ev rsterr");
  1513.      DosSleep(3000);
  1514.      DosExit(1,0);
  1515.     }
  1516. // By now the other thread has filled in OpEntryStr
  1517. // string is already waiting for me...all I do is process it
  1518. #else
  1519.      /* fflush (stdout);
  1520.       i = (int) getstr (sx);*/
  1521. #endif
  1522.       sscanf (sx, "%s", s);
  1523.       if (i == EOF)
  1524.     ExitChess ();
  1525.       if (s[0] == '\0')
  1526.     continue;
  1527.       //if (strcmp (s, CP[131]) == 0)     /*bd*/
  1528.     //{
  1529. #if defined CHESSTOOL || defined XBOARD
  1530.       //chesstool = 0;
  1531. #endif /* CHESSTOOL */
  1532.       //ClrScreen ();
  1533.       //UpdateDisplay (0, 0, 1, 0);
  1534. #if defined CHESSTOOL || defined XBOARD
  1535.       //chesstool = 1;
  1536. #endif /* CHESSTOOL */
  1537.     //}
  1538.       //else if (strcmp (s, CP[129]) == 0) /* noop */ ;   /*alg*/
  1539.       else if ((strcmp (s, CP[180]) == 0) || (strcmp (s, CP[216]) == 0))        /* quit exit*/
  1540.     flag.quit = true;
  1541.       else if (strcmp (s, CP[178]) == 0)        /*post*/
  1542.     {
  1543.      /* flag.post = !flag.post;*/
  1544.     }
  1545.       //else if ((strcmp (s, CP[191]) == 0) || (strcmp (s, CP[154]) == 0))        /*set edit*/
  1546.     //EditBoard ();
  1547. #ifdef NONDSP
  1548.       //else if (strcmp (s, CP[190]) == 0)        /*setup*/
  1549.     //SetupBoard ();
  1550. #endif
  1551.       //else if (strcmp (s, CP[156]) == 0)        /*first*/
  1552.     //{
  1553. #if defined CHESSTOOL
  1554.       //computer = white;
  1555.       //opponent = black;
  1556.       //flag.force = false;
  1557.       //Sdepth = 0;
  1558. #endif /* CHESSTOOL */
  1559.       //ok = true;
  1560.     //}
  1561.       //else if (strcmp (s, CP[162]) == 0)        /*go*/
  1562.     //{
  1563.      // ok = true;
  1564.       //flag.force = false;
  1565.       //if (computer == white)
  1566.       //  {
  1567.       //    computer = black;
  1568.       //    opponent = white;
  1569.       //  }
  1570.       //else
  1571.       //  {
  1572.       //    computer = white;
  1573.       //    opponent = black;
  1574.       //  }
  1575.     //}
  1576.       //else if (strcmp (s, CP[166]) == 0)        /*help*/
  1577.     //help ();
  1578.       //else if (strcmp (s, CP[221]) == 0)        /*material*/
  1579.     //flag.material = !flag.material;
  1580.       //else if (strcmp (s, CP[157]) == 0)        /*force*/
  1581.     //{flag.force = !flag.force; flag.bothsides = false;}
  1582.       else if (strcmp (s, CP[134]) == 0)        /*book*/
  1583.     Book = Book ? 0 : BOOKFAIL;
  1584.       //else if (strcmp (s, CP[172]) == 0)        /*new*/
  1585.     //{
  1586.      // NewGame ();
  1587.      // UpdateDisplay (0, 0, 1, 0);
  1588.     //}
  1589.       //else if (strcmp (s, CP[171]) == 0)      /*list*/
  1590.     //ListGame (0xff);
  1591.       //else if (strcmp (s, CP[169]) == 0 || strcmp (s, CP[217]) == 0)    /*level clock*/
  1592.        //{
  1593.     //GetTimeString(tstr);
  1594.     //SelectLevel (tstr);
  1595.        //}
  1596.       //else if (strcmp (s, CP[165]) == 0)        /*hash*/
  1597.     //flag.hash = !flag.hash;
  1598.       else if (strcmp (s, CP[132]) == 0)        /*beep*/
  1599.     flag.beep = !flag.beep;
  1600.       //else if (strcmp (s, CP[197]) == 0)        /*time*/
  1601.     //{
  1602.      // SetMachineTime (sx);
  1603. //    }
  1604.       //else if (strcmp (s, CP[33]) == 0) /*Awindow*/
  1605.     //ChangeAlphaWindow ();
  1606.       //else if (strcmp (s, CP[39]) == 0) /*Bwindow*/
  1607.     //ChangeBetaWindow ();
  1608.       //else if (strcmp (s, CP[183]) == 0)        /*rcptr*/
  1609.     //flag.rcptr = !flag.rcptr;
  1610.       else if (stricmp(s,"calc") == 0)
  1611.        {
  1612.     calc_pgm_rating();
  1613.     OpEntryStr[0] = 0;
  1614.     s[0] = 0;
  1615.        }
  1616. //      else if (stricmp(s,"advan") == 0)
  1617. //       {
  1618. //    DoAdvanced();
  1619. //    OpEntryStr[0] = 0;
  1620. //    s[0] = 0;
  1621. //       }
  1622. //      else if (stricmp(s,"interm") == 0)
  1623. //       {
  1624. //    DoIntermediate();
  1625. //    OpEntryStr[0] = 0;
  1626. //    s[0] = 0;
  1627. //       }
  1628. //      else if (stricmp(s,"easy") == 0)
  1629. //       {
  1630. //    DoEasy();
  1631. //    OpEntryStr[0] = 0;
  1632. //    s[0] = 0;
  1633. //       }
  1634.       else if (strcmp (s, CP[168]) == 0)        /*hint*/
  1635.        {
  1636.     GiveHint ();
  1637.        }
  1638.       else if (strcmp (s, CP[135]) == 0)        /*both*/
  1639.     {
  1640.       flag.bothsides = !flag.bothsides;
  1641.       if (flag.bothsides)
  1642.        {
  1643.         thinkahead = 1;
  1644.        }
  1645.       flag.force = false;
  1646.       Sdepth = 0;
  1647.       ElapsedTime (1);
  1648.       SelectMove (opponent, 1);
  1649.       ok = true;
  1650.     }
  1651.       else if (strcmp (s, CP[185]) == 0)        /*reverse*/
  1652.     {
  1653. #ifdef NOTSUPPORTEDYET
  1654.       flag.reverse = !flag.reverse;
  1655.       ClrScreen ();
  1656.       UpdateDisplay (0, 0, 1, 0);
  1657. #endif
  1658.     }
  1659.       else if (strcmp (s, CP[195]) == 0)        /*switch*/
  1660.     {
  1661.       computer = computer ^ 1;
  1662.       opponent = opponent ^ 1;
  1663.       OrigComputer = computer;
  1664.       OrigOpponent = opponent;
  1665.       xwndw = (computer == white) ? WXWNDW : BXWNDW;
  1666.       flag.force = false;
  1667.       Sdepth = 0;
  1668.       if ((!GameCnt) && (Book) && (flag.regularstart))
  1669.        GetOpenings(computer);
  1670.       else
  1671.        Book = 0;
  1672.       ok = true;
  1673.     }
  1674.       //else if (strcmp (s, CP[203]) == 0)        /*white*/
  1675.     //{
  1676.     //  computer = black;
  1677.     //  opponent = white;
  1678.     //  xwndw = WXWNDW;
  1679.     //  flag.force = false;
  1680.     //  Sdepth = 0;
  1681.  
  1682.       /*
  1683.        * ok = true; don't automatically start with white command
  1684.        */
  1685.     //}
  1686.       //else if (strcmp (s, CP[133]) == 0)        /*black*/
  1687.     //{
  1688.       //computer = white;
  1689.       //opponent = black;
  1690.       //xwndw = BXWNDW;
  1691.       //flag.force = false;
  1692.       //Sdepth = 0;
  1693.  
  1694.       /*
  1695.        * ok = true; don't automatically start with black command
  1696.        */
  1697.     //}
  1698.       else if (strcmp (s, CP[201]) == 0 && GameCnt > 0) /*undo*/
  1699.     {
  1700. #ifdef NOTSUPPORTEDYET
  1701.       Undo ();
  1702. #endif
  1703.     }
  1704.       else if (strcmp (s, CP[184]) == 0 && GameCnt > 1) /*remove*/
  1705.     {
  1706. #ifdef NOTSUPPORTEDYET
  1707.       Undo ();
  1708.       Undo ();
  1709. #endif
  1710.     }
  1711.       //else if (strcmp (s, CP[160]) == 0)      /*get*/
  1712.     //GetGame ();
  1713.       //else if (strcmp (s, CP[207]) == 0)      /*xget*/
  1714.     //GetXGame ();
  1715.       //else if (strcmp (s, CP[189]) == 0)      /*save*/
  1716.     //SaveGame ();
  1717. //      else if (strcmp (s, CP[151]) == 0)        /*depth*/
  1718. //    ChangeSearchDepth ();
  1719. #ifdef DEBUG
  1720.       else if (strcmp (s, CP[147]) == 0)        /*debuglevel*/
  1721.     ChangeDbLev ();
  1722. #endif /* DEBUG */
  1723.       //else if (strcmp (s, CP[164]) == 0)        /*hashdepth*/
  1724.     //ChangeHashDepth ();
  1725.       //else if (strcmp (s, CP[182]) == 0)        /*random*/
  1726.     //dither = DITHER;
  1727.       else if (strcmp (s, CP[152]) == 0)        /*easy*/
  1728.        {
  1729.     /*flag.easy = !flag.easy;*/
  1730.     flag.easy = flag.easy; /* mod this for menu toggle on amiga */
  1731.        }
  1732.       //else if (strcmp (s, CP[143]) == 0)        /*contempt*/
  1733.     //SetContempt ();
  1734.       //else if (strcmp (s, CP[209]) == 0)        /*xwndw*/
  1735.     //ChangeXwindow ();
  1736.       //else if (strcmp (s, CP[186]) == 0)        /*rv*/
  1737.     //{
  1738.       //flag.rv = !flag.rv;
  1739.       //UpdateDisplay (0, 0, 1, 0);
  1740.     //}
  1741.       //else if (strcmp (s, CP[145]) == 0)        /*coords*/
  1742.     //{
  1743.      // flag.coords = !flag.coords;
  1744.       //UpdateDisplay (0, 0, 1, 0);
  1745.     //}
  1746.       //else if (strcmp (s, CP[193]) == 0)        /*stras*/
  1747.     //{
  1748.      // flag.stars = !flag.stars;
  1749.       //UpdateDisplay (0, 0, 1, 0);
  1750.     //}
  1751.       else if (strcmp (s, CP[196]) == 0)        /*test*/
  1752.     {
  1753. // *        ShowMessage (CP[108]);/*test movelist*/
  1754.       ShowMessage ("Testing..");
  1755.       func_num = 0;
  1756.       TestSpeed (MoveList, 20000);
  1757. // *        ShowMessage (CP[107]);/*test capturelist*/
  1758.       func_num++;
  1759.       TestSpeed (CaptureList, 30000);
  1760. // *        ShowMessage (CP[85]);/*test score position*/
  1761.       func_num++;
  1762.       TestPSpeed (ScorePosition, 15000);
  1763.     }
  1764.       //else if (strcmp (s, CP[179]) == 0)      /*p*/
  1765.     //ShowPostnValues ();
  1766. #ifdef DEBUGG
  1767.       else if (strcmp (s, CP[148]) == 0)        /*debug*/
  1768.     DoDebug ();
  1769.     else if (strcmp (s, "Mwpawn") == 0)        /*debug*/
  1770.     DoTable (Mwpawn);
  1771.     else if (strcmp (s, "Mbpawn") == 0)        /*debug*/
  1772.     DoTable (Mbpawn);
  1773.     else if (strcmp (s, "Mwknight") == 0)        /*debug*/
  1774.     DoTable (Mknight[white]);
  1775.     else if (strcmp (s, "Mbknight") == 0)        /*debug*/
  1776.     DoTable (Mknight[black]);
  1777.     else if (strcmp (s, "Mwbishop") == 0)        /*debug*/
  1778.     DoTable (Mbishop[white]);
  1779.     else if (strcmp (s, "Mbbishop") == 0)        /*debug*/
  1780.     DoTable (Mbishop[black]);
  1781. #endif
  1782.       else
  1783.     { /* this is where we move the humans pieces */
  1784. #if defined CHESSTOOL
  1785.       normal = (ok = VerifyMove (s, 0, &mv));
  1786. #else
  1787.       ok = VerifyMove (s, 0, &mv);
  1788. #endif
  1789. #ifdef OLDVERSION1_01
  1790.       if ((ok && mv != hint))
  1791.         {
  1792.           Sdepth = 0;
  1793.           ft = 0;
  1794.         }
  1795.       else
  1796.         Sdepth = 0;
  1797. #else
  1798. #ifndef OLD_LOOKAHEAD
  1799.       if ((ok)&&((mv != hint)||(flag.easy)||(Sdepth2<3)||(GameCnt <= 2)))
  1800.        {
  1801. #ifndef CLEARHISTBETWEENMOVES
  1802.         if (!flag.easy) // if  thinkahead was wrong clear hist
  1803.          ClearMem(history,sizeof (history));
  1804. #endif
  1805.         Sdepth = 0;
  1806.         need_to_zero = 1;
  1807.        }
  1808.      else // TMP DEBUG UNTIL I CAN GET SOMETHING BETTER
  1809.       {
  1810.         Sdepth = 0;
  1811.         need_to_zero = 1;
  1812.       }
  1813. #endif
  1814.       if (ok)
  1815.        {
  1816.             myGameCnt = GameCnt;
  1817.         MoveMem128(color,amigacolor); // I added these for OS/2!!
  1818.         MoveMem128(board,amigaboard); 
  1819.             if (global_promote_char) // added for OS/2
  1820.              {
  1821.                 global_promote_char = 0;
  1822.                 DrawAmigaBoard();
  1823.              }
  1824.         if ((!flag.easy)&&(mv == hint)&&(Sdepth2>2)&&(GameCnt > 2))
  1825.          {
  1826.           ThinkAheadDepth = Sdepth2;
  1827.           //if (ThinkInARow > 4) /* if it got to 4, we would have skipped one */
  1828.            ThinkInARow = 0;
  1829.           ThinkAheadWorked = 1;
  1830.          }
  1831.         else
  1832.          {
  1833. #ifndef CLEARHISTBETWEENMOVES
  1834.           if (!flag.easy) // if thinkahead is wrong clear hist
  1835.            ClearMem(history,sizeof (history));
  1836. #endif
  1837.           ThinkInARow = 0;
  1838.           ThinkAheadDepth = 0;
  1839.           ThinkAheadWorked = 0;
  1840.          }
  1841.        } // ok
  1842. #endif
  1843.       if ((!ok))
  1844.        {
  1845.         IllegalMove = 1;
  1846.             if (MouseDropped)
  1847.              PutPieceBack();
  1848.        }
  1849.       if ((ok)&&(MouseDropped))
  1850.        {
  1851.          if (myEnPassant[opponent^1])
  1852.           {
  1853.            AnimEnPassant(s);
  1854.           }
  1855.          else if (Castled[opponent])
  1856.           {
  1857.            AnimCastle(s);
  1858.           }
  1859.          //DoLegalMove(s);
  1860.          MouseDropped = 0;
  1861.        }
  1862.       //ClearMem(etab,sizeof(etab)); // I find it buggy to keep around!
  1863.       if (need_to_zero)
  1864.        {
  1865.         if (!flag.easy)
  1866.          PawnStorm = tmpPawnStorm;
  1867.         need_to_zero = 0;
  1868. //            if (!flag.easy)
  1869. //#ifndef AGING
  1870. //             ZeroTTable(0);
  1871. //#else
  1872. //             ZeroTTable(0);
  1873. //#endif
  1874.        }
  1875.       if (!ok)
  1876.        MouseDropped = 0;
  1877.     }
  1878.     }
  1879.  
  1880.   ElapsedTime (1);
  1881.   if (flag.force)
  1882.     {
  1883.       computer = opponent;
  1884.       opponent = computer ^ 1;
  1885.     }
  1886.  OpEntryStr[0] = 0; // am done with it, so clear it out
  1887. }
  1888.  
  1889.  
  1890. void
  1891. ElapsedTime (INTSIZE int iop)
  1892.  
  1893.  
  1894. /*
  1895.  * Determine the time that has passed since the search was started. If the
  1896.  * elapsed time exceeds the target (ResponseTime+ExtraTime) then set timeout
  1897.  * to true which will terminate the search. iop = 0 calculate et bump ETnodes
  1898.  * iop = 1 calculate et set timeout if time exceeded, calculate et
  1899.  */
  1900.  
  1901. {
  1902. #ifndef OLDWAY
  1903.   if (OpEntryRecvd)
  1904.    {
  1905.     OpEntryRecvd = 0;
  1906.     if ((thinkahead)&&(!flag.bothsides))
  1907.      {
  1908.       if (!TCflag)
  1909.        backsrchaborted = 1;
  1910.       if (!flag.timeout)
  1911.        {
  1912.         flag.back = true;
  1913.        }
  1914.       flag.bothsides = false;
  1915.      }
  1916.     else if (thinking2)
  1917.      {
  1918.       if (OpEntryRecvd == 2)
  1919.        { // move now!
  1920.          if (!flag.timeout)
  1921.           {
  1922.            flag.back = true;
  1923.            flag.musttimeout = true;
  1924.           }
  1925.          flag.bothsides = false;
  1926.        }
  1927.      }
  1928.    }
  1929. #else
  1930.   if (thinkahead)
  1931.   {
  1932.   while ( (localmessage = (struct IntuiMessage *)
  1933.     GetMsg(wG->UserPort) )) /* got a message at window port */
  1934.    {
  1935.     if (localmessage->Class == RAWKEY)
  1936.      {
  1937.       if (localmessage->Code < 56)
  1938.        code = cookedchar[localmessage->Code];
  1939.       else
  1940.        code = 0;
  1941.      }
  1942.     else
  1943.      {
  1944.       code = 'A';
  1945.      }
  1946.     if (isalpha(code))
  1947.      {
  1948.       (void)SetTaskPri((struct Task *)myproc,procpri);
  1949.       if (!TCflag)
  1950.        backsrchaborted = 1;
  1951.       if (!flag.timeout)
  1952.        {
  1953.         flag.back = true;
  1954.        }
  1955.       flag.bothsides = false;
  1956.       globalmessage_valid = 0xffff;
  1957.       globalmessage = *localmessage;
  1958.      }
  1959.     ReplyMsg((struct Message *)localmessage);
  1960.    }
  1961.   }
  1962.   else if (thinking2) /* check for move now menu item */
  1963.   {
  1964.   while ( (localmessage = (struct IntuiMessage *)
  1965.     GetMsg(wG->UserPort) )) /* got a message at window port */
  1966.    {
  1967.     class = localmessage->Class;
  1968.     code = localmessage->Code;
  1969.     ReplyMsg((struct Message *)localmessage);
  1970.     if ((class == MENUPICK))
  1971.       {
  1972.        if (ItemAddress(&Menu1,code) == &MenuItem6)
  1973.         {
  1974.          if (!flag.timeout)
  1975.           {
  1976.            flag.back = true;
  1977.            flag.musttimeout = true;
  1978.           }
  1979.          flag.bothsides = false;
  1980.         }
  1981.       }
  1982.    }
  1983.   }
  1984. #endif // oldway
  1985.   et = (time (0L) - time0) * 100;
  1986.   ETnodes = NodeCnt + ZNODES;
  1987.   if (et < 0)
  1988.     et = 0;
  1989.   if (iop == 1)
  1990.     {
  1991.       if (et > ResponseTime + ExtraTime && Sdepth > MINDEPTH)
  1992.     flag.timeout = true;
  1993.       ETnodes = NodeCnt + ZNODES;
  1994.       time0 = time (0L);
  1995.     }
  1996.   UpdateClocks ();
  1997. }
  1998.  
  1999.  
  2000. void
  2001. SetTimeControl (void)
  2002. {
  2003.  int tmp;
  2004.   if (TCflag)
  2005.     {
  2006.       TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
  2007.       TimeControl.clock[white] = 6000L * TCminutes + TCseconds * 100;
  2008.       TimeControl.clock[black] = 6000L * TCminutes + TCseconds * 100;
  2009.       SecsPerMove = tmp = (TCminutes*60+TCseconds)/TCmoves;
  2010.       if (tmp < 10)
  2011.        {
  2012.     GlobalTgtDepth = 2;
  2013.        }
  2014.       else if (tmp < 180)
  2015.        {
  2016.     GlobalTgtDepth = 3;
  2017.        }
  2018.       else
  2019.        GlobalTgtDepth = 4;
  2020.     }
  2021.   else
  2022.     {
  2023.       TimeControl.moves[white] = TimeControl.moves[black] = 0;
  2024.       TimeControl.clock[white] = TimeControl.clock[black] = 0;
  2025.     }
  2026.   flag.onemove = (TCmoves == 1);
  2027.   et = 0;
  2028.   ElapsedTime (1);
  2029. }
  2030.