home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume19 / gnuchess / part05 < prev    next >
Encoding:
Text File  |  1991-05-17  |  50.1 KB  |  2,065 lines

  1. Newsgroups: comp.sources.misc
  2. From: Mike McGann <mwm@hasler.ascom.ch>
  3. Subject:  v19i077:  gnuchess - gnuchess version 3.1+, Part05/07
  4. Message-ID: <1991May17.024523.27798@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 6356813554cfd1013b441b2f02642dc8
  6. Date: Fri, 17 May 1991 02:45:23 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Mike McGann <mwm@hasler.ascom.ch>
  10. Posting-number: Volume 19, Issue 77
  11. Archive-name: gnuchess/part05
  12.  
  13. #!/bin/sh
  14. # do not concatenate these parts, unpack them in order with /bin/sh
  15. # file gnuchess.c continued
  16. #
  17. if test ! -r _shar_seq_.tmp; then
  18.     echo 'Please unpack part 1 first!'
  19.     exit 1
  20. fi
  21. (read Scheck
  22.  if test "$Scheck" != 5; then
  23.     echo Please unpack part "$Scheck" next!
  24.     exit 1
  25.  else
  26.     exit 0
  27.  fi
  28. ) < _shar_seq_.tmp || exit 1
  29. if test ! -f _shar_wnt_.tmp; then
  30.     echo 'x - still skipping gnuchess.c'
  31. else
  32. echo 'x - continuing file gnuchess.c'
  33. sed 's/^X//' << 'SHAR_EOF' >> 'gnuchess.c' &&
  34. X        case knight:
  35. X          s = KnightValue (sq, side);
  36. X          break;
  37. X        case bishop:
  38. X          s = BishopValue (sq, side);
  39. X          break;
  40. X        case rook:
  41. X          s = RookValue (sq, side);
  42. X          break;
  43. X        case queen:
  44. X          s = QueenValue (sq, side);
  45. X          break;
  46. X        case king:
  47. X          s = KingValue (sq, side);
  48. X          break;
  49. X        default:
  50. X          s = 0;
  51. X          break;
  52. X        }
  53. X      pscore[c1] += s;
  54. X      svalue[sq] = s;
  55. X    }
  56. X    }
  57. X  if (hung[side] > 1)
  58. X    pscore[side] += HUNGX;
  59. X  if (hung[xside] > 1)
  60. X    pscore[xside] += HUNGX;
  61. X
  62. X  *score = mtl[side] - mtl[xside] + pscore[side] - pscore[xside] + 10;
  63. X  if (dither)
  64. X    *score += urand () % dither;
  65. X
  66. X  if (*score > 0 && pmtl[side] == 0)
  67. X    if (emtl[side] < valueR)
  68. X      *score = 0;
  69. X    else if (*score < valueR)
  70. X      *score /= 2;
  71. X  if (*score < 0 && pmtl[xside] == 0)
  72. X    if (emtl[xside] < valueR)
  73. X      *score = 0;
  74. X    else if (-*score < valueR)
  75. X      *score /= 2;
  76. X
  77. X  if (mtl[xside] == valueK && emtl[side] > valueB)
  78. X    *score += 200;
  79. X  if (mtl[side] == valueK && emtl[xside] > valueB)
  80. X    *score -= 200;
  81. }
  82. X
  83. X
  84. static inline void
  85. BlendBoard (const short int a[64], const short int b[64], short int c[64])
  86. {
  87. X  register short *sqa, *sqb, *sqc, st;
  88. X  st = 10 - stage;
  89. X  for (sqa = a, sqb = b, sqc = c; sqa < a + 64;)
  90. X    *sqc++ = (*sqa++ * st + *sqb++ * stage) / 10;
  91. }
  92. X
  93. X
  94. static inline void
  95. CopyBoard (const short int a[64], short int b[64])
  96. {
  97. X  register short *sqa, *sqb;
  98. X
  99. X  for (sqa = a, sqb = b; sqa < a + 64; sqa++, sqb++)
  100. X    *sqb = *sqa;
  101. }
  102. X
  103. void
  104. ExaminePosition (void)
  105. X
  106. /*
  107. X  This is done one time before the search is started. Set up arrays
  108. X  Mwpawn, Mbpawn, Mknight, Mbishop, Mking which are used in the
  109. X  SqValue() function to determine the positional value of each piece.
  110. */
  111. X
  112. {
  113. X  register short i, sq;
  114. X  short wpadv, bpadv, wstrong, bstrong, z, side, pp, j, k, val, Pd, fyle, rank;
  115. X  static short PawnStorm = false;
  116. X
  117. X  ataks (white, atak[white]);
  118. X  ataks (black, atak[black]);
  119. X  UpdateWeights ();
  120. X  HasKnight[white] = HasKnight[black] = 0;
  121. X  HasBishop[white] = HasBishop[black] = 0;
  122. X  HasRook[white] = HasRook[black] = 0;
  123. X  HasQueen[white] = HasQueen[black] = 0;
  124. X  for (side = white; side <= black; side++)
  125. X    for (i = PieceCnt[side]; i >= 0; i--)
  126. X      switch (board[PieceList[side][i]])
  127. X    {
  128. X    case knight:
  129. X      ++HasKnight[side];
  130. X      break;
  131. X    case bishop:
  132. X      ++HasBishop[side];
  133. X      break;
  134. X    case rook:
  135. X      ++HasRook[side];
  136. X      break;
  137. X    case queen:
  138. X      ++HasQueen[side];
  139. X      break;
  140. X    }
  141. X  if (!Developed[white])
  142. X    Developed[white] = (board[1] != knight && board[2] != bishop &&
  143. X            board[5] != bishop && board[6] != knight);
  144. X  if (!Developed[black])
  145. X    Developed[black] = (board[57] != knight && board[58] != bishop &&
  146. X            board[61] != bishop && board[62] != knight);
  147. X  if (!PawnStorm && stage < 5)
  148. X    PawnStorm = ((column (wking) < 3 && column (bking) > 4) ||
  149. X         (column (wking) > 4 && column (bking) < 3));
  150. X
  151. X  CopyBoard (pknight, Mknight[white]);
  152. X  CopyBoard (pknight, Mknight[black]);
  153. X  CopyBoard (pbishop, Mbishop[white]);
  154. X  CopyBoard (pbishop, Mbishop[black]);
  155. X  BlendBoard (KingOpening, KingEnding, Mking[white]);
  156. X  BlendBoard (KingOpening, KingEnding, Mking[black]);
  157. X
  158. X  for (sq = 0; sq < 64; sq++)
  159. X    {
  160. X      fyle = column (sq);
  161. X      rank = row (sq);
  162. X      wstrong = bstrong = true;
  163. X      for (i = sq; i < 64; i += 8)
  164. X    if (Patak (black, i))
  165. X      {
  166. X        wstrong = false;
  167. X        break;
  168. X      }
  169. X      for (i = sq; i >= 0; i -= 8)
  170. X    if (Patak (white, i))
  171. X      {
  172. X        bstrong = false;
  173. X        break;
  174. X      }
  175. X      wpadv = bpadv = PADVNCM;
  176. X      if ((fyle == 0 || PawnCnt[white][fyle - 1] == 0) &&
  177. X      (fyle == 7 || PawnCnt[white][fyle + 1] == 0))
  178. X    wpadv = PADVNCI;
  179. X      if ((fyle == 0 || PawnCnt[black][fyle - 1] == 0) &&
  180. X      (fyle == 7 || PawnCnt[black][fyle + 1] == 0))
  181. X    bpadv = PADVNCI;
  182. X      Mwpawn[sq] = (wpadv * PawnAdvance[sq]) / 10;
  183. X      Mbpawn[sq] = (bpadv * PawnAdvance[63 - sq]) / 10;
  184. X      Mwpawn[sq] += PawnBonus;
  185. X      Mbpawn[sq] += PawnBonus;
  186. X      if (Mvboard[kingP[white]])
  187. X    {
  188. X      if ((fyle < 3 || fyle > 4) && distance (sq, wking) < 3)
  189. X        Mwpawn[sq] += PAWNSHIELD;
  190. X    }
  191. X      else if (rank < 3 && (fyle < 2 || fyle > 5))
  192. X    Mwpawn[sq] += PAWNSHIELD / 2;
  193. X      if (Mvboard[kingP[black]])
  194. X    {
  195. X      if ((fyle < 3 || fyle > 4) && distance (sq, bking) < 3)
  196. X        Mbpawn[sq] += PAWNSHIELD;
  197. X    }
  198. X      else if (rank > 4 && (fyle < 2 || fyle > 5))
  199. X    Mbpawn[sq] += PAWNSHIELD / 2;
  200. X      if (PawnStorm)
  201. X    {
  202. X      if ((column (wking) < 4 && fyle > 4) ||
  203. X          (column (wking) > 3 && fyle < 3))
  204. X        Mwpawn[sq] += 3 * rank - 21;
  205. X      if ((column (bking) < 4 && fyle > 4) ||
  206. X          (column (bking) > 3 && fyle < 3))
  207. X        Mbpawn[sq] -= 3 * rank;
  208. X    }
  209. X      Mknight[white][sq] += 5 - distance (sq, bking);
  210. X      Mknight[white][sq] += 5 - distance (sq, wking);
  211. X      Mknight[black][sq] += 5 - distance (sq, wking);
  212. X      Mknight[black][sq] += 5 - distance (sq, bking);
  213. X      Mbishop[white][sq] += BishopBonus;
  214. X      Mbishop[black][sq] += BishopBonus;
  215. X      for (i = PieceCnt[black]; i >= 0; i--)
  216. X    if (distance (sq, PieceList[black][i]) < 3)
  217. X      Mknight[white][sq] += KNIGHTPOST;
  218. X      for (i = PieceCnt[white]; i >= 0; i--)
  219. X    if (distance (sq, PieceList[white][i]) < 3)
  220. X      Mknight[black][sq] += KNIGHTPOST;
  221. X      if (wstrong)
  222. X    Mknight[white][sq] += KNIGHTSTRONG;
  223. X      if (bstrong)
  224. X    Mknight[black][sq] += KNIGHTSTRONG;
  225. X      if (wstrong)
  226. X    Mbishop[white][sq] += BISHOPSTRONG;
  227. X      if (bstrong)
  228. X    Mbishop[black][sq] += BISHOPSTRONG;
  229. X
  230. X      if (HasBishop[white] == 2)
  231. X    Mbishop[white][sq] += 8;
  232. X      if (HasBishop[black] == 2)
  233. X    Mbishop[black][sq] += 8;
  234. X      if (HasKnight[white] == 2)
  235. X    Mknight[white][sq] += 5;
  236. X      if (HasKnight[black] == 2)
  237. X    Mknight[black][sq] += 5;
  238. X
  239. X      Kfield[white][sq] = Kfield[black][sq] = 0;
  240. X      if (distance (sq, wking) == 1)
  241. X    Kfield[black][sq] = KATAK;
  242. X      if (distance (sq, bking) == 1)
  243. X    Kfield[white][sq] = KATAK;
  244. X
  245. X      Pd = 0;
  246. X      for (k = 0; k <= PieceCnt[white]; k++)
  247. X    {
  248. X      i = PieceList[white][k];
  249. X      if (board[i] == pawn)
  250. X        {
  251. X          pp = true;
  252. X          z = (row (i) == 6) ? i + 8 : i + 16;
  253. X          for (j = i + 8; j < 64; j += 8)
  254. X        if (Patak (black, j) || board[j] == pawn)
  255. X          {
  256. X            pp = false;
  257. X            break;
  258. X          }
  259. X          Pd += (pp) ? 5 * taxicab (sq, z) : taxicab (sq, z);
  260. X        }
  261. X    }
  262. X      for (k = 0; k <= PieceCnt[black]; k++)
  263. X    {
  264. X      i = PieceList[black][k];
  265. X      if (board[i] == pawn)
  266. X        {
  267. X          pp = true;
  268. X          z = (row (i) == 1) ? i - 8 : i - 16;
  269. X          for (j = i - 8; j >= 0; j -= 8)
  270. X        if (Patak (white, j) || board[j] == pawn)
  271. X          {
  272. X            pp = false;
  273. X            break;
  274. X          }
  275. X          Pd += (pp) ? 5 * taxicab (sq, z) : taxicab (sq, z);
  276. X        }
  277. X    }
  278. X      if (Pd != 0)
  279. X    {
  280. X      val = (Pd * stage2) / 10;
  281. X      Mking[white][sq] -= val;
  282. X      Mking[black][sq] -= val;
  283. X    }
  284. X    }
  285. }
  286. X
  287. void
  288. UpdateWeights (void)
  289. X
  290. /*
  291. X  If material balance has changed, determine the values for the positional
  292. X  evaluation terms.
  293. */
  294. X
  295. {
  296. X  register short tmtl, s1;
  297. X
  298. X  emtl[white] = mtl[white] - pmtl[white] - valueK;
  299. X  emtl[black] = mtl[black] - pmtl[black] - valueK;
  300. X  tmtl = emtl[white] + emtl[black];
  301. X  s1 = (tmtl > 6600) ? 0 : ((tmtl < 1400) ? 10 : (6600 - tmtl) / 520);
  302. X  if (s1 != stage)
  303. X    {
  304. X      stage = s1;
  305. X      stage2 = (tmtl > 3600) ? 0 : ((tmtl < 1400) ? 10 : (3600 - tmtl) / 220);
  306. X      PEDRNK2B = -15;        /* centre pawn on 2nd rank & blocked */
  307. X      PBLOK = -4;        /* blocked backward pawn */
  308. X      PDOUBLED = -14;        /* doubled pawn */
  309. X      PWEAKH = -4;        /* weak pawn on half open file */
  310. X      PAWNSHIELD = 10 - stage;    /* pawn near friendly king */
  311. X      PADVNCM = 10;        /* advanced pawn multiplier */
  312. X      PADVNCI = 7;        /* muliplier for isolated pawn */
  313. X      PawnBonus = stage;
  314. X
  315. X      KNIGHTPOST = (stage + 2) / 3;    /* knight near enemy pieces */
  316. X      KNIGHTSTRONG = (stage + 6) / 2;    /* occupies pawn hole */
  317. X
  318. X      BISHOPSTRONG = (stage + 6) / 2;    /* occupies pawn hole */
  319. X      BishopBonus = 2 * stage;
  320. X
  321. X      RHOPN = 10;        /* rook on half open file */
  322. X      RHOPNX = 4;
  323. X      RookBonus = 6 * stage;
  324. X
  325. X      XRAY = 8;            /* Xray attack on piece */
  326. X      PINVAL = 10;        /* Pin */
  327. X
  328. X      KHOPN = (3 * stage - 30) / 2;    /* king on half open file */
  329. X      KHOPNX = KHOPN / 2;
  330. X      KCASTLD = 10 - stage;
  331. X      KMOVD = -40 / (stage + 1);/* king moved before castling */
  332. X      KATAK = (10 - stage) / 2;    /* B,R attacks near enemy king */
  333. X      if (stage < 8)
  334. X    KSFTY = 16 - 2 * stage;
  335. X      else
  336. X    KSFTY = 0;
  337. X
  338. X      ATAKD = -6;        /* defender > attacker */
  339. X      HUNGP = -8;        /* each hung piece */
  340. X      HUNGX = -12;        /* extra for >1 hung piece */
  341. X    }
  342. }
  343. SHAR_EOF
  344. echo 'File gnuchess.c is complete' &&
  345. chmod 0664 gnuchess.c ||
  346. echo 'restore of gnuchess.c failed'
  347. Wc_c="`wc -c < 'gnuchess.c'`"
  348. test 79899 -eq "$Wc_c" ||
  349.     echo 'gnuchess.c: original size 79899, current size' "$Wc_c"
  350. rm -f _shar_wnt_.tmp
  351. fi
  352. # ============= gnuchess.h ==============
  353. if test -f 'gnuchess.h' -a X"$1" != X"-c"; then
  354.     echo 'x - skipping gnuchess.h (File already exists)'
  355.     rm -f _shar_wnt_.tmp
  356. else
  357. > _shar_wnt_.tmp
  358. echo 'x - extracting gnuchess.h (Text)'
  359. sed 's/^X//' << 'SHAR_EOF' > 'gnuchess.h' &&
  360. /*
  361. X  gnuchess.h - Header file for GNU CHESS
  362. X
  363. X  Revision: 1990-04-18
  364. X
  365. X  Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  366. X
  367. X  This file is part of CHESS.
  368. X
  369. X  CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  370. X  WARRANTY.  No author or distributor accepts responsibility to anyone for
  371. X  the consequences of using it or for whether it serves any particular
  372. X  purpose or works at all, unless he says so in writing.  Refer to the CHESS
  373. X  General Public License for full details.
  374. X
  375. X  Everyone is granted permission to copy, modify and redistribute CHESS, but
  376. X  only under the conditions described in the CHESS General Public License.
  377. X  A copy of this license is supposed to have been given to you along with
  378. X  CHESS so you can know your rights and responsibilities.  It should be in a
  379. X  file named COPYING.  Among other things, the copyright notice and this
  380. X  notice must be preserved on all copies.
  381. */
  382. X
  383. #include <stdio.h>
  384. /* <stdio.h */
  385. extern int fclose (FILE *);
  386. extern int fscanf (FILE *, const char *, ...);
  387. extern int fprintf (FILE *, const char *, ...);
  388. extern int fflush (FILE *);
  389. #define SEEK_SET 0
  390. #define SEEK_END 2
  391. #ifdef DEBUG
  392. void ShowDBLine(char *,short int ,short int ,
  393. X        short int , short int ,short int , 
  394. X        short unsigned int *);
  395. extern FILE *debugfd;
  396. extern short int debuglevel;
  397. #endif /*DEBUG*/
  398. X
  399. #if !defined(__STDC__) || !defined(MSDOS)
  400. #define const
  401. #endif
  402. X
  403. #ifndef __GNUC__
  404. #define inline
  405. #endif
  406. X
  407. /*
  408. X  ttblsz must be a power of 2.
  409. X  Setting ttblsz 0 removes the transposition tables.
  410. */
  411. #ifdef MSDOS
  412. #define ttblsz (1 << 11)
  413. #else
  414. #define ttblsz (1 << 16)
  415. #define huge
  416. #endif /* MSODS */
  417. X
  418. #define maxdepth 30
  419. #define white 0
  420. #define black 1
  421. #define neutral 2
  422. #define no_piece 0
  423. #define pawn 1
  424. #define knight 2
  425. #define bishop 3
  426. #define rook 4
  427. #define queen 5
  428. #define king 6
  429. #define bpawn 7
  430. #define pmask 0x0007
  431. #define promote 0x0008
  432. #define cstlmask 0x0010
  433. #define epmask 0x0020
  434. #define exact 0x0040
  435. #define pwnthrt 0x0080
  436. #define check 0x0100
  437. #define capture 0x0200
  438. #define draw 0x0400
  439. #define maxdepth 30
  440. #define false 0
  441. #define true 1
  442. /* #define absv(x) ((x) < 0 ? -(x) : (x)) */
  443. X
  444. struct leaf
  445. {
  446. X  short f, t, score, reply;
  447. X  unsigned short flags;
  448. };
  449. struct GameRec
  450. {
  451. X  unsigned short gmove;
  452. X  short score, depth, time, piece, color,flags;
  453. X  long nodes;
  454. };
  455. struct TimeControlRec
  456. {
  457. X  short moves[2];
  458. X  long clock[2];
  459. };
  460. struct BookEntry
  461. {
  462. X  struct BookEntry *next;
  463. X  unsigned short *mv;
  464. };
  465. X
  466. struct flags
  467. {
  468. X  short mate;        /* the game is over */
  469. X  short post;        /* show principle variation */
  470. X  short quit;        /* quit/exit gnuchess */
  471. X  short reverse;    /* reverse board display */
  472. X  short bothsides;    /* computer plays both sides */
  473. X  short hash;        /* enable/disable transposition table */
  474. X  short force;        /* enter moves */
  475. X  short easy;        /* disable thinking on opponents time */
  476. X  short beep;        /* enable/disable beep */
  477. X  short timeout;    /* time to make a move */
  478. X  short rcptr;        /* enable/disable recapture heuristics */
  479. };
  480. X
  481. extern struct leaf Tree[2000], *root;
  482. extern char savefile[128], listfile[128];
  483. extern short TrPnt[maxdepth];
  484. extern short board[64], color[64];
  485. extern short PieceList[2][16], PawnCnt[2][8];
  486. extern short castld[2], Mvboard[64];
  487. extern short svalue[64];
  488. extern struct flags flag;
  489. extern short opponent, computer, Awindow, Bwindow, INCscore;
  490. extern short dither, player;
  491. extern short xwndw, epsquare, contempt;
  492. extern long ResponseTime, ExtraTime, Level, et, et0, time0, ft;
  493. extern long NodeCnt, ETnodes, EvalNodes, HashAdd,HashCnt, HashCol, FHashCnt, FHashAdd;
  494. extern short HashDepth, HashMoveLimit;
  495. extern struct GameRec GameList[200];
  496. extern short GameCnt, Game50;
  497. extern short Sdepth, MaxSearchDepth;
  498. extern struct BookEntry *Book;
  499. extern struct TimeControlRec TimeControl;
  500. extern short TCflag, TCmoves, TCminutes, OperatorTime;
  501. extern const short otherside[3];
  502. extern const short Stboard[64];
  503. extern const short Stcolor[64];
  504. extern unsigned short hint, PrVar[maxdepth];
  505. extern char *DRAW;
  506. X
  507. #define distance(a,b) distdata[a][b]
  508. #define row(a) ((a) >> 3)
  509. #define column(a) ((a) & 7)
  510. #define locn(a,b) (((a) << 3) | b)
  511. extern short distdata[64][64];
  512. X
  513. /* gnuchess.c external functions */
  514. extern void NewGame (void);
  515. /* book.c */
  516. extern int parse (FILE * fd, short unsigned int *mv, short int side);
  517. extern void GetOpenings (void);
  518. extern void OpeningBook (unsigned short int *hint);
  519. /* search.c */
  520. extern void repetition (short int *cnt);
  521. extern void SelectMove (short int side, short int iop);
  522. extern int search (short int side,
  523. X           short int ply,
  524. X           short int depth,
  525. X           short int alpha,
  526. X           short int beta,
  527. X           short unsigned int *bstline,
  528. X           short int *rpt);
  529. /* tran.c */
  530. #if ttblsz
  531. extern int ProbeTTable (short int side,
  532. X            short int depth,
  533. X            short int *alpha,
  534. X            short int *beta,
  535. X            short int *score);
  536. extern int PutInTTable (short int side,
  537. X             short int score,
  538. X             short int depth,
  539. X             short int alpha,
  540. X             short int beta,
  541. X             short unsigned int mv);
  542. extern void ZeroTTable (void);
  543. extern void ZeroRPT (void);
  544. #ifdef HASHFILE
  545. extern unsigned int urand(void);
  546. extern void srand(unsigned int);
  547. extern int ProbeFTable (short int side,
  548. X            short int depth,
  549. X            short int *alpha,
  550. X            short int *beta,
  551. X            short int *score);
  552. extern void PutInFTable (short int side,
  553. X             short int score,
  554. X             short int depth,
  555. X             short int alpha,
  556. X             short int beta,
  557. X             short unsigned int f,
  558. X             short unsigned int t);
  559. #endif /* HASHFILE */
  560. #endif /* ttblsz */
  561. /* move.c */
  562. extern void Initialize_moves (void);
  563. extern void MoveList (short int side, short int ply);
  564. extern void CaptureList (short int side, short int ply);
  565. extern int castle (short int side, short int kf, short int kt, short int iop);
  566. extern void MakeMove (short int side,
  567. X              struct leaf * node,
  568. X              short int *tempb,
  569. X              short int *tempc,
  570. X              short int *tempsf,
  571. X              short int *tempst,
  572. X              short int *INCscore);
  573. extern void UnmakeMove (short int side,
  574. X            struct leaf * node,
  575. X            short int *tempb,
  576. X            short int *tempc,
  577. X            short int *tempsf,
  578. X            short int *tempst);
  579. extern void InitializeStats (void);
  580. /* eval.c */
  581. extern int SqAtakd (short int sq, short int side);
  582. extern int evaluate (short int side,
  583. X             short int ply,
  584. X             short int alpha,
  585. X             short int beta,
  586. X             short int INCscore,
  587. X             short int *slk,
  588. X             short int *InChk);
  589. extern void ScoreLoneKing (short int side, short int *score);
  590. extern void ScorePosition (short int side, short int *score);
  591. extern void ExaminePosition (void);
  592. extern void UpdateWeights (void);
  593. X
  594. /* *dsp.c external functions */
  595. extern void Initialize (void);
  596. extern void InputCommand (void);
  597. extern void ExitChess (void);
  598. extern void ClrScreen (void);
  599. extern void SetTimeControl (void);
  600. extern void SelectLevel (void);
  601. extern void UpdateDisplay (short int f,
  602. X               short int t,
  603. X               short int flag,
  604. X               short int iscastle);
  605. extern void ElapsedTime (short int iop);
  606. extern void ShowSidetoMove (void);
  607. extern void SearchStartStuff (short int side);
  608. extern void ShowDepth (char ch);
  609. extern void ShowResults (short int score,
  610. X             short unsigned int *bstline,
  611. X             char ch);
  612. extern void algbr (short int f, short int t, short int flag);
  613. extern void OutputMove (void);
  614. extern void ShowCurrentMove (short int pnt, short int f, short int t);
  615. extern void ListGame (void);
  616. extern void ShowMessage (char *s);
  617. extern void ClrScreen (void);
  618. extern void gotoXY (short int x, short int y);
  619. extern void ClrEoln (void);
  620. extern void DrawPiece (short int sq);
  621. extern void UpdateClocks (void);
  622. extern void ShowLine (short unsigned int *bstline);
  623. X
  624. SHAR_EOF
  625. chmod 0664 gnuchess.h ||
  626. echo 'restore of gnuchess.h failed'
  627. Wc_c="`wc -c < 'gnuchess.h'`"
  628. test 7534 -eq "$Wc_c" ||
  629.     echo 'gnuchess.h: original size 7534, current size' "$Wc_c"
  630. rm -f _shar_wnt_.tmp
  631. fi
  632. # ============= nondsp.c ==============
  633. if test -f 'nondsp.c' -a X"$1" != X"-c"; then
  634.     echo 'x - skipping nondsp.c (File already exists)'
  635.     rm -f _shar_wnt_.tmp
  636. else
  637. > _shar_wnt_.tmp
  638. echo 'x - extracting nondsp.c (Text)'
  639. sed 's/^X//' << 'SHAR_EOF' > 'nondsp.c' &&
  640. /*
  641. X  nondsp.c - UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
  642. X
  643. X  Revision: 1991-04-15
  644. X
  645. X  Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  646. X  Copyright (c) 1988, 1989, 1990  John Stanback
  647. X
  648. X  This file is part of CHESS.
  649. X
  650. X  CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  651. X  WARRANTY.  No author or distributor accepts responsibility to anyone for
  652. X  the consequences of using it or for whether it serves any particular
  653. X  purpose or works at all, unless he says so in writing.  Refer to the CHESS
  654. X  General Public License for full details.
  655. X
  656. X  Everyone is granted permission to copy, modify and redistribute CHESS, but
  657. X  only under the conditions described in the CHESS General Public License.
  658. X  A copy of this license is supposed to have been given to you along with
  659. X  CHESS so you can know your rights and responsibilities.  It should be in a
  660. X  file named COPYING.  Among other things, the copyright notice and this
  661. X  notice must be preserved on all copies.
  662. */
  663. X
  664. #include <ctype.h>
  665. #include <signal.h>
  666. #ifdef MSDOS
  667. #include <dos.h>
  668. #include <conio.h>
  669. #include <stdlib.h>
  670. #include <string.h>
  671. #include <time.h>
  672. #else
  673. #include <sys/param.h>
  674. #include <sys/types.h>
  675. #include <sys/file.h>
  676. #include <sys/ioctl.h>
  677. void TerminateSearch (int), Die (int);
  678. #endif /* MSDOS */
  679. X
  680. #include "gnuchess.h"
  681. X
  682. #define pxx " PNBRQK"
  683. #define qxx " pnbrqk"
  684. #define rxx "12345678"
  685. #define cxx "abcdefgh"
  686. #define printz printf
  687. #define scanz scanf
  688. char Analysis[128] = "";
  689. short int MV[29];
  690. int MSCORE;
  691. #ifdef DEBUG
  692. short int debuglevel = 0;
  693. FILE *debugfd;
  694. #endif /*DEBUG*/
  695. #ifdef CHESSTOOL
  696. short int chesstool = 1;
  697. #else
  698. short int chesstool = 0;
  699. #endif /*CHESSTOOL*/
  700. char mvstr[4][6];
  701. static char *ColorStr[2] =
  702. {"White", "Black"};
  703. static long evrate;
  704. static int mycnt1, mycnt2;
  705. static int ahead;
  706. char *DRAW;
  707. X
  708. void
  709. Initialize (void)
  710. {
  711. X  mycnt1 = mycnt2 = 0;
  712. #ifdef CHESSTOOL
  713. X  setlinebuf (stdout);
  714. X  /* setvbuf(stdout,NULL,_IOLBF,BUFSIZ); */
  715. X  printf ("Chess\n");
  716. X  if (Level == 0 && !TCflag)
  717. X    Level = 15;
  718. #endif /* CHESSTOOL */
  719. }
  720. X
  721. void
  722. ExitChess (void)
  723. {
  724. X  ListGame ();
  725. X  exit (0);
  726. }
  727. X
  728. #ifndef MSDOS                /* never called!!! */
  729. void
  730. Die (int sig)
  731. {
  732. X  char s[80];
  733. X  ShowMessage ("Abort? ");
  734. X  scanz ("%s", s);
  735. X  if (strcmp (s, "yes") == 0)
  736. X    ExitChess ();
  737. }
  738. X
  739. #endif /* MSDOS */
  740. X
  741. void
  742. TerminateSearch (int sig)
  743. {
  744. #ifdef MSDOS
  745. X  sig++;                /* shut up the compiler */
  746. #endif /* MSDOS */
  747. X  flag.timeout = true;
  748. X  flag.bothsides = false;
  749. }
  750. X
  751. void
  752. algbr (short int f, short int t, short int flag)
  753. X
  754. X
  755. /*
  756. X   Generate move strings in different formats.
  757. */
  758. X
  759. {
  760. X  int m3p;
  761. X
  762. X  if (f != t)
  763. X    {
  764. X      /* algebraic notation */
  765. X      mvstr[0][0] = cxx[column (f)];
  766. X      mvstr[0][1] = rxx[row (f)];
  767. X      mvstr[0][2] = cxx[column (t)];
  768. X      mvstr[0][3] = rxx[row (t)];
  769. X      mvstr[0][4] = mvstr[3][0] = '\0';
  770. X      if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  771. X    {
  772. X      if (mvstr[0][0] == mvstr[0][2])    /* pawn did not eat */
  773. X        {
  774. X          mvstr[2][0] = mvstr[1][0] = mvstr[0][2];    /* to column */
  775. X          mvstr[2][1] = mvstr[1][1] = mvstr[0][3];    /* to row */
  776. X          m3p = 2;
  777. X        }
  778. X      else
  779. X        /* pawn ate */
  780. X        {
  781. X          mvstr[2][0] = mvstr[1][0] = mvstr[0][0];    /* from column */
  782. X          mvstr[2][1] = mvstr[1][1] = mvstr[0][2];    /* to column */
  783. X          mvstr[2][2] = mvstr[0][3];
  784. X          m3p = 3;            /* to row */
  785. X        }
  786. X      if (flag & promote)
  787. X        {
  788. X          mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  789. X          mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[0][5] = '\0';
  790. X        }
  791. X      mvstr[2][m3p] = mvstr[1][2] = '\0';
  792. X    }
  793. X      else
  794. X    /* not a pawn */
  795. X    {
  796. X      mvstr[2][0] = mvstr[1][0];
  797. X      mvstr[2][1] = mvstr[0][1];
  798. X      mvstr[2][2] = mvstr[1][1] = mvstr[0][2];    /* to column */
  799. X      mvstr[2][3] = mvstr[1][2] = mvstr[0][3];    /* to row */
  800. X      mvstr[2][4] = mvstr[1][3] = '\0';
  801. X      strcpy (mvstr[3], mvstr[2]);
  802. X      mvstr[3][1] = mvstr[0][0];
  803. X      if (flag & cstlmask)
  804. X        {
  805. X          if (t > f)
  806. X        {
  807. X          strcpy (mvstr[1], "o-o");
  808. X          strcpy (mvstr[2], "O-O");
  809. X        }
  810. X          else
  811. X        {
  812. X          strcpy (mvstr[1], "o-o-o");
  813. X          strcpy (mvstr[2], "O-O-O");
  814. X        }
  815. X        }
  816. X    }
  817. X    }
  818. X  else
  819. X    mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
  820. }
  821. X
  822. X
  823. int
  824. VerifyMove (char *s, short int iop, short unsigned int *mv)
  825. X
  826. /*
  827. X   Compare the string 's' to the list of legal moves available for the
  828. X   opponent. If a match is found, make the move on the board.
  829. */
  830. X
  831. {
  832. X  static short pnt, tempb, tempc, tempsf, tempst, cnt;
  833. X  static struct leaf xnode;
  834. X  struct leaf *node;
  835. X
  836. X  *mv = 0;
  837. X  if (iop == 2)
  838. X    {
  839. X      UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  840. X      return (false);
  841. X    }
  842. X  cnt = 0;
  843. X  MoveList (opponent, 2);
  844. X  pnt = TrPnt[2];
  845. X  while (pnt < TrPnt[3])
  846. X    {
  847. X      node = &Tree[pnt++];
  848. X      algbr (node->f, node->t, (short) node->flags);
  849. X      if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  850. X      strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
  851. X    {
  852. X      cnt++;
  853. X      xnode = *node;
  854. X    }
  855. X    }
  856. X  if (cnt == 1)
  857. X    {
  858. X      MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  859. X      if (SqAtakd (PieceList[opponent][0], computer))
  860. X    {
  861. X      UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  862. X      printz ("Illegal move..(you are in check)\n");
  863. X      return (false);
  864. X    }
  865. X      else
  866. X    {
  867. X      if (iop == 1)
  868. X        return (true);
  869. X      UpdateDisplay (xnode.f, xnode.t, 0, (short) xnode.flags);
  870. X      if ((board[xnode.t] == pawn)
  871. X          || (xnode.flags & capture)
  872. X          || (xnode.flags & cstlmask))
  873. X        {
  874. X          Game50 = GameCnt;
  875. X          ZeroRPT ();
  876. X        }
  877. X      GameList[GameCnt].depth = GameList[GameCnt].score = 0;
  878. X      GameList[GameCnt].nodes = 0;
  879. X      ElapsedTime (1);
  880. X      GameList[GameCnt].time = (short) et;
  881. X      TimeControl.clock[opponent] -= et;
  882. X      --TimeControl.moves[opponent];
  883. X      *mv = (xnode.f << 8) | xnode.t;
  884. X      algbr (xnode.f, xnode.t, false);
  885. X      return (true);
  886. X    }
  887. X    }
  888. #ifdef CHESSTOOL
  889. X  printz ("Illegal move (no matching move generated)");
  890. X  printz ("%s ", s);
  891. #ifdef DEBUG
  892. X  if (true)
  893. X    {
  894. X      short r, c, l;
  895. X      pnt = TrPnt[2];
  896. X      fprintf (debugfd, "Illegal Move\nInput move is |%s|\n", s);
  897. X      fprintf (debugfd, "Generated moves are:\n");
  898. X      while (pnt < TrPnt[3])
  899. X    {
  900. X      node = &Tree[pnt++];
  901. X      algbr (node->f, node->t, (short) node->flags);
  902. X      fprintf (debugfd, "|%s|%s|%s|%s|\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3]);
  903. X    }
  904. X      fprintf (debugfd, "\nCurrent board is:\n");
  905. X      for (r = 7; r >= 0; r--)
  906. X    {
  907. X      for (c = 0; c <= 7; c++)
  908. X        {
  909. X          l = locn (r, c);
  910. X          if (color[l] == neutral)
  911. X        fprintf (debugfd, " -");
  912. X          else if (color[l] == white)
  913. X        fprintf (debugfd, " %c", qxx[board[l]]);
  914. X          else
  915. X        fprintf (debugfd, " %c", pxx[board[l]]);
  916. X        }
  917. X      fprintf (debugfd, "\n");
  918. X    }
  919. X      fprintf (debugfd, "\n");
  920. X    }
  921. #endif /* DEBUG*/
  922. #else
  923. X  if (cnt > 1)
  924. X    ShowMessage ("Ambiguous Move!");
  925. #endif /*CHESSTOOL*/
  926. X  return (false);
  927. }
  928. X
  929. void
  930. help (void)
  931. {
  932. X  ClrScreen ();
  933. X  printz ("CHESS command summary\n");
  934. X  printz ("----------------------------------------------------------------\n");
  935. X  printz ("g1f3      move from g1 to f3      quit      Exit Chess\n");
  936. X  printz ("Nf3       move knight to f3       beep      on/off\n");
  937. X  printz ("o-o       castle king side        easy      on/off\n");
  938. X  printz ("o-o-o     castle queen side       hash      on/off\n");
  939. X  printz ("bd        redraw board            reverse   board display\n");
  940. X  printz ("list      game to chess.lst       book      on/off\n");
  941. X  printz ("undo      undo last ply           remove    take back a move\n");
  942. X  printz ("edit      edit board              force     enter game moves\n");
  943. X  printz ("switch    sides with computer     both      computer match\n");
  944. X  printz ("white     computer plays white    black     computer plays black\n");
  945. X  printz ("depth     set search depth        clock     set time control\n");
  946. X  printz ("post      principle variation     hint      suggest a move\n");
  947. X  printz ("save      game to file            get       game from file\n");
  948. X  printz ("random    randomize play          new       start new game\n");
  949. X  printz ("----------------------------------------------------------------\n");
  950. X  printz ("Computer: %-12s Opponent:            %s\n",
  951. X      ColorStr[computer], ColorStr[opponent]);
  952. X  printz ("Depth:    %-12d Response time:       %d sec\n",
  953. X      MaxSearchDepth, Level);
  954. X  printz ("Random:   %-12s Easy mode:           %s\n",
  955. X      (dither) ? "ON" : "OFF", (flag.easy) ? "ON" : "OFF");
  956. X  printz ("Beep:     %-12s Transposition table: %s\n",
  957. X      (flag.beep) ? "ON" : "OFF", (flag.hash) ? "ON" : "OFF");
  958. X  signal (SIGINT, TerminateSearch);
  959. #ifndef MSDOS
  960. X  signal (SIGQUIT, TerminateSearch);
  961. #endif /* MSDOS */
  962. }
  963. X
  964. void
  965. EditBoard (void)
  966. /*
  967. X   Set up a board position. Pieces are entered by typing the piece followed
  968. X   by the location. For example, Nf3 will place a knight on square f3.
  969. */
  970. X
  971. {
  972. X  short a, r, c, sq, i;
  973. X  char s[80];
  974. X
  975. X  ClrScreen ();
  976. X  UpdateDisplay (0, 0, 1, 0);
  977. X  printz (".   exit to main\n");
  978. X  printz ("#   clear board\n");
  979. X  printz ("c   change sides\n");
  980. X  printz ("enter piece & location: \n");
  981. X
  982. X  a = white;
  983. X  do
  984. X    {
  985. X      scanz ("%s", s);
  986. X      if (s[0] == '#')
  987. X    for (sq = 0; sq < 64; sq++)
  988. X      {
  989. X        board[sq] = no_piece;
  990. X        color[sq] = neutral;
  991. X      }
  992. X      if (s[0] == 'c' || s[0] == 'C')
  993. X    a = otherside[a];
  994. X      c = s[1] - 'a';
  995. X      r = s[2] - '1';
  996. X      if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  997. X    {
  998. X      sq = locn (r, c);
  999. X      color[sq] = a;
  1000. X      board[sq] = no_piece;
  1001. X      for (i = no_piece; i <= king; i++)
  1002. X        if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  1003. X          {
  1004. X        board[sq] = i;
  1005. X        break;
  1006. X          }
  1007. X    }
  1008. X  } while (s[0] != '.');
  1009. X  for (sq = 0; sq < 64; sq++)
  1010. X    Mvboard[sq] = (board[sq] != Stboard[sq]) ? 10 : 0;
  1011. X  GameCnt = 0;
  1012. X  Game50 = 1;
  1013. X  ZeroRPT ();
  1014. X  InitializeStats ();
  1015. X  ClrScreen ();
  1016. X  UpdateDisplay (0, 0, 1, 0);
  1017. }
  1018. X
  1019. void
  1020. SetupBoard (void)
  1021. X
  1022. /*
  1023. X   Compatibility with Unix chess and the nchesstool.
  1024. X   Set up a board position. Eight lines of eight characters are used
  1025. X   to setup the board. a8-h8 is the first line.
  1026. X   Black pieces are  represented  by  uppercase characters.
  1027. */
  1028. X
  1029. {
  1030. X  short r, c, sq, i;
  1031. X  char ch;
  1032. X  char s[80];
  1033. X
  1034. X  NewGame ();
  1035. X
  1036. X  gets (s);                /* skip "setup" command */
  1037. X  for (r = 7; r >= 0; r--)
  1038. X    {
  1039. X      gets (s);
  1040. X      for (c = 0; c <= 7; c++)
  1041. X    {
  1042. X      ch = s[c];
  1043. X      sq = locn (r, c);
  1044. X      color[sq] = neutral;
  1045. X      board[sq] = no_piece;
  1046. X      for (i = no_piece; i <= king; i++)
  1047. X        if (ch == pxx[i])
  1048. X          {
  1049. X        color[sq] = black;
  1050. X        board[sq] = i;
  1051. X        break;
  1052. X          }
  1053. X        else if (ch == qxx[i])
  1054. X          {
  1055. X        color[sq] = white;
  1056. X        board[sq] = i;
  1057. X        break;
  1058. X          }
  1059. X    }
  1060. X    }
  1061. X  for (sq = 0; sq < 64; sq++)
  1062. X    Mvboard[sq] = (board[sq] != Stboard[sq]) ? 10 : 0;
  1063. X  InitializeStats ();
  1064. X  ClrScreen ();
  1065. X  UpdateDisplay (0, 0, 1, 0);
  1066. X  printz ("Setup successful\n");
  1067. }
  1068. X
  1069. void
  1070. ShowDepth (char ch)
  1071. {
  1072. #ifdef MSDOS
  1073. X  ch++;                    /* shut up the compiler */
  1074. #endif /* MSDOS */
  1075. }
  1076. X
  1077. #ifdef DEBUG
  1078. void
  1079. ShowDBLine (const char *x, short int ply, short int depth,
  1080. X        short int alpha, short int beta, short int score,
  1081. X        short unsigned int *bstline)
  1082. {
  1083. X  register int i;
  1084. X  if (debuglevel > 2)
  1085. X    {
  1086. X      fprintf (debugfd, "%s ply %d depth %d alpha %d beta %d score %d",
  1087. X           x, ply, depth, alpha, beta, score);
  1088. X      for (i = 1; bstline[i] != 0; i++)
  1089. X    {
  1090. X      if ((i > 1) && (i % 8 == 1))
  1091. X        fprintf (debugfd, "\n                          ");
  1092. X      algbr ((short) (bstline[i] >> 8), (short) (bstline[i] & 0xFF), false);
  1093. X      fprintf (debugfd, "%5s ", mvstr[0]);
  1094. X    }
  1095. X      fprintf (debugfd, "\n");
  1096. X    }
  1097. }
  1098. X
  1099. #endif /*DEBUG*/
  1100. X
  1101. void
  1102. ShowLine (short unsigned int *bstline)
  1103. {
  1104. X  register int i;
  1105. X  for (i = 1; bstline[i] > 0; i++)
  1106. X    {
  1107. X      if ((i > 1) && (i % 8 == 1))
  1108. X    fprintf (stderr, "\n                          ");
  1109. X      algbr ((short) (bstline[i] >> 8), (short) (bstline[i] & 0xFF), false);
  1110. X      fprintf (stderr, "%5s ", mvstr[0]);
  1111. X    }
  1112. X  fprintf (stderr, "\n");
  1113. }
  1114. X
  1115. void
  1116. ShowResults (short int score, short unsigned int *bstline, char ch)
  1117. {
  1118. X  register int i;
  1119. #ifndef CHESSTOOL
  1120. X  if (flag.post)
  1121. X    {
  1122. X      fprintf (stderr, "%2d%c %6d %4ld %8ld  ", Sdepth, ch, score, et, NodeCnt);
  1123. X      ShowLine (bstline);
  1124. X    }
  1125. #else
  1126. X  MSCORE = score;
  1127. X  for (i = 1; bstline[i] > 0; i++)
  1128. X    {
  1129. X      MV[i] = bstline[i];
  1130. X    } MV[i] = 0;
  1131. #endif /* CHESSTOOL */
  1132. }
  1133. X
  1134. void
  1135. SearchStartStuff (short int side)
  1136. {
  1137. X  signal (SIGINT, TerminateSearch);
  1138. #ifndef MSDOS
  1139. X  signal (SIGQUIT, TerminateSearch);
  1140. #endif /* MSDOS */
  1141. #ifndef CHESSTOOL
  1142. X  if (flag.post)
  1143. X    {
  1144. X      fprintf (stderr, "\nMove# %d    Target= %ld    Clock: %ld\n",
  1145. X           TCmoves - TimeControl.moves[side] + 1,
  1146. X           ResponseTime, TimeControl.clock[side]);
  1147. X    }
  1148. #endif /* CHESSTOOL */
  1149. }
  1150. X
  1151. void
  1152. OutputMove (void)
  1153. {
  1154. X  printz ("%d. ... %s\n", ++mycnt1, mvstr[0]);
  1155. #ifdef DEBUG
  1156. X  fprintf (debugfd,"%d. ... %s\n", ++mycnt1, mvstr[0]);
  1157. #endif /*DEBUG*/
  1158. X  if (root->flags & draw)
  1159. X    {
  1160. X      printz ("Draw %s\n", DRAW);
  1161. X      ExitChess ();
  1162. X    }
  1163. X  if (root->score == -9999)
  1164. X    {
  1165. X      printz ("%s\n", ColorStr[opponent]);
  1166. X      ExitChess ();
  1167. X    }
  1168. X  if (root->score == 9998)
  1169. X    {
  1170. X      printz ("%s\n", ColorStr[computer]);
  1171. X      ExitChess ();
  1172. X    }
  1173. #ifndef CHESSTOOL
  1174. X  if (flag.post)
  1175. X    {
  1176. X      fprintf (stderr, "Nodes= %ld  Eval= %ld  Rate= %ld  ",
  1177. X           NodeCnt, EvalNodes, evrate);
  1178. X      fprintf (stderr, "Hin/Hout/Coll/Fin/Fout = %ld/%ld/%ld/%ld/%ld\n",
  1179. X           HashAdd, HashCnt, HashCol, FHashAdd, FHashCnt);
  1180. X    }
  1181. #endif /* CHESSTOOL */
  1182. X  UpdateDisplay (root->f, root->t, 0, root->flags);
  1183. X  fprintf (stderr, "My move is: %s\n", mvstr[0]);
  1184. #ifdef DEBUG
  1185. X  fprintf (debugfd, "My move is: %s\n", mvstr[0]);
  1186. #endif /* DEBUG */
  1187. X  if (flag.beep)
  1188. X    printz ("%c", 7);
  1189. X
  1190. X  if (root->flags & draw)
  1191. X    fprintf (stderr, "Drawn game!\n");
  1192. X  else if (root->score == -9999)
  1193. X    fprintf (stderr, "opponent mates!\n");
  1194. X  else if (root->score == 9998)
  1195. X    fprintf (stderr, "computer mates!\n");
  1196. X  else if (root->score < -9000)
  1197. X    fprintf (stderr, "opponent will soon mate!\n");
  1198. X  else if (root->score > 9000)
  1199. X    fprintf (stderr, "computer will soon mate!\n");
  1200. }
  1201. X
  1202. void
  1203. ElapsedTime (short int iop)
  1204. X
  1205. X
  1206. /*
  1207. X   Determine the time that has passed since the search was started. If the
  1208. X   elapsed time exceeds the target (ResponseTime+ExtraTime) then set timeout
  1209. X   to true which will terminate the search.
  1210. */
  1211. X
  1212. {
  1213. X  if (ahead)
  1214. X    {
  1215. #ifndef MSDOS
  1216. X      long nchar;
  1217. X      ioctl (0, FIONREAD, &nchar);
  1218. X      if (nchar)
  1219. #else
  1220. X      if (kbhit ())
  1221. #endif /* MSDOS */
  1222. X    {
  1223. X      flag.timeout = true;
  1224. X      flag.bothsides = false;
  1225. X    }
  1226. X    }
  1227. X  et = time ((long *) 0) - time0;
  1228. X  if (et < 0)
  1229. X    et = 0;
  1230. X  ETnodes += 50;
  1231. X  if (et > et0 || iop == 1)
  1232. X    {
  1233. X      if (et > ResponseTime + ExtraTime && Sdepth > 1)
  1234. X    flag.timeout = true;
  1235. X      et0 = et;
  1236. X      if (iop == 1)
  1237. X    {
  1238. X      time0 = time ((long *) 0);
  1239. X      et0 = 0;
  1240. X    }
  1241. X      if (et > 0)
  1242. X    /* evrate used to be Nodes / cputime I dont` know why */
  1243. X    evrate = NodeCnt / (et + ft);
  1244. X      else
  1245. X    evrate = 0;
  1246. X      ETnodes = NodeCnt + 50;
  1247. X    }
  1248. }
  1249. X
  1250. void
  1251. SetTimeControl (void)
  1252. {
  1253. X  if (TCflag)
  1254. X    {
  1255. X      TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
  1256. X      TimeControl.clock[white] = TimeControl.clock[black] = 60L * TCminutes;
  1257. X    }
  1258. X  else
  1259. X    {
  1260. X      TimeControl.moves[white] = TimeControl.moves[black] = 0;
  1261. X      TimeControl.clock[white] = TimeControl.clock[black] = 0;
  1262. X      Level = 60L * TCminutes;
  1263. X    }
  1264. X  et = 0;
  1265. X  ElapsedTime (1);
  1266. }
  1267. X
  1268. void
  1269. ClrScreen (void)
  1270. {
  1271. #ifndef CHESSTOOL
  1272. X  printz ("\n");
  1273. #endif
  1274. }
  1275. X
  1276. void
  1277. UpdateDisplay (short int f, short int t, short int redraw, short int isspec)
  1278. {
  1279. X
  1280. X  short r, c, l;
  1281. X  if (redraw && !chesstool)
  1282. X    {
  1283. X      printz ("\n");
  1284. X      for (r = 7; r >= 0; r--)
  1285. X    {
  1286. X      for (c = 0; c <= 7; c++)
  1287. X        {
  1288. X          l = (flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c);
  1289. X          if (color[l] == neutral)
  1290. X        printz (" -");
  1291. X          else if (color[l] == white)
  1292. X        printz (" %c", qxx[board[l]]);
  1293. X          else
  1294. X        printz (" %c", pxx[board[l]]);
  1295. X        }
  1296. X      printz ("\n");
  1297. X    }
  1298. X      printz ("\n");
  1299. X    }
  1300. }
  1301. X
  1302. char *InPtr;
  1303. void
  1304. skip ()
  1305. {
  1306. X  while (*InPtr != ' ')
  1307. X    InPtr++;
  1308. X  while (*InPtr == ' ')
  1309. X    InPtr++;
  1310. }
  1311. void
  1312. skipb ()
  1313. {
  1314. X  while (*InPtr == ' ')
  1315. X    InPtr++;
  1316. }
  1317. int
  1318. parser (char *f, int side)
  1319. {
  1320. X  int c1, r1, c2, r2;
  1321. X  if (f[4] == 'o')
  1322. X    if (side == black)
  1323. X      return 0x3C3A;
  1324. X    else
  1325. X      return 0x0402;
  1326. X  else if (f[0] == 'o')
  1327. X    if (side == black)
  1328. X      return 0x3C3E;
  1329. X    else
  1330. X      return 0x0406;
  1331. X  else
  1332. X    {
  1333. X      c1 = f[0] - 'a';
  1334. X      r1 = f[1] - '1';
  1335. X      c2 = f[2] - 'a';
  1336. X      r2 = f[3] - '1';
  1337. X      return (locn (r1, c1) << 8) | locn (r2, c2);
  1338. X    }
  1339. X  return (0);
  1340. }
  1341. X
  1342. void
  1343. GetGame (void)
  1344. {
  1345. X  FILE *fd;
  1346. X  char fname[256], *p;
  1347. X  int c, i, j;
  1348. X  short sq;
  1349. X  unsigned short m;
  1350. X  printz ("Enter file name: ");
  1351. X  scanz ("%s", fname);
  1352. X  if (fname[0] == '\0')
  1353. X    strcpy (fname, "chess.000");
  1354. X  if ((fd = fopen (fname, "r")) != NULL)
  1355. X    {
  1356. X      fgets (fname, 256, fd);
  1357. X      computer = opponent = white;
  1358. X      InPtr = fname;
  1359. X      skip ();
  1360. X      if (*InPtr == 'c')
  1361. X    computer = black;
  1362. X      else
  1363. X    opponent = black;
  1364. X      skip ();
  1365. X      skip ();
  1366. X      skip ();
  1367. X      Game50 = atoi (InPtr);
  1368. X      fgets (fname, 256, fd);
  1369. X      InPtr = &fname[14];
  1370. X      castld[white] = (*InPtr == 't') ? true : false;
  1371. X      skip ();
  1372. X      skip ();
  1373. X      castld[black] = (*InPtr == 't') ? true : false;
  1374. X      fgets (fname, 256, fd);
  1375. X      InPtr = &fname[11];
  1376. X      skipb ();
  1377. X      TCflag = atoi (InPtr);
  1378. X      skip ();
  1379. X      InPtr += 14;
  1380. X      skipb ();
  1381. X      OperatorTime = atoi (InPtr);
  1382. X      fgets (fname, 256, fd);
  1383. X      InPtr = &fname[11];
  1384. X      skipb ();
  1385. X      TimeControl.clock[white] = atoi (InPtr);
  1386. X      skip ();
  1387. X      skip ();
  1388. X      TimeControl.moves[white] = atoi (InPtr);
  1389. X      fgets (fname, 256, fd);
  1390. X      InPtr = &fname[11];
  1391. X      skipb ();
  1392. X      TimeControl.clock[black] = atoi (InPtr);
  1393. X      skip ();
  1394. X      skip ();
  1395. X      TimeControl.moves[black] = atoi (InPtr);
  1396. X      fgets (fname, 256, fd);
  1397. X      for (i = 7; i > -1; i--)
  1398. X    {
  1399. X      fgets (fname, 256, fd);
  1400. X      p = &fname[2];
  1401. X      InPtr = &fname[11];
  1402. X      skipb ();
  1403. X      for (j = 0; j < 8; j++)
  1404. X        {
  1405. X          sq = i * 8 + j;
  1406. X          if (*p == '.')
  1407. X        {
  1408. X          board[sq] = no_piece;
  1409. X          color[sq] = neutral;
  1410. X        }
  1411. X          else
  1412. X        {
  1413. X          for (c = 0; c < 8; c++)
  1414. X            {
  1415. X              if (*p == pxx[c])
  1416. X            {
  1417. X              board[sq] = c;
  1418. X              color[sq] = black;
  1419. X            }
  1420. X            }
  1421. X          for (c = 0; c < 8; c++)
  1422. X            {
  1423. X              if (*p == qxx[c])
  1424. X            {
  1425. X              board[sq] = c;
  1426. X              color[sq] = white;
  1427. X            }
  1428. X            }
  1429. X        }
  1430. X          p++;
  1431. X          Mvboard[sq] = atoi (InPtr);
  1432. X          skip ();
  1433. X        }
  1434. X    }
  1435. X      GameCnt = 0;
  1436. X      fgets (fname, 256, fd);
  1437. X      fgets (fname, 256, fd);
  1438. X      fgets (fname, 256, fd);
  1439. X      while (fgets (fname, 256, fd))
  1440. X    {
  1441. X      struct GameRec *g;
  1442. X      int side = computer;
  1443. X      side = otherside[side];
  1444. X      ++GameCnt;
  1445. X      InPtr = fname;
  1446. X      skipb ();
  1447. X      g = &GameList[GameCnt];
  1448. X      g->gmove = parser (InPtr, side);
  1449. X      skip ();
  1450. X      g->score = atoi (InPtr);
  1451. X      skip ();
  1452. X      g->depth = atoi (InPtr);
  1453. X      skip ();
  1454. X      g->nodes = atoi (InPtr);
  1455. X      skip ();
  1456. X      g->time = atoi (InPtr);
  1457. X      skip ();
  1458. X      g->flags = c = atoi (InPtr);
  1459. X      g->piece = no_piece;
  1460. X      g->color = neutral;
  1461. X      if (c & (capture | cstlmask))
  1462. X        {
  1463. X          if (c & capture)
  1464. X        {
  1465. X          skip ();
  1466. X          for (c = 0; c < 8; c++)
  1467. X            if (pxx[c] == *InPtr)
  1468. X              break;
  1469. X          g->piece = c;
  1470. X        }
  1471. X          skip ();
  1472. X          g->color = ((*InPtr == 'B') ? black : white);
  1473. X        }
  1474. X    }
  1475. X      /* GameCnt--;*/
  1476. X      if (TimeControl.clock[white] > 0)
  1477. X    TCflag = true;
  1478. X      fclose (fd);
  1479. X    }
  1480. X  InitializeStats ();
  1481. X  UpdateDisplay (0, 0, 1, 0);
  1482. X  Sdepth = 0;
  1483. }
  1484. X
  1485. void
  1486. GetXGame (void)
  1487. {
  1488. X  FILE *fd;
  1489. X  char fname[256], *p;
  1490. X  int c, i, j;
  1491. X  short sq;
  1492. X  unsigned short m;
  1493. X  strcpy (fname, "xboard.position.read");
  1494. X  if ((fd = fopen (fname, "r")) != NULL)
  1495. X    {
  1496. X      NewGame ();
  1497. X      fgets (fname, 256, fd);
  1498. X      fname[6] = '\0';
  1499. X      if (strcmp (fname, "xboard"))
  1500. X    return;
  1501. X      fgets (fname, 256, fd);
  1502. X      fgets (fname, 256, fd);
  1503. X      for (i = 7; i > -1; i--)
  1504. X    {
  1505. X      fgets (fname, 256, fd);
  1506. X      p = fname;
  1507. X      for (j = 0; j < 8; j++)
  1508. X        {
  1509. X          sq = i * 8 + j;
  1510. X          if (*p == '.')
  1511. X        {
  1512. X          board[sq] = no_piece;
  1513. X          color[sq] = neutral;
  1514. X        }
  1515. X          else
  1516. X        {
  1517. X          for (c = 0; c < 8; c++)
  1518. X            {
  1519. X              if (*p == qxx[c])
  1520. X            {
  1521. X              board[sq] = c;
  1522. X              color[sq] = black;
  1523. X            }
  1524. X            }
  1525. X          for (c = 0; c < 8; c++)
  1526. X            {
  1527. X              if (*p == pxx[c])
  1528. X            {
  1529. X              board[sq] = c;
  1530. X              color[sq] = white;
  1531. X            }
  1532. X            }
  1533. X        }
  1534. X          p += 2;
  1535. X        }
  1536. X    }
  1537. X      fclose (fd);
  1538. X    }
  1539. X  ZeroRPT ();
  1540. X  InitializeStats ();
  1541. X  UpdateDisplay (0, 0, 1, 0);
  1542. X  Sdepth = 0;
  1543. }
  1544. X
  1545. void
  1546. SaveGame (void)
  1547. {
  1548. X  FILE *fd;
  1549. X  char fname[256];
  1550. X  short sq, i, c, f, t;
  1551. X  char p;
  1552. X
  1553. X  if (savefile[0])
  1554. X    strcpy (fname, savefile);
  1555. X  else
  1556. X    {
  1557. X      printz ("Enter file name: ");
  1558. X      scanz ("%s", fname);
  1559. X    }
  1560. X
  1561. X  if (fname[0] == '\0')
  1562. X    strcpy (fname, "chess.000");
  1563. X  if ((fd = fopen (fname, "w")) != NULL)
  1564. X    {
  1565. X      char *b, *w;
  1566. X      b = w = "Human";
  1567. X      if (computer == black)
  1568. X    b = "computer";
  1569. X      if (computer == white)
  1570. X    w = "computer";
  1571. X      fprintf (fd, "Black %s White %s %d\n", b, w, Game50);
  1572. X      fprintf (fd, "Castled White %s Black %s\n", castld[white] ? "true" : "false", castld[black] ? "true" : "false");
  1573. X      fprintf (fd, "TimeControl %d Operator Time %d\n", TCflag, OperatorTime);
  1574. X      fprintf (fd, "White Clock %ld Moves %ld\nBlack Clock %d Moves %d\n\n",
  1575. X           TimeControl.clock[white], TimeControl.moves[white],
  1576. X           TimeControl.clock[black], TimeControl.moves[black]);
  1577. X      for (i = 7; i > -1; i--)
  1578. X    {
  1579. X      fprintf (fd, "%1d ", i + 1);
  1580. X      for (c = 0; c < 8; c++)
  1581. X        {
  1582. X          sq = i * 8 + c;
  1583. X          switch (color[sq])
  1584. X        {
  1585. X        case black:
  1586. X          p = pxx[board[sq]];
  1587. X          break;
  1588. X        case white:
  1589. X          p = qxx[board[sq]];
  1590. X          break;
  1591. X        default:
  1592. X          p = '.';
  1593. X        }
  1594. X          fprintf (fd, "%c", p);
  1595. X        }
  1596. X      for (f = i * 8; f < i * 8 + 8; f++)
  1597. X        fprintf (fd, " %d", Mvboard[f]);
  1598. X      fprintf (fd, "\n");
  1599. X    }
  1600. X      fprintf (fd, "  %s\n", cxx);
  1601. X      fprintf (fd, "\nmove  score depth  nodes  time flags capture color\n");
  1602. X      for (i = 1; i <= GameCnt; i++)
  1603. X    {
  1604. X      struct GameRec *g = &GameList[i];
  1605. X      f = g->gmove >> 8;
  1606. X      t = (g->gmove & 0xFF);
  1607. X      algbr (f, t, g->flags);
  1608. X      fprintf (fd, "%s %5d %5d %7ld %5d %5d   %c   %s\n",
  1609. X           mvstr[0], g->score, g->depth,
  1610. X           g->nodes, g->time, g->flags,
  1611. X           pxx[g->piece], g->color == 2 ? "     " : ColorStr[g->color]);
  1612. X    }
  1613. X      fclose (fd);
  1614. X      printz ("Game saved on file: %s\n", fname);
  1615. X    }
  1616. X  else
  1617. X    printz ("Could not open file: %s", fname);
  1618. }
  1619. X
  1620. void
  1621. ListGame (void)
  1622. {
  1623. X  FILE *fd;
  1624. X  short i, f, t;
  1625. X  char fname[256];
  1626. X  if (listfile[0])
  1627. X    strcpy (fname, listfile);
  1628. X  else
  1629. X    strcpy (fname, "chess.lst");
  1630. X  fd = fopen (fname, "w");
  1631. X  fprintf (fd, "gnuchess\n");
  1632. X  fprintf (fd, "       score  depth   nodes  time         ");
  1633. X  fprintf (fd, "       score  depth   nodes  time\n");
  1634. X  for (i = 1; i <= GameCnt; i++)
  1635. X    {
  1636. X      f = GameList[i].gmove >> 8;
  1637. X      t = (GameList[i].gmove & 0xFF);
  1638. X      algbr (f, t, false);
  1639. X      if ((i % 2) == 0)
  1640. X    fprintf (fd, "         ");
  1641. X      else
  1642. X    fprintf (fd, "\n");
  1643. X      fprintf (fd, "%5s  %5d     %2d %7ld %5d", mvstr[0],
  1644. X           GameList[i].score, GameList[i].depth,
  1645. X           GameList[i].nodes, GameList[i].time);
  1646. X    }
  1647. X  fprintf (fd, "\n\n");
  1648. X  fclose (fd);
  1649. }
  1650. X
  1651. void
  1652. Undo (void)
  1653. /*
  1654. X   Undo the most recent half-move.
  1655. */
  1656. X
  1657. {
  1658. X  short f, t;
  1659. X  f = GameList[GameCnt].gmove >> 8;
  1660. X  t = GameList[GameCnt].gmove & 0xFF;
  1661. X  if (board[t] == king && distance (t, f) > 1)
  1662. X    (void) castle (GameList[GameCnt].color, f, t, 2);
  1663. X  else
  1664. X    {
  1665. X      /* Check for promotion: */
  1666. X      if (GameList[GameCnt].flags & promote)
  1667. X    {
  1668. X      board[t] = pawn;
  1669. X    }
  1670. X      board[f] = board[t];
  1671. X      color[f] = color[t];
  1672. X      board[t] = GameList[GameCnt].piece;
  1673. X      color[t] = GameList[GameCnt].color;
  1674. X      if (color[t] != neutral)
  1675. X    Mvboard[t]--;
  1676. X      Mvboard[f]--;
  1677. X    }
  1678. X  if (GameList[GameCnt].flags & epmask)
  1679. X    EnPassant (color[t], f, t, 2);
  1680. X  if (TCflag)
  1681. X    ++TimeControl.moves[color[f]];
  1682. X  GameCnt--;
  1683. X  computer = otherside[computer];
  1684. X  opponent = otherside[opponent];
  1685. X  flag.mate = false;
  1686. X  Sdepth = 0;
  1687. X  player = otherside[player];
  1688. X  ShowSidetoMove();
  1689. X  UpdateDisplay (0, 0, 1, 0);
  1690. X  InitializeStats ();
  1691. }
  1692. X
  1693. void
  1694. ShowMessage (char *s)
  1695. {
  1696. X  fprintf (stderr, "%s\n", s);
  1697. }
  1698. X
  1699. void
  1700. ShowSidetoMove (void)
  1701. {
  1702. }
  1703. X
  1704. void
  1705. PromptForMove (void)
  1706. {
  1707. #ifndef CHESSTOOL
  1708. X  printz ("\nYour move is? ");
  1709. #endif /* CHESSTOOL */
  1710. }
  1711. X
  1712. X
  1713. void
  1714. ShowCurrentMove (short int pnt, short int f, short int t)
  1715. {
  1716. #ifdef MSDOS
  1717. X  f++;
  1718. X  t++;
  1719. X  pnt++;                /* shut up the compiler */
  1720. #endif /* MSDOS */
  1721. }
  1722. X
  1723. void
  1724. ChangeAlphaWindow (void)
  1725. {
  1726. X  printz ("window: ");
  1727. X  scanz ("%hd", &Awindow);
  1728. }
  1729. X
  1730. void
  1731. ChangeBetaWindow (void)
  1732. {
  1733. X  printz ("window: ");
  1734. X  scanz ("%hd", &Bwindow);
  1735. }
  1736. X
  1737. void
  1738. SetAnalysis (void)
  1739. {
  1740. X  printz ("game file: ");
  1741. X  scanz ("%s", &Analysis);
  1742. }
  1743. X
  1744. void
  1745. GiveHint (void)
  1746. {
  1747. X  algbr ((short) (hint >> 8), (short) (hint & 0xFF), false);
  1748. X  fprintf (stderr, "Hint: %s\n", mvstr[0]);
  1749. }
  1750. X
  1751. void
  1752. SelectLevel (void)
  1753. {
  1754. X  printz ("Enter #moves #minutes: ");
  1755. X  scanz ("%hd %hd", &TCmoves, &TCminutes);
  1756. X  printz ("Operator time= ");
  1757. X  scanz ("%hd", &OperatorTime);
  1758. X  TCflag = (TCmoves > 1);
  1759. X  SetTimeControl ();
  1760. }
  1761. X
  1762. #ifdef DEBUG
  1763. void
  1764. ChangeDbLev (void)
  1765. {
  1766. X  printz ("debuglevel= ");
  1767. X  scanz ("%hd", &debuglevel);
  1768. }
  1769. X
  1770. #endif /*DEBUG*/
  1771. X
  1772. void
  1773. ChangeSearchDepth (void)
  1774. {
  1775. X  printz ("depth= ");
  1776. X  scanz ("%hd", &MaxSearchDepth);
  1777. }
  1778. X
  1779. ChangeHashDepth (void)
  1780. {
  1781. X  printz ("hashdepth= ");
  1782. X  scanz ("%hd", &HashDepth);
  1783. X  printz ("MoveLimit= ");
  1784. X  scanz ("%hd", &HashMoveLimit);
  1785. }
  1786. X
  1787. void
  1788. SetContempt (void)
  1789. {
  1790. X  printz ("contempt= ");
  1791. X  scanz ("%hd", &contempt);
  1792. }
  1793. X
  1794. void
  1795. ChangeXwindow (void)
  1796. {
  1797. X  printz ("xwndw= ");
  1798. X  scanz ("%hd", &xwndw);
  1799. }
  1800. X
  1801. void
  1802. TestSpeed (void (*f) (short int side, short int ply))
  1803. {
  1804. X  short i;
  1805. X  long cnt, rate, t1, t2;
  1806. X
  1807. X  t1 = time (0);
  1808. X  for (i = 0; i < 10000; i++)
  1809. X    {
  1810. X      f (opponent, 2);
  1811. X    }
  1812. X  t2 = time (0);
  1813. X  cnt = 10000L * (TrPnt[3] - TrPnt[2]);
  1814. X  rate = cnt / (t2 - t1);
  1815. X  printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);
  1816. }
  1817. X
  1818. X
  1819. void
  1820. InputCommand (void)
  1821. /*
  1822. X   Process the users command. If easy mode is OFF (the computer is thinking
  1823. X   on opponents time) and the program is out of book, then make the 'hint'
  1824. X   move on the board and call SelectMove() to find a response. The user
  1825. X   terminates the search by entering ^C (quit siqnal) before entering a
  1826. X   command. If the opponent does not make the hint move, then set Sdepth to
  1827. X   zero.
  1828. */
  1829. X
  1830. {
  1831. X  int i;
  1832. X  short ok, tmp;
  1833. X  unsigned short mv;
  1834. X  char s[80];
  1835. X
  1836. #ifdef DEBUG
  1837. X  debugfd = fopen ("/tmp/DEBUG", "w");
  1838. #endif /*DEBUG*/
  1839. X  ok = flag.quit = false;
  1840. X  player = opponent;
  1841. X  ft = 0;
  1842. X  if (hint > 0 && !flag.easy && Book == NULL)
  1843. X    {
  1844. X      fflush (stdout);
  1845. X      time0 = time ((long *) 0);
  1846. X      algbr ((short) hint >> 8, (short) hint & 0xFF, false);
  1847. X      strcpy (s, mvstr[0]);
  1848. X      tmp = epsquare;
  1849. X      if (flag.post)
  1850. X    GiveHint ();
  1851. X      if (VerifyMove (s, 1, &mv))
  1852. X    {
  1853. X      ahead = 1;
  1854. X      SelectMove (computer, 2);
  1855. X      VerifyMove (mvstr[0], 2, &mv);
  1856. X      if (Sdepth > 0)
  1857. X        Sdepth--;
  1858. X    }
  1859. X      ft = time ((long *) 0) - time0;
  1860. X      epsquare = tmp;
  1861. X    }
  1862. X  ahead = 0;
  1863. X  while (!(ok || flag.quit))
  1864. X    {
  1865. X      PromptForMove ();
  1866. X      i = scanz ("%s", s);
  1867. X      if (i == EOF || s[0] == 0)
  1868. X    ExitChess ();
  1869. X      player = opponent;
  1870. X      if (strcmp (s, "bd") == 0)
  1871. X    {
  1872. #ifdef CHESSTOOL
  1873. X      chesstool = 0;
  1874. #endif /*CHESSTOOL*/
  1875. X      ClrScreen ();
  1876. X      UpdateDisplay (0, 0, 1, 0);
  1877. #ifdef CHESSTOOL
  1878. X      chesstool = 1;
  1879. #endif /*CHESSTOOL*/
  1880. X    }
  1881. X      else if (strcmp (s, "alg") == 0) /* noop */ ;
  1882. X      else if ((strcmp (s, "quit") == 0) || (strcmp (s, "exit") == 0))
  1883. X    flag.quit = true;
  1884. X      else if (strcmp (s, "post") == 0)
  1885. X    flag.post = !flag.post;
  1886. X      else if ((strcmp (s, "set") == 0) || (strcmp (s, "edit") == 0))
  1887. X    EditBoard ();
  1888. X      else if (strcmp (s, "setup") == 0)
  1889. X    SetupBoard ();
  1890. X      else if (strcmp (s, "first") == 0)
  1891. X    ok = true;
  1892. X      else if (strcmp (s, "go") == 0)
  1893. X    ok = true;
  1894. X      else if (strcmp (s, "help") == 0)
  1895. X    help ();
  1896. X      else if (strcmp (s, "force") == 0)
  1897. X    flag.force = !flag.force;
  1898. X      else if (strcmp (s, "book") == 0)
  1899. X    Book = NULL;
  1900. X      else if (strcmp (s, "new") == 0)
  1901. X    NewGame ();
  1902. X      else if (strcmp (s, "list") == 0)
  1903. X    ListGame ();
  1904. X      else if (strcmp (s, "level") == 0 || strcmp (s, "clock") == 0)
  1905. X    SelectLevel ();
  1906. X      else if (strcmp (s, "hash") == 0)
  1907. X    flag.hash = !flag.hash;
  1908. X      else if (strcmp (s, "beep") == 0)
  1909. X    flag.beep = !flag.beep;
  1910. X      else if (strcmp (s, "Awindow") == 0)
  1911. X    ChangeAlphaWindow ();
  1912. X      else if (strcmp (s, "Bwindow") == 0)
  1913. X    ChangeBetaWindow ();
  1914. X      else if (strcmp (s, "rcptr") == 0)
  1915. X    flag.rcptr = !flag.rcptr;
  1916. X      else if (strcmp (s, "hint") == 0)
  1917. X    GiveHint ();
  1918. X      else if (strcmp (s, "both") == 0)
  1919. X    {
  1920. X      flag.bothsides = !flag.bothsides;
  1921. X      Sdepth = 0;
  1922. X      ElapsedTime (1);
  1923. X      SelectMove (opponent, 1);
  1924. X      ok = true;
  1925. X    }
  1926. X      else if (strcmp (s, "reverse") == 0)
  1927. X    {
  1928. X      flag.reverse = !flag.reverse;
  1929. X      ClrScreen ();
  1930. X      UpdateDisplay (0, 0, 1, 0);
  1931. X    }
  1932. X      else if (strcmp (s, "switch") == 0)
  1933. X    {
  1934. X      computer = otherside[computer];
  1935. X      opponent = otherside[opponent];
  1936. X      flag.force = false;
  1937. X      Sdepth = 0;
  1938. X      ok = true;
  1939. X    }
  1940. X      else if (strcmp (s, "white") == 0)
  1941. X    {
  1942. X      computer = white;
  1943. X      opponent = black;
  1944. X      flag.force = false;
  1945. X      Sdepth = 0;
  1946. X      /* ok = true;/* don't automatically start with white command */
  1947. X    }
  1948. X      else if (strcmp (s, "black") == 0)
  1949. X    {
  1950. X      computer = black;
  1951. X      opponent = white;
  1952. X      flag.force = false;
  1953. X      Sdepth = 0;
  1954. X      /* ok = true;/* don't automatically start with black command */
  1955. X    }
  1956. X      else if (strcmp (s, "undo") == 0 && GameCnt > 0)
  1957. X    Undo ();
  1958. X      else if (strcmp (s, "remove") == 0 && GameCnt > 1)
  1959. X    {
  1960. X      Undo ();
  1961. X      Undo ();
  1962. X    }
  1963. X      else if (strcmp (s, "get") == 0)
  1964. X    GetGame ();
  1965. X      else if (strcmp (s, "xget") == 0)
  1966. X    GetXGame ();
  1967. X      else if (strcmp (s, "save") == 0)
  1968. X    SaveGame ();
  1969. X      else if (strcmp (s, "depth") == 0)
  1970. X    ChangeSearchDepth ();
  1971. #ifdef DEBUG
  1972. X      else if (strcmp (s, "debuglevel") == 0)
  1973. X    ChangeDbLev ();
  1974. #endif /*DEBUG*/
  1975. X      else if (strcmp (s, "hashdepth") == 0)
  1976. X    ChangeHashDepth ();
  1977. X      else if (strcmp (s, "random") == 0)
  1978. X    dither = 6;
  1979. X      else if (strcmp (s, "easy") == 0)
  1980. X    flag.easy = !flag.easy;
  1981. X      else if (strcmp (s, "contempt") == 0)
  1982. X    SetContempt ();
  1983. X      else if (strcmp (s, "xwndw") == 0)
  1984. X    ChangeXwindow ();
  1985. X      else if (strcmp (s, "test") == 0)
  1986. X    {
  1987. X      ShowMessage ("Testing MoveList Speed");
  1988. X      TestSpeed (MoveList);
  1989. X      ShowMessage ("Testing CaptureList Speed");
  1990. X      TestSpeed (CaptureList);
  1991. X    }
  1992. X      else
  1993. X    {
  1994. X      ok = VerifyMove (s, 0, &mv);
  1995. X      if (ok && mv != hint)
  1996. X        {
  1997. X          Sdepth = 0;
  1998. X          ft = 0;
  1999. X        }
  2000. X    }
  2001. X    }
  2002. X
  2003. X  ElapsedTime (1);
  2004. X  if (flag.force)
  2005. X    {
  2006. X      computer = opponent;
  2007. X      opponent = otherside[computer];
  2008. X    }
  2009. #ifdef CHESSTOOL
  2010. X  printf ("%d. %s", ++mycnt2, s);
  2011. X  if (flag.post)
  2012. X    {
  2013. X      register int i;
  2014. X      printf (" %6d ", MSCORE);
  2015. X      for (i = 1; MV[i] > 0; i++)
  2016. X    {
  2017. X      algbr ((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
  2018. X      printf ("%5s ", mvstr[0]);
  2019. X    }
  2020. X    }
  2021. X  printf ("\n");
  2022. #endif /* CHESSTOOL */
  2023. X  signal (SIGINT, TerminateSearch);
  2024. #ifndef MSDOS
  2025. X  signal (SIGQUIT, TerminateSearch);
  2026. #endif /* MSDOS */
  2027. }
  2028. SHAR_EOF
  2029. chmod 0664 nondsp.c ||
  2030. echo 'restore of nondsp.c failed'
  2031. Wc_c="`wc -c < 'nondsp.c'`"
  2032. test 30778 -eq "$Wc_c" ||
  2033.     echo 'nondsp.c: original size 30778, current size' "$Wc_c"
  2034. rm -f _shar_wnt_.tmp
  2035. fi
  2036. # ============= nuxdsp.c ==============
  2037. if test -f 'nuxdsp.c' -a X"$1" != X"-c"; then
  2038.     echo 'x - skipping nuxdsp.c (File already exists)'
  2039.     rm -f _shar_wnt_.tmp
  2040. else
  2041. > _shar_wnt_.tmp
  2042. echo 'x - extracting nuxdsp.c (Text)'
  2043. sed 's/^X//' << 'SHAR_EOF' > 'nuxdsp.c' &&
  2044. /* nuxdsp.c - (new)  ALPHA interface for CHESS
  2045. X
  2046. X  Revision: 1991-04-15
  2047. X
  2048. X  Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  2049. X  Copyright (c) 1988, 1989, 1990  John Stanback
  2050. X
  2051. X  Modified extensively Nov 1989 Christopher North-Keys
  2052. SHAR_EOF
  2053. true || echo 'restore of nuxdsp.c failed'
  2054. fi
  2055. echo 'End of  part 5'
  2056. echo 'File nuxdsp.c is continued in part 6'
  2057. echo 6 > _shar_seq_.tmp
  2058. exit 0
  2059. exit 0 # Just in case...
  2060. -- 
  2061. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2062. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2063. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2064. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2065.