home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / game / uchess-2.89.lha / UChess / src / dspcom.c < prev    next >
C/C++ Source or Header  |  1994-06-29  |  52KB  |  2,231 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. #include "gnuchess.h"
  25. void calc_pgm_rating(void);
  26. void DoEasy(void);
  27. void DoIntermediate(void);
  28. void DoAdvanced(void);
  29.  
  30. #define PTRHEIGHT 55
  31. extern UWORD chip myPointer[];
  32.  
  33. #define MYREPLY (1<<InputReply->mp_SigBit)
  34. extern struct MsgPort *InputReply;
  35. extern struct MsgPort *InThreadPort;
  36. extern struct myMsgStruct Global_Message;
  37.  
  38.  
  39. #if defined NULLMOVE || defined DEEPNULL
  40. extern short int __aligned no_null;
  41. extern short int __aligned null;         /* Null-move already made or not */
  42. extern short int __aligned PVari;        /* Is this the PV */
  43. #endif
  44. extern short __aligned Threat[MAXDEPTH];
  45. extern unsigned short int __aligned PrVar[MAXDEPTH];
  46. extern short __aligned PawnStorm;
  47. extern short __aligned start_stage;
  48. extern short __aligned thrashing_tt; /* must we recycle slots at random. TomV */
  49. extern INTSIZE __aligned amigaboard[64],amigacolor[64];
  50. int __aligned GetEntryDone;
  51.  
  52.  
  53. extern int OpEntryRecvd;
  54. extern char __aligned OpEntryStr[64];
  55. extern INTSIZE Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
  56. extern char *version, *patchlevel;
  57. char __aligned mvstr[8][8];
  58. char __aligned mvstrhint[8][8];
  59. char __aligned *InPtr;
  60. #define BOOKMENUNUM 0xc2
  61.  
  62. #ifdef CACHE
  63. extern struct etable __far __aligned etab[2][ETABLE];
  64. #endif
  65.  
  66.  
  67. void algbr2 (SHORT f, SHORT t, SHORT flag);
  68. extern unsigned int TTadd;
  69.  
  70. int __aligned SecsPerMove=10;
  71. extern int IllegalMove;
  72. int __aligned func_num=0;
  73. int __aligned thinkahead=0;
  74. int __aligned ThinkInARow=0;
  75. int __aligned ThinkAheadWorked=0;
  76. int __aligned ThinkAheadDepth=0;
  77.  
  78. extern int backsrchaborted;
  79. extern short int ISZERO;
  80. extern short __aligned background;
  81. int __aligned verifyquiet=0;
  82. int __aligned MouseDropped=0;
  83.  
  84. #include <ctype.h>
  85. #include <signal.h>
  86.  
  87. #ifdef AMIGA
  88. #define __USE_SYSBASE
  89. #include <exec/types.h>
  90. #include <exec/exec.h>
  91. #include <proto/exec.h>
  92. #include <proto/dos.h>
  93. #include <proto/graphics.h>
  94. #include <proto/intuition.h>
  95. struct IntuiMessage __aligned globalmessage;
  96. int __aligned globalmessage_valid=0;
  97. extern struct Window __aligned *wG;
  98. extern int procpri;
  99. extern struct Process *myproc;
  100. extern struct MenuItem MenuItem6;
  101. extern struct Menu Menu1;
  102. extern unsigned char __far cookedchar[128];
  103. extern struct Menu __aligned Menu1;
  104. #define MenuList1 Menu1
  105. extern struct MenuItem __aligned MenuItem8ab;
  106. extern int __aligned MenuStripSet;
  107. #endif
  108.  
  109. #define SIGQUIT SIGINT
  110.  
  111. #ifdef MSDOS
  112. #include <dos.h>
  113. #include <conio.h>
  114. #include <stdlib.h>
  115. #include <string.h>
  116. #include <time.h>
  117. #else
  118. #include <dos.h>
  119. #include <stdlib.h>
  120. #include <string.h>
  121. #include <time.h>
  122. /*
  123. #include <sys/param.h>
  124. #include <sys/types.h>
  125. #include <sys/file.h>
  126. #include <sys/ioctl.h>
  127. */
  128. #endif
  129.  
  130.  
  131. /*
  132.  * ataks.h - Header source for GNU CHESS
  133.  *
  134.  * Copyright (c) 1988,1989,1990 John Stanback
  135.  * Copyright (c) 1992 Free Software Foundation
  136.  *
  137.  * This file is part of GNU CHESS.
  138.  *
  139.  * GNU Chess is free software; you can redistribute it and/or modify
  140.  * it under the terms of the GNU General Public License as published by
  141.  * the Free Software Foundation; either version 2, or (at your option)
  142.  * any later version.
  143.  *
  144.  * GNU Chess is distributed in the hope that it will be useful,
  145.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  146.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  147.  * GNU General Public License for more details.
  148.  *
  149.  * You should have received a copy of the GNU General Public License
  150.  * along with GNU Chess; see the file COPYING.  If not, write to
  151.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  152.  */
  153. inline int
  154. SqAtakd2 (ARGSZ int sq, ARGSZ int side)
  155.  
  156. /*
  157.  * See if any piece with color 'side' ataks sq.  First check pawns then
  158.  * Queen, Bishop, Rook and King and last Knight.
  159.  */
  160.  
  161. {
  162.   register INTSIZE u;
  163.   register unsigned char *ppos, *pdir;
  164.   INTSIZE xside;
  165.  
  166.   xside = side ^ 1;
  167.   pdir = nextdir[ptype[xside][pawn]][sq];
  168.   u = pdir[sq];            /* follow captures thread */
  169.   if (u != sq)
  170.     {
  171.       if (board[u] == pawn && color[u] == side)
  172.     return (true);
  173.       u = pdir[u];
  174.       if (u != sq && board[u] == pawn && color[u] == side)
  175.     return (true);
  176.     }
  177.   /* king capture */
  178.   if (distance (sq, PieceList[side][0]) == 1)
  179.     return (true);
  180.   /* try a queen bishop capture */
  181.   ppos = nextpos[bishop][sq];
  182.   pdir = nextdir[bishop][sq];
  183.   u = ppos[sq];
  184.   do
  185.     {
  186.       if (color[u] == neutral)
  187.     u = ppos[u];
  188.       else
  189.     {
  190.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  191.         return (true);
  192.       u = pdir[u];
  193.     }
  194.   } while (u != sq);
  195.   /* try a queen rook capture */
  196.   ppos = nextpos[rook][sq];
  197.   pdir = nextdir[rook][sq];
  198.   u = ppos[sq];
  199.   do
  200.     {
  201.       if (color[u] == neutral)
  202.     u = ppos[u];
  203.       else
  204.     {
  205.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  206.         return (true);
  207.       u = pdir[u];
  208.     }
  209.   } while (u != sq);
  210.   /* try a knight capture */
  211.   pdir = nextdir[knight][sq];
  212.   u = pdir[sq];
  213.   do
  214.     {
  215.       if (color[u] == side && board[u] == knight)
  216.     return (true);
  217.       u = pdir[u];
  218.   } while (u != sq);
  219.   return (false);
  220. }
  221.  
  222.  
  223. #ifndef OLD_ALGBR
  224. void
  225. algbr (SHORT f, SHORT t, SHORT flag)
  226.  
  227.  
  228. /*
  229.  * Generate move strings in different formats.
  230.  */
  231.  
  232. {
  233.   int m3p;
  234.  
  235.   if (f != t)
  236.     {
  237.       /* algebraic notation */
  238.       mvstr[0][0] = cxx[column (f)];
  239.       mvstr[0][1] = rxx[row (f)];
  240.       mvstr[0][2] = cxx[column (t)];
  241.       mvstr[0][3] = rxx[row (t)];
  242.       mvstr[4][0] = mvstr[0][4] = mvstr[3][0] = '\0';
  243.       if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  244.     {
  245.       if (mvstr[0][0] == mvstr[0][2])    /* pawn did not eat */
  246.         {
  247.           mvstr[2][0] = mvstr[1][0] = mvstr[0][2];    /* to column */
  248.           mvstr[2][1] = mvstr[1][1] = mvstr[0][3];    /* to row */
  249.           m3p = 2;
  250.         }
  251.       else
  252.         /* pawn ate */
  253.         {
  254.           mvstr[2][0] = mvstr[1][0] = mvstr[0][0];    /* column */
  255.           mvstr[2][1] = mvstr[1][1] = mvstr[0][2];    /* to column */
  256.           mvstr[2][2] = mvstr[0][3];
  257.           m3p = 3;        /* to row */
  258.         }
  259.       if (flag & promote)
  260.         {
  261.           mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  262.           mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
  263. #ifdef CHESSTOOL 
  264.           mvstr[3][0] = mvstr[0][0];    /* Allow e7e8 for chesstool */
  265.           mvstr[3][1] = mvstr[0][1];
  266.           mvstr[3][2] = mvstr[0][2];
  267.           mvstr[3][3] = mvstr[0][3];
  268.           mvstr[3][4] = '\0';
  269. #endif
  270.         } else mvstr[2][m3p] = mvstr[1][2] = '\0';
  271.     }
  272.       else
  273.     /* not a pawn */
  274.     {
  275.       mvstr[2][0] = mvstr[1][0];
  276.       mvstr[2][1] = mvstr[0][1];
  277.       mvstr[2][2] = mvstr[1][1] = mvstr[0][2];    /* to column */
  278.       mvstr[2][3] = mvstr[1][2] = mvstr[0][3];    /* to row */
  279.       mvstr[2][4] = mvstr[1][3] = '\0';
  280.       strcpy (mvstr[3], mvstr[2]);
  281.           mvstr[3][1] = mvstr[0][0];
  282.       mvstr[4][0] = mvstr[1][0]; strcpy(&mvstr[4][1],mvstr[0]);
  283.       if (flag & cstlmask)
  284.         {
  285.           if (t > f)
  286.         {
  287.           //strcpy (mvstr[1], mvstr[0]);
  288.           strcpy (mvstr[1], CP[5]);
  289.           strcpy (mvstr[2], CP[7]);
  290.         }
  291.           else
  292.         {
  293.           //strcpy (mvstr[1], mvstr[0]);
  294.           strcpy (mvstr[1], CP[6]);
  295.           strcpy (mvstr[2], CP[8]);
  296.         }
  297.         }
  298.     }
  299.     }
  300.   else
  301.     mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = mvstr[4][0] = '\0';
  302. }
  303.  
  304. void
  305. algbr2 (SHORT f, SHORT t, SHORT flag)
  306.  
  307.  
  308. /*
  309.  * Generate move strings in different formats.
  310.  */
  311.  
  312. {
  313.   int m3p;
  314.  
  315.   if (f != t)
  316.     {
  317.       /* algebraic notation */
  318.       mvstrhint[0][0] = cxx[c