home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume13 / gnuchess4 / part06 < prev    next >
Internet Message Format  |  1992-08-03  |  56KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v13i094:  gnuchess4 - GNU Chess 4.0, Part06/12
  5. Message-ID: <3061@master.CNA.TEK.COM>
  6. Date: 19 Jun 92 15:54:22 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 2379
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: cracraft@rice-chex.ai.mit.edu (Stuart Cracraft)
  12. Posting-number: Volume 13, Issue 94
  13. Archive-name: gnuchess4/Part06
  14. Supersedes: gnuchess2: Volume 4, Issue 37-40
  15. Environment: 
  16.  
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 6 (of 12)."
  26. # Contents:  doc/postprint.1 src/checkbook.c src/dspcom.c
  27. # Wrapped by billr@saab on Fri Jun 19 08:36:01 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'doc/postprint.1' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'doc/postprint.1'\"
  31. else
  32. echo shar: Extracting \"'doc/postprint.1'\" \(1093 characters\)
  33. sed "s/^X//" >'doc/postprint.1' <<'END_OF_FILE'
  34. X.TH POSTPRINT GNUCHESS
  35. X.SH NAME
  36. Xpostprint
  37. X.SH SYNOPSIS
  38. X.B postprint
  39. Xfilename
  40. X.SH DESCRIPTION
  41. X.I postprint
  42. Xcreates a board by board postscript output file on stdout of the contents of the 
  43. X.I gnuchess
  44. Xpersistent hashfile.
  45. XThe hashfile contains information from previous games saved by 
  46. X.I gnuchess.
  47. XFor each position it prints the board, the best move for that position
  48. Xand the search depth that generated the move as well as several flags
  49. Xindicating information about the position.
  50. XFlags show whether the score is a true score, or an upper or lower bound on the score
  51. Xand whether or not kingside or queenside castling was legal.
  52. XWhen combined with
  53. X.I ChessFont
  54. Xfile and sent to a postscript printer it will show all boards in the range specified.
  55. XFor each board the move and the current score are also printed.
  56. X.B ChessFont
  57. Xis courtesy of Andy Walker, Maths Dept., Nott'm Univ., UK. (anw@maths.nott.ac.uk) 
  58. Xand is copyrighted by him. 
  59. X
  60. XTo use:
  61. X
  62. X.B    postprint >tmp
  63. X
  64. X.B    cat ChessFont tmp | lpr
  65. X
  66. X.SH "FUNCTION LETTERS"
  67. X.TP
  68. X.SH BUGS
  69. X.PP
  70. X.fi
  71. X.SH SEE ALSO
  72. X.nf
  73. Xgnuchess(6)
  74. Xchesstool(6)
  75. Xxboard(6)
  76. X.fi
  77. X
  78. END_OF_FILE
  79. if test 1093 -ne `wc -c <'doc/postprint.1'`; then
  80.     echo shar: \"'doc/postprint.1'\" unpacked with wrong size!
  81. fi
  82. # end of 'doc/postprint.1'
  83. fi
  84. if test -f 'src/checkbook.c' -a "${1}" != "-c" ; then 
  85.   echo shar: Will not clobber existing file \"'src/checkbook.c'\"
  86. else
  87. echo shar: Extracting \"'src/checkbook.c'\" \(21713 characters\)
  88. sed "s/^X//" >'src/checkbook.c' <<'END_OF_FILE'
  89. X/*
  90. X * checkbook.c - Check a xboard game file or a gnuchess format book for
  91. X * illegal moves. Usage: checkbook [-x] file
  92. X *
  93. X * -x : read xboard game file otherwise read gnuchess book file
  94. X *
  95. X * Limitations: It checks the positions of all pieces of a castling move but
  96. X * does not check that any of the squares crossed is under control of the
  97. X * opponent and does not check that the king or rook have been previously
  98. X * moved. Take it as a TODO.
  99. X *
  100. X * Author M. McGann (mwm@hslrswi.hasler.ascom.ch)
  101. X *
  102. X * Copyright (c) 1992 Free Software Foundation
  103. X *
  104. X * This file is part of GNU CHESS.
  105. X *
  106. X * GNU Chess is free software; you can redistribute it and/or modify
  107. X * it under the terms of the GNU General Public License as published by
  108. X * the Free Software Foundation; either version 2, or (at your option)
  109. X * any later version.
  110. X *
  111. X * GNU Chess is distributed in the hope that it will be useful,
  112. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  113. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  114. X * GNU General Public License for more details.
  115. X *
  116. X * You should have received a copy of the GNU General Public License
  117. X * along with GNU Chess; see the file COPYING.  If not, write to
  118. X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  119. X */
  120. X#include <stdio.h>
  121. X#include "gnuchess.h"
  122. X
  123. X#ifdef MSDOS
  124. X#include <stdlib.h>
  125. X#include <string.h>
  126. X#include <time.h>
  127. X#undef RWA_ACC
  128. X#undef WA_ACC
  129. X#define RWA_ACC "rb"
  130. X#define WA_ACC "w+b"
  131. X#else
  132. X#undef RWA_ACC
  133. X#undef WA_ACC
  134. X#define RWA_ACC "r"
  135. X#define WA_ACC "w+"
  136. X#include <sys/param.h>
  137. X#include <sys/types.h>
  138. X#include <sys/times.h>
  139. X#endif /* MSDOS */
  140. XFILE *fd;
  141. X
  142. X#define truescore 0x0001
  143. X#define lowerbound 0x0002
  144. X#define upperbound 0x0004
  145. X#define kingcastle 0x0008
  146. X#define queencastle 0x0010
  147. Xconst short otherside[3] =
  148. X{black, white, neutral};
  149. X
  150. Xstruct GameRec GameList[512];
  151. Xchar mvstr[4][6];
  152. Xlong i, j;
  153. Xshort int ep;
  154. Xint r, c;
  155. Xchar line[128];
  156. Xchar *l;
  157. Xshort int board[64];
  158. Xshort int color[64];
  159. Xshort int GameCnt;
  160. Xint from, to;
  161. Xchar *InPtr;
  162. Xint ckcastld[2];
  163. Xshort int epsquare = -1;
  164. Xint ok;
  165. Xint mvptr = 0;
  166. Xstruct leaf Tree[256];
  167. Xint endflag;
  168. Xint xflag = false;
  169. Xchar mvflag;
  170. Xchar MOVE[256];
  171. X
  172. X/* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
  173. X
  174. Xconst short kingP[3] =
  175. X{4, 60, 0};
  176. Xconst short Stboard[64] =
  177. X{rook, knight, bishop, queen, king, bishop, knight, rook,
  178. X pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  179. X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  180. X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  181. X pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  182. X rook, knight, bishop, queen, king, bishop, knight, rook};
  183. Xconst short Stcolor[64] =
  184. X{white, white, white, white, white, white, white, white,
  185. X white, white, white, white, white, white, white, white,
  186. X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  187. X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  188. X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  189. X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  190. X black, black, black, black, black, black, black, black,
  191. X black, black, black, black, black, black, black, black};
  192. Xshort board[64], color[64];
  193. X
  194. X/*
  195. X * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
  196. X * positions reachable from from-square in ppos with piece such that the
  197. X * sequence    ppos = nextpos[piece][from-square]; pdir =
  198. X * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
  199. X * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
  200. X * all squares reachable from sq.
  201. X *
  202. X * If the path is blocked u = pdir[sq] will generate the continuation of the
  203. X * sequence in other directions.
  204. X */
  205. X
  206. Xunsigned char nextpos[8][64][64];
  207. Xunsigned char nextdir[8][64][64];
  208. X
  209. X/*
  210. X * ptype is used to separate white and black pawns, like this; ptyp =
  211. X * ptype[side][piece] piece can be used directly in nextpos/nextdir when
  212. X * generating moves for pieces that are not black pawns.
  213. X */
  214. Xconst short ptype[2][8] =
  215. X{
  216. X  no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
  217. X  no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
  218. X
  219. X/* data used to generate nextpos/nextdir */
  220. Xstatic const short direc[8][8] =
  221. X{
  222. X  0, 0, 0, 0, 0, 0, 0, 0,
  223. X  10, 9, 11, 0, 0, 0, 0, 0,
  224. X  8, -8, 12, -12, 19, -19, 21, -21,
  225. X  9, 11, -9, -11, 0, 0, 0, 0,
  226. X  1, 10, -1, -10, 0, 0, 0, 0,
  227. X  1, 10, -1, -10, 9, 11, -9, -11,
  228. X  1, 10, -1, -10, 9, 11, -9, -11,
  229. X  -10, -9, -11, 0, 0, 0, 0, 0};
  230. Xstatic const short max_steps[8] =
  231. X{0, 2, 1, 7, 7, 7, 1, 2};
  232. Xstatic const short nunmap[120] =
  233. X{
  234. X  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  235. X  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  236. X  -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
  237. X  -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
  238. X  -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
  239. X  -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
  240. X  -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
  241. X  -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
  242. X  -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
  243. X  -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
  244. X  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  245. X  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  246. X
  247. Xint InitFlag = false;
  248. X
  249. X
  250. Xvoid
  251. XDISP (void)
  252. X{
  253. X
  254. X  short r, c, l;
  255. X
  256. X  if (true)
  257. X    {
  258. X      printf ("\n");
  259. X      for (r = 7; r >= 0; r--)
  260. X    {
  261. X      printf ("%c ", Rxx[r]);
  262. X      for (c = 0; c <= 7; c++)
  263. X        {
  264. X          l = locn (r, c);
  265. X          if (color[l] == neutral)
  266. X        printf (" -");
  267. X          else if (color[l] == white)
  268. X        printf (" %c", Qxx[board[l]]);
  269. X          else
  270. X        printf (" %c", Pxx[board[l]]);
  271. X        }
  272. X      printf ("\n");
  273. X    }
  274. X      printf ("   a b c d e f g h\n");
  275. X    }
  276. X}
  277. X
  278. Xint
  279. Xcastle (short int side, short int kf, short int kt, short int iop)
  280. X
  281. X/* Make or Unmake a castling move. */
  282. X
  283. X{
  284. X  register short rf, rt, xside;
  285. X
  286. X  xside = otherside[side];
  287. X  if (kt > kf)
  288. X    {
  289. X      rf = kf + 3;
  290. X      rt = kt - 1;
  291. X    }
  292. X  else
  293. X    {
  294. X      rf = kf - 4;
  295. X      rt = kt + 1;
  296. X    }
  297. X  if (kf != kingP[side] ||
  298. X      board[kf] != king ||
  299. X      board[rf] != rook ||
  300. X      color[kt] != neutral ||
  301. X      color[rt] != neutral ||
  302. X      color[kt - 1] != neutral)
  303. X    return (false);
  304. X  else
  305. X    return (true);
  306. X}
  307. X
  308. Xvoid
  309. XInitialize_moves (void)
  310. X
  311. X/*
  312. X * This procedure pre-calculates all moves for every piece from every square.
  313. X * This data is stored in nextpos/nextdir and used later in the move
  314. X * generation routines.
  315. X */
  316. X
  317. X{
  318. X  short ptyp, po, p0, d, di, s, delta;
  319. X  unsigned char *ppos, *pdir;
  320. X  short dest[8][8];
  321. X  short steps[8];
  322. X  short sorted[8];
  323. X
  324. X  for (ptyp = 0; ptyp < 8; ptyp++)
  325. X    for (po = 0; po < 64; po++)
  326. X      for (p0 = 0; p0 < 64; p0++)
  327. X    {
  328. X      nextpos[ptyp][po][p0] = (unsigned char) po;
  329. X      nextdir[ptyp][po][p0] = (unsigned char) po;
  330. X    }
  331. X  for (ptyp = 1; ptyp < 8; ptyp++)
  332. X    for (po = 21; po < 99; po++)
  333. X      if (nunmap[po] >= 0)
  334. X    {
  335. X      ppos = nextpos[ptyp][nunmap[po]];
  336. X      pdir = nextdir[ptyp][nunmap[po]];
  337. X      /* dest is a function of direction and steps */
  338. X      for (d = 0; d < 8; d++)
  339. X        {
  340. X          dest[d][0] = nunmap[po];
  341. X          delta = direc[ptyp][d];
  342. X          if (delta != 0)
  343. X        {
  344. X          p0 = po;
  345. X          for (s = 0; s < max_steps[ptyp]; s++)
  346. X            {
  347. X              p0 = p0 + delta;
  348. X
  349. X              /*
  350. X               * break if (off
  351. X               * board) or (pawns
  352. X               * only move two
  353. X               * steps from home
  354. X               * square)
  355. X               */
  356. X              if ((nunmap[p0] < 0) || (((ptyp == pawn) || (ptyp == bpawn))
  357. X                           && ((s > 0) && ((d > 0) || (Stboard[nunmap[po]] != pawn)))))
  358. X            break;
  359. X              else
  360. X            dest[d][s] = nunmap[p0];
  361. X            }
  362. X        }
  363. X          else
  364. X        s = 0;
  365. X
  366. X          /*
  367. X           * sort dest in number of steps order
  368. X           * currently no sort is done due to
  369. X           * compability with the move
  370. X           * generation order in old gnu chess
  371. X           */
  372. X          steps[d] = s;
  373. X          for (di = d; s > 0 && di > 0; di--)
  374. X        if (steps[sorted[di - 1]] == 0)    /* should be: < s */
  375. X          sorted[di] = sorted[di - 1];
  376. X        else
  377. X          break;
  378. X          sorted[di] = d;
  379. X        }
  380. X
  381. X      /*
  382. X       * update nextpos/nextdir, pawns have two
  383. X       * threads (capture and no capture)
  384. X       */
  385. X      p0 = nunmap[po];
  386. X      if (ptyp == pawn || ptyp == bpawn)
  387. X        {
  388. X          for (s = 0; s < steps[0]; s++)
  389. X        {
  390. X          ppos[p0] = (unsigned char) dest[0][s];
  391. X          p0 = dest[0][s];
  392. X        }
  393. X          p0 = nunmap[po];
  394. X          for (d = 1; d < 3; d++)
  395. X        {
  396. X          pdir[p0] = (unsigned char) dest[d][0];
  397. X          p0 = dest[d][0];
  398. X        }
  399. X        }
  400. X      else
  401. X        {
  402. X          pdir[p0] = (unsigned char) dest[sorted[0]][0];
  403. X          for (d = 0; d < 8; d++)
  404. X        for (s = 0; s < steps[sorted[d]]; s++)
  405. X          {
  406. X            ppos[p0] = (unsigned char) dest[sorted[d]][s];
  407. X            p0 = dest[sorted[d]][s];
  408. X            if (d < 7)
  409. X              pdir[p0] = (unsigned char) dest[sorted[d + 1]][0];
  410. X
  411. X            /*
  412. X             * else is already
  413. X             * initialized
  414. X             */
  415. X          }
  416. X        }
  417. X    }
  418. X}
  419. X
  420. X#define Link(from,to,flag,s) \
  421. X{\
  422. X   node->f = from; node->t = to;\
  423. X     node->reply = 0;\
  424. X       node->flags = flag;\
  425. X     node->score = s;\
  426. X       ++node;\
  427. X         ++mvptr;\
  428. X         }
  429. X
  430. Xinline void
  431. XLinkMove (short int ply,
  432. X      short int f,
  433. X      short int t,
  434. X      short int flag,
  435. X      short int xside)
  436. X
  437. X/*
  438. X * Add a move to the tree.  Assign a bonus to order the moves as follows: 1.
  439. X * Principle variation 2. Capture of last moved piece 3. Other captures
  440. X * (major pieces first) 4. Killer moves 5.
  441. X */
  442. X
  443. X{
  444. X  register short s;
  445. X  register unsigned short mv;
  446. X  register struct leaf *node;
  447. X
  448. X  s = 0;
  449. X  node = &Tree[mvptr];
  450. X  mv = (f << 8) | t;
  451. X  if (row (t) == 0 || row (t) == 7)
  452. X    {
  453. X      flag |= promote;
  454. X      Link (f, t, flag | queen, s - 20000);
  455. X      Link (f, t, flag | knight, s - 20000);
  456. X      Link (f, t, flag | rook, s - 20000);
  457. X      flag |= bishop;
  458. X    }
  459. X  else if (row (t) == 1 || row (t) == 6)
  460. X    {
  461. X      flag |= pwnthrt;
  462. X    }
  463. X  Link (f, t, flag, s - 20000);
  464. X}
  465. X
  466. X
  467. Xvoid
  468. XGenMoves (register short int ply, register short int sq, short int side, short int xside)
  469. X
  470. X/*
  471. X * Generate moves for a piece. The moves are taken from the precalulated
  472. X * array nextpos/nextdir. If the board is free, next move is choosen from
  473. X * nextpos else from nextdir.
  474. X */
  475. X
  476. X{
  477. X  register short u, piece;
  478. X  register unsigned char *ppos, *pdir;
  479. X
  480. X  mvptr = 0;
  481. X  piece = board[sq];
  482. X  ppos = nextpos[ptype[side][piece]][sq];
  483. X  pdir = nextdir[ptype[side][piece]][sq];
  484. X  if (piece == pawn)
  485. X    {
  486. X      u = ppos[sq];        /* follow no captures thread */
  487. X      if (color[u] == neutral)
  488. X    {
  489. X      LinkMove (ply, sq, u, 0, xside);
  490. X      u = ppos[u];
  491. X      if (color[u] == neutral)
  492. X        LinkMove (ply, sq, u, 0, xside);
  493. X    }
  494. X      u = pdir[sq];        /* follow captures thread */
  495. X      if (color[u] == xside)
  496. X    LinkMove (ply, sq, u, capture, xside);
  497. X      else if (u == epsquare)
  498. X    LinkMove (ply, sq, u, capture | epmask, xside);
  499. X      u = pdir[u];
  500. X      if (color[u] == xside)
  501. X    LinkMove (ply, sq, u, capture, xside);
  502. X      else if (u == epsquare)
  503. X    LinkMove (ply, sq, u, capture | epmask, xside);
  504. X
  505. X    }
  506. X  else
  507. X    {
  508. X      u = ppos[sq];
  509. X      do
  510. X    {
  511. X      if (color[u] == neutral)
  512. X        {
  513. X          LinkMove (ply, sq, u, 0, xside);
  514. X          u = ppos[u];
  515. X        }
  516. X      else
  517. X        {
  518. X          if (color[u] == xside)
  519. X        LinkMove (ply, sq, u, capture, xside);
  520. X          u = pdir[u];
  521. X        }
  522. X      } while (u != sq);
  523. X    }
  524. X}
  525. Xvoid
  526. Xskip ()
  527. X{
  528. X  while (*InPtr != ' ' && *InPtr != '\n')
  529. X    InPtr++;
  530. X  while (*InPtr == ' ' && *InPtr != '\n')
  531. X    InPtr++;
  532. X}
  533. Xvoid
  534. Xskipb ()
  535. X{
  536. X  while (*InPtr == ' ')
  537. X    InPtr++;
  538. X}
  539. Xint
  540. Xparser (char *f, int side, short *flags)
  541. X{
  542. X  int c1, r1, c2, r2;
  543. X
  544. X  *flags = 0;
  545. X
  546. X  if (f[4] == 'o')
  547. X    if (side == black)
  548. X      return 0x3C3A;
  549. X    else
  550. X      return 0x0402;
  551. X  else if (f[0] == 'o')
  552. X    if (side == black)
  553. X      return 0x3C3E;
  554. X    else
  555. X      return 0x0406;
  556. X  else
  557. X    {
  558. X      c1 = f[0] - 'a';
  559. X      r1 = f[1] - '1';
  560. X      c2 = f[2] - 'a';
  561. X      r2 = f[3] - '1';
  562. X      if ((f[4] != ' ') && (f[4] != '\n') && f[4] != '?')
  563. X    {
  564. X      /* promotion */
  565. X      for (i = 0; i < sizeof (Qxx); i++)
  566. X        if (f[4] == Qxx[i])
  567. X          {
  568. X        *flags = (i | promote);
  569. X        break;
  570. X          }
  571. X    }
  572. X      return (locn (r1, c1) << 8) | locn (r2, c2);
  573. X    }
  574. X  /*NOTREACHED*/
  575. X}
  576. X
  577. Xvoid
  578. Xalgbr (short int f, short int t, short int flag)
  579. X
  580. X
  581. X/*
  582. X * Generate move strings in different formats.
  583. X */
  584. X
  585. X{
  586. X  int m3p;
  587. X
  588. X  if (f != t)
  589. X    {
  590. X      /* algebraic notation */
  591. X      mvstr[0][0] = Cxx[column (f)];
  592. X      mvstr[0][1] = Rxx[row (f)];
  593. X      mvstr[0][2] = Cxx[column (t)];
  594. X      mvstr[0][3] = Rxx[row (t)];
  595. X      mvstr[0][4] = mvstr[3][0] = '\0';
  596. X      if (((mvstr[1][0] = Pxx[board[f]]) == 'P') || (flag & promote))
  597. X    {
  598. X      if (mvstr[0][0] == mvstr[0][2])    /* pawn did not eat */
  599. X        {
  600. X          mvstr[2][0] = mvstr[1][0] = mvstr[0][2];    /* to column */
  601. X          mvstr[2][1] = mvstr[1][1] = mvstr[0][3];    /* to row */
  602. X          m3p = 2;
  603. X        }
  604. X      else
  605. X        /* pawn ate */
  606. X        {
  607. X          mvstr[2][0] = mvstr[1][0] = mvstr[0][0];    /* column */
  608. X          mvstr[2][1] = mvstr[1][1] = mvstr[0][2];    /* to column */
  609. X          mvstr[2][2] = mvstr[0][3];
  610. X          m3p = 3;        /* to row */
  611. X        }
  612. X      if (flag & promote)
  613. X        {
  614. X          mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = Qxx[flag & pmask];
  615. X          mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[0][5] = '\0';
  616. X#ifdef CHESSTOOL
  617. X          mvstr[3][0] = mvstr[0][0];    /* Allow e7e8 for
  618. X                         * chesstool */
  619. X          mvstr[3][1] = mvstr[0][1];
  620. X          mvstr[3][2] = mvstr[0][2];
  621. X          mvstr[3][3] = mvstr[0][3];
  622. X          mvstr[3][4] = '\0';
  623. X#endif
  624. X        }
  625. X      mvstr[2][m3p] = mvstr[1][2] = '\0';
  626. X    }
  627. X      else
  628. X    /* not a pawn */
  629. X    {
  630. X      mvstr[2][0] = mvstr[1][0];
  631. X      mvstr[2][1] = mvstr[0][1];
  632. X      mvstr[2][2] = mvstr[1][1] = mvstr[0][2];    /* to column */
  633. X      mvstr[2][3] = mvstr[1][2] = mvstr[0][3];    /* to row */
  634. X      mvstr[2][4] = mvstr[1][3] = '\0';
  635. X      strcpy (mvstr[3], mvstr[2]);
  636. X      mvstr[3][1] = mvstr[0][0];
  637. X      if (flag & cstlmask)
  638. X        {
  639. X          if (t > f)
  640. X        {
  641. X          strcpy (mvstr[1], "o-o");
  642. X          strcpy (mvstr[2], "O-O");
  643. X        }
  644. X          else
  645. X        {
  646. X          strcpy (mvstr[1], "o-o-o");
  647. X          strcpy (mvstr[2], "O-O-O");
  648. X        }
  649. X        }
  650. X    }
  651. X    }
  652. X  else
  653. X    mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
  654. X}
  655. Xchar fb[256];
  656. Xint
  657. Xcheckend (char *p)
  658. X{
  659. X  int j, l;
  660. X  char *q;
  661. X  if (xflag)
  662. X    {
  663. X      if (!strcmp (MOVE, "White"))
  664. X    return true;
  665. X      if (!strcmp (MOVE, "Black"))
  666. X    return true;
  667. X      if (!strcmp (MOVE, "draw"))
  668. X    return true;
  669. X    }
  670. X  for (q = MOVE; *p != ' ' && *p != '\t' && *p != '\n'; p++)
  671. X    {
  672. X      *q++ = *p;
  673. X    } *q = '\0';
  674. X  l = strlen (MOVE);
  675. X  if (l == 2)
  676. X    {
  677. X      j = MOVE[1] - 'a';
  678. X      if (j < 0 || j > 8)
  679. X    {
  680. X      printf ("illegal move %s\n", fb);
  681. X      exit (1);
  682. X    }
  683. X      j = MOVE[2] - '0';
  684. X      if (j < 0 || j > 8)
  685. X    {
  686. X      printf ("illegal move %s\n", fb);
  687. X      exit (1);
  688. X    }
  689. X      return false;
  690. X    }
  691. X  else if (l == 3)
  692. X    {
  693. X      if (!strcmp (MOVE, "o-o"))
  694. X    return false;
  695. X      for (j = 0; j < sizeof (Qxx); j++)
  696. X    if (MOVE[0] == Qxx[j])
  697. X      {
  698. X        return false;
  699. X      }
  700. X      j = MOVE[1] - 'a';
  701. X      if (j < 0 || j > 8)
  702. X    {
  703. X      printf ("illegal move %s\n", fb);
  704. X      exit (1);
  705. X    }
  706. X      j = MOVE[2] - '0';
  707. X      if (j < 0 || j > 8)
  708. X    {
  709. X      printf ("illegal move %s\n", fb);
  710. X      exit (1);
  711. X    }
  712. X      return false;
  713. X    }
  714. X  else if (l == 5)
  715. X    {
  716. X      if (!strcmp (MOVE, "o-o-o"))
  717. X    return false;
  718. X    }
  719. X  else if (l != 4)
  720. X    {
  721. X      printf ("illegal move %s\n", fb);
  722. X      exit (1);
  723. X    }
  724. X  /* check for a legal move */
  725. X  j = MOVE[0] - 'a';
  726. X  if (j < 0 || j > 8)
  727. X    {
  728. X      printf ("illegal move %s\n", fb);
  729. X      exit (1);
  730. X    }
  731. X  j = MOVE[1] - '0';
  732. X  if (j < 0 || j > 8)
  733. X    {
  734. X      printf ("illegal move %s\n", fb);
  735. X      exit (1);
  736. X    }
  737. X  j = MOVE[2] - 'a';
  738. X  if (j < 0 || j > 8)
  739. X    {
  740. X      printf ("illegal move %s\n", fb);
  741. X      exit (1);
  742. X    }
  743. X  j = MOVE[3] - '0';
  744. X  if (j < 0 || j > 8)
  745. X    {
  746. X      printf ("illegal move %s\n", fb);
  747. X      exit (1);
  748. X    }
  749. X  if (l == 4)
  750. X    return false;
  751. X  if (MOVE[4] == '?')
  752. X    return false;
  753. X  if (MOVE[4] == 'p')
  754. X    {
  755. X      printf ("illegal promotion??? %s", fb);
  756. X      exit (1);
  757. X    }
  758. X  for (j = 0; j < sizeof (Qxx); j++)
  759. X    if (MOVE[4] == Qxx[j])
  760. X      {
  761. X    return false;
  762. X      }
  763. X  printf ("illegal promotion??? %s", fb);
  764. X  exit (1);
  765. X  return true;
  766. X}
  767. X
  768. Xchar title[256];
  769. Xint firsttime = true;
  770. X
  771. XGetGame ()
  772. X{
  773. X  struct GameRec *g;
  774. X  int side = white;
  775. X
  776. X  if (firsttime)
  777. X    {
  778. X      if (xflag)
  779. X    {
  780. X      fgets (fb, 256, fd);
  781. X      fgets (fb, 256, fd);
  782. X      fgets (fb, 256, fd);
  783. X    }
  784. X      fgets (fb, 256, fd);
  785. X      firsttime = false;
  786. X    }
  787. X  do
  788. X    {
  789. X      if ((fb[0] == '!') || (fb[0] == '#'))
  790. X    {
  791. X      if (!GameCnt)
  792. X        {
  793. X          strcpy (title, fb);
  794. X          continue;
  795. X        }
  796. X      else
  797. X        return 0;
  798. X    }
  799. X      InPtr = fb;
  800. X      skipb ();
  801. X      if (*InPtr == '\n')
  802. X    continue;
  803. X      if (isdigit (*InPtr))
  804. X    {
  805. X      skip ();
  806. X      if (*InPtr == '\n')
  807. X        continue;
  808. X    }
  809. X      if (checkend (InPtr))
  810. X    {
  811. X      if (GameCnt)
  812. X        return 0;
  813. X      else
  814. X        {
  815. X          printf ("No moves???\n");
  816. X          exit (1);
  817. X        }
  818. X    }
  819. X      ++GameCnt;
  820. X      g = &GameList[GameCnt];
  821. X      g->gmove = parser (InPtr, side, &(g->flags));
  822. X      skip ();
  823. X      if (*InPtr == '\n')
  824. X    continue;
  825. X      if (checkend (InPtr))
  826. X    {
  827. X      if (GameCnt)
  828. X        return 0;
  829. X      else
  830. X        {
  831. X          printf ("No moves???\n");
  832. X          exit (1);
  833. X        }
  834. X    }
  835. X      ++GameCnt;
  836. X      side = otherside[side];
  837. X      g = &GameList[GameCnt];
  838. X      g->gmove = parser (InPtr, side, &(g->flags));
  839. X      side = otherside[side];
  840. X
  841. X  } while (fgets (fb, 256, fd) != NULL);
  842. X  return -1;
  843. X}
  844. Xshort int xside, side;
  845. Xint
  846. Xgetboard (int mvno)
  847. X
  848. X{
  849. X  register short int f, t;
  850. X  short int rf, rt;
  851. X  unsigned short mv;
  852. X
  853. X
  854. X  /* now update the board and hash values */
  855. X
  856. X  /*
  857. X   * should really check the moves as we do this, but???
  858. X   */
  859. X  mv = GameList[mvno].gmove;
  860. X  f = mv >> 8 & 0x7F;
  861. X  t = mv & 0xFF;
  862. X  /* can only capture other side */
  863. X  if (board[t] != no_piece)
  864. X    {
  865. X      if (color[t] != xside)
  866. X    {
  867. X      algbr (f, t, 0);
  868. X      printf ("\nIllegal move - %d %s \n", mvno, mvstr);
  869. X    }
  870. X    }
  871. X  /* there must be a piece to move */
  872. X  if (board[f] == no_piece || color[f] != side)
  873. X    {
  874. X      algbr (f, t, 0);
  875. X      printf ("\nIllegal move + %d %s \n", mvno, mvstr);
  876. X    }
  877. X  /* is it EnPassant */
  878. X
  879. X  if (board[f] == pawn && board[t] == no_piece)
  880. X    {
  881. X      if ((row (f) == 3 &&
  882. X       row (t) == 2) || (row (f) == 4 && row (t) == 5))
  883. X    {
  884. X      if (column (t) != column (f))
  885. X        {
  886. X          ep = t + ((t > f) ? -8 : 8);
  887. X          if (board[ep] == pawn && color[ep] == xside)
  888. X        {
  889. X          mvflag = 'e';
  890. X          board[ep] = no_piece;
  891. X          color[ep] = neutral;
  892. X        }
  893. X        }
  894. X    }
  895. X    }
  896. X  board[t] = board[f];
  897. X  color[t] = color[f];
  898. X  color[f] = neutral;
  899. X  board[f] = no_piece;
  900. X  /* castle moves */
  901. X  if ((mv == BLACKCASTLE) || (mv == WHITECASTLE) || (mv == LONGBLACKCASTLE) || (mv == LONGWHITECASTLE))
  902. X    {
  903. X
  904. X      if (t > f)
  905. X    {
  906. X      rf = f + 3;
  907. X      rt = t - 1;
  908. X    }
  909. X      else
  910. X    {
  911. X      rf = f - 4;
  912. X      rt = t + 1;
  913. X    }
  914. X      if ((board[t] == king && color[t] == side) && (board[rf] == rook) && (color[rf] == side))
  915. X    {
  916. X      mvflag = 'c';
  917. X      board[rt] = rook;
  918. X      color[rt] = side;
  919. X      board[rf] = no_piece;
  920. X      color[rf] = neutral;
  921. X      ckcastld[side] = true;
  922. X    }
  923. X    }
  924. X  else if (GameList[i].flags & promote)
  925. X    {
  926. X      board[t] = GameList[i].flags & pmask;
  927. X      color[t] = side;
  928. X    }
  929. X}
  930. X
  931. Xint
  932. Xmain (int argc, char **argv)
  933. X{
  934. X  int from, to;
  935. X  unsigned short int mv;
  936. X  int start, end;
  937. X  int ii, kf, jj;
  938. X  int filearg = 1;
  939. X
  940. X  Initialize_moves ();
  941. X
  942. X  if ((argc < 2) || (argc > 3))
  943. X    {
  944. X      printf ("Usage: checkbook file \n");
  945. X      exit (1);
  946. X    }
  947. X  if (argc == 3)
  948. X    {
  949. X      if (strcmp (argv[1], "-x"))
  950. X    {
  951. X      printf ("illegal flag %s\n", argv[1]);
  952. X      exit (1);
  953. X    }
  954. X      xflag = true;
  955. X      filearg = 2;
  956. X    }
  957. X  if ((fd = fopen (argv[filearg], RWA_ACC)) == NULL)
  958. X    exit (1);
  959. X  endflag = 0;
  960. X  while (true)
  961. X    {
  962. X      if (endflag < 0)
  963. X    exit (0);
  964. X      start = end = 0;
  965. X      ckcastld[0] = ckcastld[1] = false;
  966. X
  967. X      side = white;
  968. X      xside = black;
  969. X      for (i = 0; i < 64; i++)
  970. X    {
  971. X      board[i] = Stboard[i];
  972. X      color[i] = Stcolor[i];
  973. X    }
  974. X      i = 1;
  975. X      GameCnt = 0;
  976. X      while (GameCnt == 0)
  977. X    {
  978. X      if ((endflag = GetGame ()) < 0)
  979. X        if (!GameCnt)
  980. X          exit (0);
  981. X    }
  982. X      printf ("-->%s %d\n", title, GameCnt);
  983. X      start = 1;
  984. X      end = GameCnt + 1;
  985. X      side = white;
  986. X      xside = black;
  987. X      for (i = 1; i < end; i++)
  988. X    {
  989. X      mvflag = ' ';
  990. X      mv = GameList[i].gmove;
  991. X      from = mv >> 8 & 0x7F;
  992. X      to = mv & 0x7F;
  993. X      algbr (from, to, 0);
  994. X
  995. X      GenMoves (0, from, side, xside);
  996. X      if (!ckcastld[side] && board[from] == king && color[from] == side)
  997. X        {
  998. X          if (castle (side, from, from + 2, 0))
  999. X        {
  1000. X          LinkMove (0, from, from + 2, cstlmask, xside);
  1001. X        }
  1002. X          if (castle (side, from, from - 2, 0))
  1003. X        {
  1004. X          LinkMove (0, from, from - 2, cstlmask, xside);
  1005. X        }
  1006. X        }
  1007. X      ok = false;
  1008. X      for (ii = 0; ii < mvptr; ii++)
  1009. X        {
  1010. X          if (from == Tree[ii].f && to == Tree[ii].t)
  1011. X        {
  1012. X          ok = true;
  1013. X          break;
  1014. X        }
  1015. X        }
  1016. X      if (!ok)
  1017. X        {
  1018. X          algbr (from, to, 0);
  1019. X          printf ("\nIllegal move %s\n", mvstr);
  1020. X          for (ii = 0; ii < mvptr; ii++)
  1021. X        {
  1022. X          algbr (Tree[ii].f, Tree[ii].t, 0);
  1023. X          printf (" %s\n", mvstr);
  1024. X        }
  1025. X          DISP ();
  1026. X          exit (1);
  1027. X        }
  1028. X      getboard (i);
  1029. X      if (side)
  1030. X        printf ("%s%c\n", mvstr, mvflag);
  1031. X      else
  1032. X        {
  1033. X          printf ("%d. ", 1 + ((i - 1) / 2));
  1034. X          printf ("%s%c  ", mvstr, mvflag);
  1035. X        }
  1036. X      if (board[to] == pawn)
  1037. X        if (to - from == 16)
  1038. X          epsquare = from + 8;
  1039. X        else if (from - to == 16)
  1040. X          epsquare = from - 8;
  1041. X        else
  1042. X          epsquare = -1;
  1043. X      kf = -1;
  1044. X      for (ii = 0; ii < 64; ii++)
  1045. X        {
  1046. X          if ((board[ii] == king) && (color[ii] == side))
  1047. X        {
  1048. X          kf = ii;
  1049. X          break;
  1050. X        }
  1051. X        }
  1052. X      if (kf < 0)
  1053. X        {
  1054. X          printf ("Badnews: you have no king\n");
  1055. X          DISP ();
  1056. X          exit (1);
  1057. X
  1058. X        }
  1059. X      for (ii = 0; ii < 64; ii++)
  1060. X        {
  1061. X          if (color[ii] == xside)
  1062. X        {
  1063. X          mvptr = 0;
  1064. X          GenMoves (0, ii, xside, side);
  1065. X          for (jj = 0; jj < mvptr; jj++)
  1066. X            {
  1067. X              if (Tree[jj].t == kf)
  1068. X            {
  1069. X
  1070. X              printf ("Badnews: you are in check\n");
  1071. X              printf ("king is at %c%c\n", Cxx[column (kf)], Rxx[row (kf)]);
  1072. X              algbr (Tree[jj].f, Tree[jj].t, 0);
  1073. X              printf ("move is %s\n", mvstr);
  1074. X              DISP ();
  1075. X              exit (1);
  1076. X            }
  1077. X            }
  1078. X        }
  1079. X        }
  1080. X      xside = side;
  1081. X      side = otherside[side];
  1082. X    }
  1083. X      printf ("\n\n");
  1084. X      if (xflag)
  1085. X    {
  1086. X      printf ("Final position:\n\n");
  1087. X      DISP ();
  1088. X      exit (0);
  1089. X    }
  1090. X    }
  1091. X  /*NOTREACHED*/
  1092. X}
  1093. END_OF_FILE
  1094. if test 21713 -ne `wc -c <'src/checkbook.c'`; then
  1095.     echo shar: \"'src/checkbook.c'\" unpacked with wrong size!
  1096. fi
  1097. # end of 'src/checkbook.c'
  1098. fi
  1099. if test -f 'src/dspcom.c' -a "${1}" != "-c" ; then 
  1100.   echo shar: Will not clobber existing file \"'src/dspcom.c'\"
  1101. else
  1102. echo shar: Extracting \"'src/dspcom.c'\" \(28242 characters\)
  1103. sed "s/^X//" >'src/dspcom.c' <<'END_OF_FILE'
  1104. X/*
  1105. X * dspcom.c - C source for GNU CHESS
  1106. X *
  1107. X * Copyright (c) 1988,1989,1990 John Stanback
  1108. X * Copyright (c) 1992 Free Software Foundation
  1109. X *
  1110. X * This file is part of GNU CHESS.
  1111. X *
  1112. X * GNU Chess is free software; you can redistribute it and/or modify
  1113. X * it under the terms of the GNU General Public License as published by
  1114. X * the Free Software Foundation; either version 2, or (at your option)
  1115. X * any later version.
  1116. X *
  1117. X * GNU Chess is distributed in the hope that it will be useful,
  1118. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1119. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1120. X * GNU General Public License for more details.
  1121. X *
  1122. X * You should have received a copy of the GNU General Public License
  1123. X * along with GNU Chess; see the file COPYING.  If not, write to
  1124. X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  1125. X */
  1126. X#include "gnuchess.h"
  1127. X#include "ataks.h"
  1128. Xextern char *version, *patchlevel;
  1129. Xchar mvstr[4][6];
  1130. Xchar *InPtr;
  1131. X
  1132. X
  1133. X#include <ctype.h>
  1134. X#include <signal.h>
  1135. X#ifdef MSDOS
  1136. X#include <dos.h>
  1137. X#include <conio.h>
  1138. X#include <stdlib.h>
  1139. X#include <string.h>
  1140. X#include <time.h>
  1141. X#else
  1142. X#include <sys/param.h>
  1143. X#include <sys/types.h>
  1144. X#include <sys/file.h>
  1145. X#include <sys/ioctl.h>
  1146. X#endif
  1147. X
  1148. Xvoid
  1149. Xalgbr (short int f, short int t, short int flag)
  1150. X
  1151. X
  1152. X/*
  1153. X * Generate move strings in different formats.
  1154. X */
  1155. X
  1156. X{
  1157. X  int m3p;
  1158. X
  1159. X  if (f != t)
  1160. X    {
  1161. X      /* algebraic notation */
  1162. X      mvstr[0][0] = cxx[column (f)];
  1163. X      mvstr[0][1] = rxx[row (f)];
  1164. X      mvstr[0][2] = cxx[column (t)];
  1165. X      mvstr[0][3] = rxx[row (t)];
  1166. X      mvstr[0][4] = mvstr[3][0] = '\0';
  1167. X      if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
  1168. X    {
  1169. X      if (mvstr[0][0] == mvstr[0][2])    /* pawn did not eat */
  1170. X        {
  1171. X          mvstr[2][0] = mvstr[1][0] = mvstr[0][2];    /* to column */
  1172. X          mvstr[2][1] = mvstr[1][1] = mvstr[0][3];    /* to row */
  1173. X          m3p = 2;
  1174. X        }
  1175. X      else
  1176. X        /* pawn ate */
  1177. X        {
  1178. X          mvstr[2][0] = mvstr[1][0] = mvstr[0][0];    /* column */
  1179. X          mvstr[2][1] = mvstr[1][1] = mvstr[0][2];    /* to column */
  1180. X          mvstr[2][2] = mvstr[0][3];
  1181. X          m3p = 3;        /* to row */
  1182. X        }
  1183. X      if (flag & promote)
  1184. X        {
  1185. X          mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
  1186. X          mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
  1187. X#ifdef CHESSTOOL
  1188. X          mvstr[3][0] = mvstr[0][0];    /* Allow e7e8 for chesstool */
  1189. X          mvstr[3][1] = mvstr[0][1];
  1190. X          mvstr[3][2] = mvstr[0][2];
  1191. X          mvstr[3][3] = mvstr[0][3];
  1192. X          mvstr[3][4] = '\0';
  1193. X#endif
  1194. X        }
  1195. X      mvstr[2][m3p] = mvstr[1][2] = '\0';
  1196. X    }
  1197. X      else
  1198. X    /* not a pawn */
  1199. X    {
  1200. X      mvstr[2][0] = mvstr[1][0];
  1201. X      mvstr[2][1] = mvstr[0][1];
  1202. X      mvstr[2][2] = mvstr[1][1] = mvstr[0][2];    /* to column */
  1203. X      mvstr[2][3] = mvstr[1][2] = mvstr[0][3];    /* to row */
  1204. X      mvstr[2][4] = mvstr[1][3] = '\0';
  1205. X      strcpy (mvstr[3], mvstr[2]);
  1206. X      mvstr[3][1] = mvstr[0][0];
  1207. X      if (flag & cstlmask)
  1208. X        {
  1209. X          if (t > f)
  1210. X        {
  1211. X          strcpy (mvstr[1], CP[5]);
  1212. X          strcpy (mvstr[2], CP[7]);
  1213. X        }
  1214. X          else
  1215. X        {
  1216. X          strcpy (mvstr[1], CP[6]);
  1217. X          strcpy (mvstr[2], CP[8]);
  1218. X        }
  1219. X        }
  1220. X    }
  1221. X    }
  1222. X  else
  1223. X    mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
  1224. X}
  1225. X
  1226. X
  1227. Xint
  1228. XVerifyMove (char *s, short int iop, short unsigned int *mv)
  1229. X
  1230. X/*
  1231. X * Compare the string 's' to the list of legal moves available for the
  1232. X * opponent. If a match is found, make the move on the board.
  1233. X */
  1234. X
  1235. X{
  1236. X  static short pnt, tempb, tempc, tempsf, tempst, cnt;
  1237. X  static struct leaf xnode;
  1238. X  struct leaf *node;
  1239. X
  1240. X  *mv = 0;
  1241. X  if (iop == 2)
  1242. X    {
  1243. X      UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  1244. X      return (false);
  1245. X    }
  1246. X  cnt = 0;
  1247. X  MoveList (opponent, 2);
  1248. X  pnt = TrPnt[2];
  1249. X  while (pnt < TrPnt[3])
  1250. X    {
  1251. X      node = &Tree[pnt++];
  1252. X      algbr (node->f, node->t, (short) node->flags);
  1253. X      if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
  1254. X      strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
  1255. X    {
  1256. X      cnt++;
  1257. X      xnode = *node;
  1258. X    }
  1259. X    }
  1260. X  if (cnt == 1)
  1261. X    {
  1262. X      MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
  1263. X      if (SqAtakd (PieceList[opponent][0], computer))
  1264. X    {
  1265. X      UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
  1266. X#if defined CHESSTOOL
  1267. X      printz (CP[15]);
  1268. X#else
  1269. X#ifdef NONDSP
  1270. X/* Illegal move in check */
  1271. X      printz (CP[77]);
  1272. X      printz ("\n");
  1273. X#else
  1274. X/* Illegal move in check */
  1275. X      ShowMessage (CP[77]);
  1276. X#endif
  1277. X#endif /* CHESSTOOL */
  1278. X      return (false);
  1279. X    }
  1280. X      else
  1281. X    {
  1282. X      if (iop == 1)
  1283. X        return (true);
  1284. X      UpdateDisplay (xnode.f, xnode.t, 0, (short) xnode.flags);
  1285. X      if ((board[xnode.t] == pawn)
  1286. X          || (xnode.flags & capture)
  1287. X          || (xnode.flags & cstlmask))
  1288. X        {
  1289. X          Game50 = GameCnt;
  1290. X          ZeroRPT ();
  1291. X        }
  1292. X      GameList[GameCnt].depth = GameList[GameCnt].score = 0;
  1293. X      GameList[GameCnt].nodes = 0;
  1294. X      ElapsedTime (1);
  1295. X      GameList[GameCnt].time = (short) et;
  1296. X      if (TCflag)
  1297. X        {
  1298. X          TimeControl.clock[opponent] -= et;
  1299. X          --TimeControl.moves[opponent];
  1300. X        }
  1301. X      *mv = (xnode.f << 8) | xnode.t;
  1302. X      algbr (xnode.f, xnode.t, false);
  1303. X      return (true);
  1304. X    }
  1305. X    }
  1306. X#if defined CHESSTOOL
  1307. X  printz (CP[78]);
  1308. X#else
  1309. X#ifdef NONDSP
  1310. X/* Illegal move */
  1311. X  printz (CP[75], s);
  1312. X#ifdef DEBUG8
  1313. X  if (1)
  1314. X    {
  1315. X      FILE *D;
  1316. X      int r, c, l;
  1317. X      extern unsigned short int PrVar[];
  1318. X      D = fopen ("/tmp/DEBUG", "a+");
  1319. X      pnt = TrPnt[2];
  1320. X      fprintf (D, "resp = %d\n", ResponseTime);
  1321. X      fprintf (D, "iop = %d\n", iop);
  1322. X      fprintf (D, "matches = %d\n", cnt);
  1323. X      algbr (hint >> 8, hint & 0xff, (short) 0);
  1324. X      fprintf (D, "hint %s\n", mvstr[0]);
  1325. X      fprintf (D, "inout move is %s\n", s);
  1326. X      for (r = 1; PrVar[r]; r++)
  1327. X    {
  1328. X      algbr (PrVar[r] >> 8, PrVar[r] & 0xff, (short) 0);
  1329. X      fprintf (D, " %s", mvstr[0]);
  1330. X    }
  1331. X      fprintf (D, "\n");
  1332. X      fprintf (D, "legal move are \n");
  1333. X      while (pnt < TrPnt[3])
  1334. X    {
  1335. X      node = &Tree[pnt++];
  1336. X      algbr (node->f, node->t, (short) node->flags);
  1337. X      fprintf (D, "%s %s %s %s\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3]);
  1338. X    }
  1339. X      fprintf (D, "\n current board is\n");
  1340. X      for (r = 7; r >= 0; r--)
  1341. X    {
  1342. X      for (c = 0; c <= 7; c++)
  1343. X        {
  1344. X          l = locn (r, c);
  1345. X          if (color[l] == neutral)
  1346. X        fprintf (D, " -");
  1347. X          else if (color[l] == white)
  1348. X        fprintf (D, " %c", qxx[board[l]]);
  1349. X          else
  1350. X        fprintf (D, " %c", pxx[board[l]]);
  1351. X        }
  1352. X      fprintf (D, "\n");
  1353. X    }
  1354. X      fprintf (D, "\n");
  1355. X      fclose (D);
  1356. X      abort ();
  1357. X    }
  1358. X#endif
  1359. X#else
  1360. X/* Illegal move */
  1361. X  ShowMessage (CP[76]);
  1362. X#endif
  1363. X#endif /* CHESSTOOL */
  1364. X#if !defined CHESSTOOL && !defined XBOARD
  1365. X  if (cnt > 1)
  1366. X    ShowMessage (CP[32]);
  1367. X#endif /* CHESSTOOL */
  1368. X  return (false);
  1369. X}
  1370. X
  1371. Xint
  1372. Xparser (char *f, int side)
  1373. X{
  1374. X  int c1, r1, c2, r2;
  1375. X
  1376. X  if (f[4] == 'o')
  1377. X    if (side == black)
  1378. X      return 0x3C3A;
  1379. X    else
  1380. X      return 0x0402;
  1381. X  else if (f[0] == 'o')
  1382. X    if (side == black)
  1383. X      return 0x3C3E;
  1384. X    else
  1385. X      return 0x0406;
  1386. X  else
  1387. X    {
  1388. X      c1 = f[0] - 'a';
  1389. X      r1 = f[1] - '1';
  1390. X      c2 = f[2] - 'a';
  1391. X      r2 = f[3] - '1';
  1392. X      return (locn (r1, c1) << 8) | locn (r2, c2);
  1393. X    }
  1394. X  /*NOTREACHED*/
  1395. X}
  1396. X
  1397. Xvoid
  1398. XGetGame (void)
  1399. X{
  1400. X  FILE *fd;
  1401. X  char fname[256], *p;
  1402. X  int c, i, j;
  1403. X  short sq;
  1404. X/* enter file name */
  1405. X  ShowMessage (CP[63]);
  1406. X  scanz ("%s", fname);
  1407. X/* chess.000 */
  1408. X  if (fname[0] == '\0')
  1409. X    strcpy (fname, CP[137]);
  1410. X  if ((fd = fopen (fname, "r")) != NULL)
  1411. X    {
  1412. X      NewGame ();
  1413. X      fgets (fname, 256, fd);
  1414. X      computer = opponent = white;
  1415. X      InPtr = fname;
  1416. X      skip ();
  1417. X      if (*InPtr == 'c')
  1418. X    computer = black;
  1419. X      else
  1420. X    opponent = black;
  1421. X      skip ();
  1422. X      skip ();
  1423. X      skip ();
  1424. X      Game50 = atoi (InPtr);
  1425. X      fgets (fname, 256, fd);
  1426. X      InPtr = &fname[14];
  1427. X      castld[white] = ((*InPtr == CP[214][0]) ? true : false);
  1428. X      skip ();
  1429. X      skip ();
  1430. X      castld[black] = ((*InPtr == CP[214][0]) ? true : false);
  1431. X      fgets (fname, 256, fd);
  1432. X      InPtr = &fname[11];
  1433. X      skipb ();
  1434. X      TCflag = atoi (InPtr);
  1435. X      skip ();
  1436. X      InPtr += 14;
  1437. X      skipb ();
  1438. X      OperatorTime = atoi (InPtr);
  1439. X      fgets (fname, 256, fd);
  1440. X      InPtr = &fname[11];
  1441. X      skipb ();
  1442. X      TimeControl.clock[white] = atoi (InPtr);
  1443. X      skip ();
  1444. X      skip ();
  1445. X      TimeControl.moves[white] = atoi (InPtr);
  1446. X      fgets (fname, 256, fd);
  1447. X      InPtr = &fname[11];
  1448. X      skipb ();
  1449. X      TimeControl.clock[black] = atoi (InPtr);
  1450. X      skip ();
  1451. X      skip ();
  1452. X      TimeControl.moves[black] = atoi (InPtr);
  1453. X      fgets (fname, 256, fd);
  1454. X      for (i = 7; i > -1; i--)
  1455. X    {
  1456. X      fgets (fname, 256, fd);
  1457. X      p = &fname[2];
  1458. X      InPtr = &fname[11];
  1459. X      skipb ();
  1460. X      for (j = 0; j < 8; j++)
  1461. X        {
  1462. X          sq = i * 8 + j;
  1463. X          if (*p == '.')
  1464. X        {
  1465. X          board[sq] = no_piece;
  1466. X          color[sq] = neutral;
  1467. X        }
  1468. X          else
  1469. X        {
  1470. X          for (c = 0; c < 8; c++)
  1471. X            {
  1472. X              if (*p == pxx[c])
  1473. X            {
  1474. X              board[sq] = c;
  1475. X              color[sq] = black;
  1476. X            }
  1477. X            }
  1478. X          for (c = 0; c < 8; c++)
  1479. X            {
  1480. X              if (*p == qxx[c])
  1481. X            {
  1482. X              board[sq] = c;
  1483. X              color[sq] = white;
  1484. X            }
  1485. X            }
  1486. X        }
  1487. X          p++;
  1488. X          Mvboard[sq] = atoi (InPtr);
  1489. X          skip ();
  1490. X        }
  1491. X    }
  1492. X      GameCnt = 0;
  1493. X      flag.regularstart = true;
  1494. X      Book = BOOKFAIL;
  1495. X      fgets (fname, 256, fd);
  1496. X      fgets (fname, 256, fd);
  1497. X      fgets (fname, 256, fd);
  1498. X      while (fgets (fname, 256, fd))
  1499. X    {
  1500. X      struct GameRec *g;
  1501. X      int side = computer;
  1502. X
  1503. X      side = side ^ 1;
  1504. X      ++GameCnt;
  1505. X      InPtr = fname;
  1506. X      skipb ();
  1507. X      g = &GameList[GameCnt];
  1508. X      g->gmove = parser (InPtr, side);
  1509. X      skip ();
  1510. X      g->score = atoi (InPtr);
  1511. X      skip ();
  1512. X      g->depth = atoi (InPtr);
  1513. X      skip ();
  1514. X      g->nodes = atoi (InPtr);
  1515. X      skip ();
  1516. X      g->time = atoi (InPtr);
  1517. X      skip ();
  1518. X      g->flags = c = atoi (InPtr);
  1519. X      skip ();
  1520. X      g->hashkey = strtol (InPtr, (char **) NULL, 16);
  1521. X      skip ();
  1522. X      g->hashbd = strtol (InPtr, (char **) NULL, 16);
  1523. X      g->piece = no_piece;
  1524. X      g->color = neutral;
  1525. X      if (c & (capture | cstlmask))
  1526. X        {
  1527. X          if (c & capture)
  1528. X        {
  1529. X          skip ();
  1530. X          for (c = 0; c < 8; c++)
  1531. X            if (pxx[c] == *InPtr)
  1532. X              break;
  1533. X          g->piece = c;
  1534. X        }
  1535. X          skip ();
  1536. X          g->color = ((*InPtr == CP[119][0]) ? black : white);
  1537. X        }
  1538. X    }
  1539. X      /* GameCnt--; */
  1540. X      if (TimeControl.clock[white] > 0)
  1541. X    TCflag = true;
  1542. X      fclose (fd);
  1543. X    }
  1544. X  ZeroRPT ();
  1545. X  InitializeStats ();
  1546. X  UpdateDisplay (0, 0, 1, 0);
  1547. X  Sdepth = 0;
  1548. X  hint = 0;
  1549. X}
  1550. X
  1551. Xvoid
  1552. XGetXGame (void)
  1553. X{
  1554. X  FILE *fd;
  1555. X  char fname[256], *p;
  1556. X  int c, i, j;
  1557. X  short sq;
  1558. X/* Enter file name */
  1559. X  ShowMessage (CP[63]);
  1560. X  scanz ("%s", fname);
  1561. X  if (fname[0] == '\0')
  1562. X/* xboard.position.read*/
  1563. X    strcpy (fname, CP[205]);
  1564. X  if ((fd = fopen (fname, "r")) != NULL)
  1565. X    {
  1566. X      NewGame ();
  1567. X      flag.regularstart = false;
  1568. X      Book = false;
  1569. X      fgets (fname, 256, fd);
  1570. X      fname[6] = '\0';
  1571. X      if (strcmp (fname, CP[206]))
  1572. X    return;
  1573. X      fgets (fname, 256, fd);
  1574. X      fgets (fname, 256, fd);
  1575. X      for (i = 7; i > -1; i--)
  1576. X    {
  1577. X      fgets (fname, 256, fd);
  1578. X      p = fname;
  1579. X      for (j = 0; j < 8; j++)
  1580. X        {
  1581. X          sq = i * 8 + j;
  1582. X          if (*p == '.')
  1583. X        {
  1584. X          board[sq] = no_piece;
  1585. X          color[sq] = neutral;
  1586. X        }
  1587. X          else
  1588. X        {
  1589. X          for (c = 0; c < 8; c++)
  1590. X            {
  1591. X              if (*p == qxx[c])
  1592. X            {
  1593. X              board[sq] = c;
  1594. X              color[sq] = black;
  1595. X            }
  1596. X            }
  1597. X          for (c = 0; c < 8; c++)
  1598. X            {
  1599. X              if (*p == pxx[c])
  1600. X            {
  1601. X              board[sq] = c;
  1602. X              color[sq] = white;
  1603. X            }
  1604. X            }
  1605. X        }
  1606. X          p += 2;
  1607. X        }
  1608. X    }
  1609. X      fclose (fd);
  1610. X    }
  1611. X  ZeroRPT ();
  1612. X  InitializeStats ();
  1613. X  UpdateDisplay (0, 0, 1, 0);
  1614. X  Sdepth = 0;
  1615. X  hint = 0;
  1616. X}
  1617. X
  1618. Xvoid
  1619. XSaveGame (void)
  1620. X{
  1621. X  FILE *fd;
  1622. X  char fname[256];
  1623. X  short sq, i, c, f, t;
  1624. X  char p;
  1625. X
  1626. X  if (savefile[0])
  1627. X    strcpy (fname, savefile);
  1628. X  else
  1629. X    {
  1630. X/* Enter file name*/
  1631. X      ShowMessage (CP[63]);
  1632. X      scanz ("%s", fname);
  1633. X    }
  1634. X
  1635. X  if (fname[0] == '\0')
  1636. X/* chess.000 */
  1637. X    strcpy (fname, CP[137]);
  1638. X  if ((fd = fopen (fname, "w")) != NULL)
  1639. X    {
  1640. X      char *b, *w;
  1641. X
  1642. X      b = w = CP[74];
  1643. X      if (computer == black)
  1644. X    b = CP[141];
  1645. X      if (computer == white)
  1646. X    w = CP[141];
  1647. X      fprintf (fd, CP[37], b, w, Game50);
  1648. X      fprintf (fd, CP[42], castld[white] ? CP[214] : CP[215], castld[black] ? CP[214] : CP[215]);
  1649. X      fprintf (fd, CP[111], TCflag, OperatorTime);
  1650. X      fprintf (fd, CP[117],
  1651. X           TimeControl.clock[white], TimeControl.moves[white],
  1652. X           TimeControl.clock[black], TimeControl.moves[black]);
  1653. X      for (i = 7; i > -1; i--)
  1654. X    {
  1655. X      fprintf (fd, "%1d ", i + 1);
  1656. X      for (c = 0; c < 8; c++)
  1657. X        {
  1658. X          sq = i * 8 + c;
  1659. X          switch (color[sq])
  1660. X        {
  1661. X        case black:
  1662. X          p = pxx[board[sq]];
  1663. X          break;
  1664. X        case white:
  1665. X          p = qxx[board[sq]];
  1666. X          break;
  1667. X        default:
  1668. X          p = '.';
  1669. X        }
  1670. X          fprintf (fd, "%c", p);
  1671. X        }
  1672. X      for (f = i * 8; f < i * 8 + 8; f++)
  1673. X        fprintf (fd, " %d", Mvboard[f]);
  1674. X      fprintf (fd, "\n");
  1675. X    }
  1676. X      fprintf (fd, "  %s\n", cxx);
  1677. X      fprintf (fd, CP[126]);
  1678. X      for (i = 1; i <= GameCnt; i++)
  1679. X    {
  1680. X      struct GameRec *g = &GameList[i];
  1681. X
  1682. X      f = g->gmove >> 8;
  1683. X      t = (g->gmove & 0xFF);
  1684. X      algbr (f, t, g->flags);
  1685. X      fprintf (fd, "%s %5d %5d %7ld %5d %5d  %#08lx %#08lx  %c   %s\n",
  1686. X           mvstr[0], g->score, g->depth,
  1687. X           g->nodes, g->time, g->flags, g->hashkey, g->hashbd,
  1688. X       pxx[g->piece], ((g->color == 2) ? "     " : ColorStr[g->color]));
  1689. X    }
  1690. X      fclose (fd);
  1691. X/* Game saved */
  1692. X      ShowMessage (CP[70]);
  1693. X    }
  1694. X  else
  1695. X    /*ShowMessage ("Could not open file");*/
  1696. X    ShowMessage (CP[48]);
  1697. X}
  1698. X
  1699. Xvoid
  1700. XListGame (void)
  1701. X{
  1702. X  FILE *fd;
  1703. X  short i, f, t;
  1704. X  long when;
  1705. X  char fname[256], dbuf[256];
  1706. X
  1707. X  if (listfile[0])
  1708. X    strcpy (fname, listfile);
  1709. X  else
  1710. X    {
  1711. X#ifdef MSDOS
  1712. X      sprintf (fname, "chess.lst");
  1713. X#else
  1714. X      time (&when);
  1715. X      strncpy (dbuf, ctime (&when), 20);
  1716. X      dbuf[7] = '\0';
  1717. X      dbuf[10] = '\0';
  1718. X      dbuf[13] = '\0';
  1719. X      dbuf[16] = '\0';
  1720. X      dbuf[19] = '\0';
  1721. X/* use format "CLp16.Jan01-020304B" when patchlevel is 16,
  1722. X   date is Jan 1
  1723. X   time is 02:03:04
  1724. X   program played black */
  1725. X      sprintf (fname, "CLp%s.%s%s-%s%s%s%c", patchlevel, dbuf + 4, dbuf + 8, dbuf + 11, dbuf + 14, dbuf + 17, ColorStr[computer][0]);
  1726. X      /* replace space padding with 0 */
  1727. X      for (i = 0; fname[i] != '\0'; i++)
  1728. X    if (fname[i] == ' ')
  1729. X      fname[i] = '0';
  1730. X#endif /* MSDOS */
  1731. X    }
  1732. X  fd = fopen (fname, "w");
  1733. X  if (!fd)
  1734. X    {
  1735. X      printf (CP[219], fname);
  1736. X      exit (1);
  1737. X    }
  1738. X  /*fprintf (fd, "gnuchess game %d\n", u);*/
  1739. X  fprintf (fd, CP[161], patchlevel);
  1740. X  fprintf (fd, CP[10]);
  1741. X  fprintf (fd, CP[11]);
  1742. X  for (i = 1; i <= GameCnt; i++)
  1743. X    {
  1744. X      f = GameList[i].gmove >> 8;
  1745. X      t = (GameList[i].gmove & 0xFF);
  1746. X      algbr (f, t, GameList[i].flags);
  1747. X      fprintf (fd, "%5s  %5d     %2d %7ld %5d", mvstr[0],
  1748. X           GameList[i].score, GameList[i].depth,
  1749. X           GameList[i].nodes, GameList[i].time);
  1750. X      if ((i % 2) == 0)
  1751. X    {
  1752. X      fprintf (fd, "\n");
  1753. X#ifdef DEBUG40
  1754. X      if (computer == black)
  1755. X        fprintf (fd, " %d %d %d %ld %d %d\n",
  1756. X             GameList[i].d1,
  1757. X             GameList[i].d2,
  1758. X             GameList[i].d3,
  1759. X             GameList[i].d4,
  1760. X             GameList[i].d5,
  1761. X             GameList[i].d6);
  1762. X      else
  1763. X        fprintf (fd, " %d %d %d %ld %d %d\n",
  1764. X             GameList[i - 1].d1,
  1765. X             GameList[i - 1].d2,
  1766. X             GameList[i - 1].d3,
  1767. X             GameList[i - 1].d4,
  1768. X             GameList[i - 1].d5,
  1769. X             GameList[i - 1].d6);
  1770. X#endif
  1771. X    }
  1772. X      else
  1773. X    fprintf (fd, "         ");
  1774. X    }
  1775. X  fprintf (fd, "\n\n");
  1776. X  if (GameList[GameCnt].flags & draw)
  1777. X    {
  1778. X      fprintf (fd, CP[54], DRAW);
  1779. X    }
  1780. X  else if (GameList[GameCnt].score == -9999)
  1781. X    {
  1782. X      fprintf (fd, "%s\n", ColorStr[player ^ 1]);
  1783. X    }
  1784. X  else if (GameList[GameCnt].score == 9998)
  1785. X    {
  1786. X      fprintf (fd, "%s\n", ColorStr[player]);
  1787. X    }
  1788. X  fclose (fd);
  1789. X}
  1790. X
  1791. Xvoid
  1792. XUndo (void)
  1793. X
  1794. X/*
  1795. X * Undo the most recent half-move.
  1796. X */
  1797. X
  1798. X{
  1799. X  short f, t;
  1800. X  f = GameList[GameCnt].gmove >> 8;
  1801. X  t = GameList[GameCnt].gmove & 0xFF;
  1802. X  if (board[t] == king && distance (t, f) > 1)
  1803. X    (void) castle (GameList[GameCnt].color, f, t, 2);
  1804. X  else
  1805. X    {
  1806. X      /* Check for promotion: */
  1807. X      if (GameList[GameCnt].flags & promote)
  1808. X    {
  1809. X      board[t] = pawn;
  1810. X    }
  1811. X      board[f] = board[t];
  1812. X      color[f] = color[t];
  1813. X      board[t] = GameList[GameCnt].piece;
  1814. X      color[t] = GameList[GameCnt].color;
  1815. X      if (color[t] != neutral)
  1816. X    Mvboard[t]--;
  1817. X      Mvboard[f]--;
  1818. X    }
  1819. X  if (GameList[GameCnt].flags & epmask)
  1820. X    EnPassant (otherside[color[f]], f, t, 2);
  1821. X  else
  1822. X    InitializeStats ();
  1823. X  if (TCflag)
  1824. X    ++TimeControl.moves[color[f]];
  1825. X  hashkey = GameList[GameCnt].hashkey;
  1826. X  hashbd = GameList[GameCnt].hashbd;
  1827. X  GameCnt--;
  1828. X  computer = computer ^ 1;
  1829. X  opponent = opponent ^ 1;
  1830. X  flag.mate = false;
  1831. X  Sdepth = 0;
  1832. X  player = player ^ 1;
  1833. X  ShowSidetoMove ();
  1834. X  UpdateDisplay (0, 0, 1, 0);
  1835. X  if (flag.regularstart)
  1836. X    Book = BOOKFAIL;
  1837. X}
  1838. X
  1839. Xvoid
  1840. X TestSpeed (void (*f) (short int side, short int ply), unsigned j)
  1841. X{
  1842. X  short i;
  1843. X  long cnt, rate, t1, t2;
  1844. X
  1845. X  t1 = time (0);
  1846. X  for (i = 0; i < j; i++)
  1847. X    {
  1848. X      f (opponent, 2);
  1849. X    }
  1850. X  t2 = time (0);
  1851. X  cnt = j * (TrPnt[3] - TrPnt[2]);
  1852. X  if (t2 - t1)
  1853. X    et = (t2 - t1) * 100;
  1854. X  else
  1855. X    et = 1;
  1856. X  rate = (et) ? (cnt / et) : 0;
  1857. X  /*printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);*/
  1858. X#ifdef NONDSP
  1859. X  printz (CP[91], cnt, rate);
  1860. X#ifdef DEBUG9
  1861. X  for (j = TrPnt[2]; j < TrPnt[3]; j++)
  1862. X    {
  1863. X      struct leaf *node = &Tree[j];
  1864. X      algbr (node->f, node->t, node->flags);
  1865. X      printf ("%s %s %s %s\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3]);
  1866. X    }
  1867. X#endif
  1868. X#else
  1869. X  ShowNodeCnt (cnt);
  1870. X#endif
  1871. X}
  1872. X
  1873. Xvoid
  1874. X TestPSpeed (void (*f) (short int side), unsigned j)
  1875. X{
  1876. X  short i;
  1877. X  long cnt, rate, t1, t2;
  1878. X  short int t;
  1879. X
  1880. X  t1 = time (0);
  1881. X  for (i = 0; i < j; i++)
  1882. X    {
  1883. X      f (opponent);
  1884. X    }
  1885. X  t2 = time (0);
  1886. X  cnt = j;
  1887. X  if (t2 - t1)
  1888. X    et = (t2 - t1) * 100;
  1889. X  else
  1890. X    et = 1;
  1891. X  rate = (et) ? (cnt / et) : 0;
  1892. X  /*printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);*/
  1893. X#ifdef NONDSP
  1894. X  printz (CP[91], cnt, rate);
  1895. X#else
  1896. X  ShowNodeCnt (cnt);
  1897. X#endif
  1898. X}
  1899. X
  1900. X
  1901. Xvoid
  1902. XSetMachineTime (char *s)
  1903. X{
  1904. X  char *time;
  1905. X  int m, t;
  1906. X  time = &s[strlen (CP[197])];
  1907. X  t = strtol (time, &time, 10);
  1908. X  m = strtol (time, &time, 10);
  1909. X  if (t)
  1910. X    TimeControl.clock[computer] = t;
  1911. X  if (m)
  1912. X    TimeControl.moves[computer] = m;
  1913. X#ifdef XBOARD
  1914. X  printz (CP[222], m, t);
  1915. X#endif
  1916. X}
  1917. X
  1918. X
  1919. Xvoid
  1920. XInputCommand (void)
  1921. X
  1922. X/*
  1923. X * Process the users command. If easy mode is OFF (the computer is thinking
  1924. X * on opponents time) and the program is out of book, then make the 'hint'
  1925. X * move on the board and call SelectMove() to find a response. The user
  1926. X * terminates the search by entering ^C (quit siqnal) before entering a
  1927. X * command. If the opponent does not make the hint move, then set Sdepth to
  1928. X * zero.
  1929. X */
  1930. X
  1931. X{
  1932. X  int i = 0;
  1933. X  short have_shown_prompt = false;
  1934. X  short ok, tmp;
  1935. X  unsigned short mv;
  1936. X  char s[80], sx[80];
  1937. X
  1938. X#if defined CHESSTOOL
  1939. X  short normal = false;
  1940. X
  1941. X#endif
  1942. X
  1943. X  ok = flag.quit = false;
  1944. X  player = opponent;
  1945. X  ft = 0;
  1946. X  if (hint > 0 && !flag.easy && !flag.force)
  1947. X    if ((board[hint >> 8] != pawn) || ((row (hint & 0xFF) != 0) && (row (hint & 0xFF) != 7)))
  1948. X      {
  1949. X    fflush (stdout);
  1950. X    time0 = time ((long *) 0);
  1951. X    algbr ((short) hint >> 8, (short) hint & 0xFF, false);
  1952. X    strcpy (s, mvstr[0]);
  1953. X    tmp = epsquare;
  1954. X#ifdef DEBUG12
  1955. X    if (1)
  1956. X      {
  1957. X        FILE *D;
  1958. X        int r, c, l;
  1959. X        extern unsigned short int PrVar[];
  1960. X        extern struct leaf rootnode;
  1961. X        D = fopen ("/tmp/DEBUGA", "a+");
  1962. X        fprintf (D, "score = %d\n", rootnode.score);
  1963. X        fprintf (D, "inout move is %s\n", s);
  1964. X        for (r = 1; PrVar[r]; r++)
  1965. X          {
  1966. X        algbr (PrVar[r] >> 8, PrVar[r] & 0xff, (short) 0);
  1967. X        fprintf (D, " %s", mvstr[0]);
  1968. X          }
  1969. X        fprintf (D, "\n current board is\n");
  1970. X        for (r = 7; r >= 0; r--)
  1971. X          {
  1972. X        for (c = 0; c <= 7; c++)
  1973. X          {
  1974. X            l = locn (r, c);
  1975. X            if (color[l] == neutral)
  1976. X              fprintf (D, " -");
  1977. X            else if (color[l] == white)
  1978. X              fprintf (D, " %c", qxx[board[l]]);
  1979. X            else
  1980. X              fprintf (D, " %c", pxx[board[l]]);
  1981. X          }
  1982. X        fprintf (D, "\n");
  1983. X          }
  1984. X        fprintf (D, "\n");
  1985. X        fclose (D);
  1986. X      }
  1987. X#endif
  1988. X#if !defined XBOARD && !defined CHESSTOOL
  1989. X    if (flag.post)
  1990. X      GiveHint ();
  1991. X#endif
  1992. X    if (VerifyMove (s, 1, &mv))
  1993. X      {
  1994. X        Sdepth = 0;
  1995. X#ifdef QUIETBACKGROUND
  1996. X#ifdef NONDSP
  1997. X        PromptForMove ();
  1998. X#else
  1999. X        ShowSidetoMove ();
  2000. X        ShowPrompt ();
  2001. X#endif
  2002. X        have_shown_prompt = true;
  2003. X#endif /* QUIETBACKGROUND */
  2004. X        SelectMove (computer, 2);
  2005. X        VerifyMove (s, 2, &mv);
  2006. X        Sdepth = 0;
  2007. X      }
  2008. X    ft = (time ((long *) 0) - time0) * 100;
  2009. X    epsquare = tmp;
  2010. X      }
  2011. X  while (!(ok || flag.quit))
  2012. X    {
  2013. X#if defined CHESSTOOL
  2014. X      normal = false;
  2015. X#endif
  2016. X      player = opponent;
  2017. X#ifdef QUIETBACKGROUND
  2018. X      if (!have_shown_prompt)
  2019. X    {
  2020. X#endif /* QUIETBACKGROUND */
  2021. X#ifdef NONDSP
  2022. X      PromptForMove ();
  2023. X#else
  2024. X      ShowSidetoMove ();
  2025. X      ShowPrompt ();
  2026. X#endif
  2027. X#ifdef QUIETBACKGROUND
  2028. X    }
  2029. X      have_shown_prompt = false;
  2030. X#endif /* QUIETBACKGROUND */
  2031. X#ifdef NONDSP
  2032. X      s[0] = sx[0] = '\0';
  2033. X      while (!sx[0])
  2034. X    i = (int) gets (sx);
  2035. X#else
  2036. X      fflush (stdout);
  2037. X      i = (int) getstr (sx);
  2038. X#endif
  2039. X      sscanf (sx, "%s", s);
  2040. X      if (i == EOF)
  2041. X    ExitChess ();
  2042. X      if (s[0] == '\0')
  2043. X    continue;
  2044. X      if (strcmp (s, CP[131]) == 0)    /*bd*/
  2045. X    {
  2046. X#if defined CHESSTOOL || defined XBOARD
  2047. X      chesstool = 0;
  2048. X#endif /* CHESSTOOL */
  2049. X      ClrScreen ();
  2050. X      UpdateDisplay (0, 0, 1, 0);
  2051. X#if defined CHESSTOOL || defined XBOARD
  2052. X      chesstool = 1;
  2053. X#endif /* CHESSTOOL */
  2054. X    }
  2055. X      else if (strcmp (s, CP[129]) == 0) /* noop */ ;    /*alg*/
  2056. X      else if ((strcmp (s, CP[180]) == 0) || (strcmp (s, CP[216]) == 0))    /* quit exit*/
  2057. X    flag.quit = true;
  2058. X      else if (strcmp (s, CP[178]) == 0)    /*post*/
  2059. X    {
  2060. X      flag.post = !flag.post;
  2061. X    }
  2062. X      else if ((strcmp (s, CP[191]) == 0) || (strcmp (s, CP[154]) == 0))    /*set edit*/
  2063. X    EditBoard ();
  2064. X#ifdef NONDSP
  2065. X      else if (strcmp (s, CP[190]) == 0)    /*setup*/
  2066. X    SetupBoard ();
  2067. X#endif
  2068. X      else if (strcmp (s, CP[156]) == 0)    /*first*/
  2069. X    {
  2070. X#if defined CHESSTOOL
  2071. X      computer = white;
  2072. X      opponent = black;
  2073. X      flag.force = false;
  2074. X      Sdepth = 0;
  2075. X#endif /* CHESSTOOL */
  2076. X      ok = true;
  2077. X    }
  2078. X      else if (strcmp (s, CP[162]) == 0)    /*go*/
  2079. X    {
  2080. X      ok = true;
  2081. X      flag.force = false;
  2082. X      if (computer == white)
  2083. X        {
  2084. X          computer = black;
  2085. X          opponent = white;
  2086. X        }
  2087. X      else
  2088. X        {
  2089. X          computer = white;
  2090. X          opponent = black;
  2091. X        }
  2092. X    }
  2093. X      else if (strcmp (s, CP[166]) == 0)    /*help*/
  2094. X    help ();
  2095. X      else if (strcmp (s, CP[221]) == 0)    /*material*/
  2096. X    flag.material = !flag.material;
  2097. X      else if (strcmp (s, CP[157]) == 0)    /*force*/
  2098. X    flag.force = !flag.force;
  2099. X      else if (strcmp (s, CP[134]) == 0)    /*book*/
  2100. X    Book = Book ? 0 : BOOKFAIL;
  2101. X      else if (strcmp (s, CP[172]) == 0)    /*new*/
  2102. X    {
  2103. X      NewGame ();
  2104. X      UpdateDisplay (0, 0, 1, 0);
  2105. X    }
  2106. X      else if (strcmp (s, CP[171]) == 0)    /*list*/
  2107. X    ListGame ();
  2108. X      else if (strcmp (s, CP[169]) == 0 || strcmp (s, CP[217]) == 0)    /*level clock*/
  2109. X    SelectLevel ();
  2110. X      else if (strcmp (s, CP[165]) == 0)    /*hash*/
  2111. X    flag.hash = !flag.hash;
  2112. X      else if (strcmp (s, CP[132]) == 0)    /*beep*/
  2113. X    flag.beep = !flag.beep;
  2114. X      else if (strcmp (s, CP[197]) == 0)    /*time*/
  2115. X    {
  2116. X      SetMachineTime (sx);
  2117. X    }
  2118. X      else if (strcmp (s, CP[33]) == 0)    /*Awindow*/
  2119. X    ChangeAlphaWindow ();
  2120. X      else if (strcmp (s, CP[39]) == 0)    /*Bwindow*/
  2121. X    ChangeBetaWindow ();
  2122. X      else if (strcmp (s, CP[183]) == 0)    /*rcptr*/
  2123. X    flag.rcptr = !flag.rcptr;
  2124. X      else if (strcmp (s, CP[168]) == 0)    /*hint*/
  2125. X    GiveHint ();
  2126. X      else if (strcmp (s, CP[135]) == 0)    /*both*/
  2127. X    {
  2128. X      flag.bothsides = !flag.bothsides;
  2129. X      Sdepth = 0;
  2130. X      ElapsedTime (1);
  2131. X      SelectMove (opponent, 1);
  2132. X      ok = true;
  2133. X    }
  2134. X      else if (strcmp (s, CP[185]) == 0)    /*reverse*/
  2135. X    {
  2136. X      flag.reverse = !flag.reverse;
  2137. X      ClrScreen ();
  2138. X      UpdateDisplay (0, 0, 1, 0);
  2139. X    }
  2140. X      else if (strcmp (s, CP[195]) == 0)    /*switch*/
  2141. X    {
  2142. X      computer = computer ^ 1;
  2143. X      opponent = opponent ^ 1;
  2144. X      xwndw = (computer == white) ? WXWNDW : BXWNDW;
  2145. X      flag.force = false;
  2146. X      Sdepth = 0;
  2147. X      ok = true;
  2148. X    }
  2149. X      else if (strcmp (s, CP[203]) == 0)    /*white*/
  2150. X    {
  2151. X      computer = black;
  2152. X      opponent = white;
  2153. X      xwndw = WXWNDW;
  2154. X      flag.force = false;
  2155. X      Sdepth = 0;
  2156. X
  2157. X      /*
  2158. X           * ok = true; don't automatically start with white command
  2159. X           */
  2160. X    }
  2161. X      else if (strcmp (s, CP[133]) == 0)    /*black*/
  2162. X    {
  2163. X      computer = white;
  2164. X      opponent = black;
  2165. X      xwndw = BXWNDW;
  2166. X      flag.force = false;
  2167. X      Sdepth = 0;
  2168. X
  2169. X      /*
  2170. X           * ok = true; don't automatically start with black command
  2171. X           */
  2172. X    }
  2173. X      else if (strcmp (s, CP[201]) == 0 && GameCnt > 0)    /*undo*/
  2174. X    {
  2175. X      Undo ();
  2176. X    }
  2177. X      else if (strcmp (s, CP[184]) == 0 && GameCnt > 1)    /*remove*/
  2178. X    {
  2179. X      Undo ();
  2180. X      Undo ();
  2181. X    }
  2182. X      else if (strcmp (s, CP[160]) == 0)    /*get*/
  2183. X    GetGame ();
  2184. X      else if (strcmp (s, CP[207]) == 0)    /*xget*/
  2185. X    GetXGame ();
  2186. X      else if (strcmp (s, CP[189]) == 0)    /*save*/
  2187. X    SaveGame ();
  2188. X      else if (strcmp (s, CP[151]) == 0)    /*depth*/
  2189. X    ChangeSearchDepth ();
  2190. X#ifdef DEBUG
  2191. X      else if (strcmp (s, CP[147]) == 0)    /*debuglevel*/
  2192. X    ChangeDbLev ();
  2193. X#endif /* DEBUG */
  2194. X      else if (strcmp (s, CP[164]) == 0)    /*hashdepth*/
  2195. X    ChangeHashDepth ();
  2196. X      else if (strcmp (s, CP[182]) == 0)    /*random*/
  2197. X    dither = DITHER;
  2198. X      else if (strcmp (s, CP[152]) == 0)    /*easy*/
  2199. X    flag.easy = !flag.easy;
  2200. X      else if (strcmp (s, CP[143]) == 0)    /*contempt*/
  2201. X    SetContempt ();
  2202. X      else if (strcmp (s, CP[209]) == 0)    /*xwndw*/
  2203. X    ChangeXwindow ();
  2204. X      else if (strcmp (s, CP[186]) == 0)    /*rv*/
  2205. X    {
  2206. X      flag.rv = !flag.rv;
  2207. X      UpdateDisplay (0, 0, 1, 0);
  2208. X    }
  2209. X      else if (strcmp (s, CP[145]) == 0)    /*coords*/
  2210. X    {
  2211. X      flag.coords = !flag.coords;
  2212. X      UpdateDisplay (0, 0, 1, 0);
  2213. X    }
  2214. X      else if (strcmp (s, CP[193]) == 0)    /*stras*/
  2215. X    {
  2216. X      flag.stars = !flag.stars;
  2217. X      UpdateDisplay (0, 0, 1, 0);
  2218. X    }
  2219. X      else if (strcmp (s, CP[196]) == 0)    /*test*/
  2220. X    {
  2221. X      ShowMessage (CP[108]);/*test movelist*/
  2222. X      TestSpeed (MoveList, 20000);
  2223. X      ShowMessage (CP[107]);/*test capturelist*/
  2224. X      TestSpeed (CaptureList, 30000);
  2225. X      ShowMessage (CP[107]);/*test capturelist*/
  2226. X      TestPSpeed ((void *) ScorePosition, 15000);
  2227. X    }
  2228. X      else
  2229. X#if !defined NONDSP
  2230. X      if (strcmp (s, CP[179]) == 0)    /*p*/
  2231. X    ShowPostnValues ();
  2232. X      else if (strcmp (s, CP[148]) == 0)    /*debug*/
  2233. X    DoDebug ();
  2234. X      else
  2235. X#endif
  2236. X    {
  2237. X#if defined CHESSTOOL
  2238. X      normal = (ok = VerifyMove (s, 0, &mv));
  2239. X#else
  2240. X      ok = VerifyMove (s, 0, &mv);
  2241. X#endif
  2242. X      if ((ok && mv != hint))
  2243. X        {
  2244. X          Sdepth = 0;
  2245. X          ft = 0;
  2246. X        }
  2247. X      else
  2248. X        Sdepth = 0;
  2249. X    }
  2250. X    }
  2251. X
  2252. X  ElapsedTime (1);
  2253. X  if (flag.force)
  2254. X    {
  2255. X      computer = opponent;
  2256. X      opponent = computer ^ 1;
  2257. X    }
  2258. X#if defined CHESSTOOL || defined XBOARD
  2259. X#if defined CHESSTOOL
  2260. X  if (normal)
  2261. X    if (computer == white)
  2262. X      printz ("%d. %s", ++mycnt2, s);
  2263. X    else
  2264. X      printz ("%d. ... %s", ++mycnt2, s);
  2265. X#else
  2266. X  printz ("%d. %s\n", ++mycnt2, s);
  2267. X#endif
  2268. X#ifdef notdef
  2269. X  if (flag.post)
  2270. X    {
  2271. X      register int i;
  2272. X
  2273. X      printz (" %6d ", MSCORE);
  2274. X      for (i = 1; MV[i] > 0; i++)
  2275. X    {
  2276. X      algbr ((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
  2277. X      printz ("%5s ", mvstr[0]);
  2278. X    }
  2279. X    }
  2280. X  printz ("\n");
  2281. X#endif
  2282. X#endif /* CHESSTOOL */
  2283. X  signal (SIGINT, TerminateSearch);
  2284. X#ifndef MSDOS
  2285. X  signal (SIGQUIT, TerminateSearch);
  2286. X#endif /* MSDOS */
  2287. X}
  2288. X
  2289. Xvoid
  2290. XElapsedTime (short int iop)
  2291. X
  2292. X
  2293. X/*
  2294. X * Determine the time that has passed since the search was started. If the
  2295. X * elapsed time exceeds the target (ResponseTime+ExtraTime) then set timeout
  2296. X * to true which will terminate the search. iop = 0 calculate et bump ETnodes
  2297. X * iop = 1 calculate et set timeout if time exceeded, calculate et
  2298. X */
  2299. X
  2300. X{
  2301. X#ifndef MSDOS
  2302. X  long nchar;
  2303. X  extern int errno;
  2304. X  int i;
  2305. X#ifdef FIONREAD
  2306. X  if (i = ioctl ((int) 0, FIONREAD, &nchar))
  2307. X    {
  2308. X      printf ("ioctl failure is this gcc 2.00? See README %d %d\n", i, errno);
  2309. X      perror ("FIONREAD");
  2310. X      exit ();
  2311. X    }
  2312. X
  2313. X  if (nchar)
  2314. X    {
  2315. X      if (!flag.timeout)
  2316. X    flag.musttimeout = true;
  2317. X      flag.bothsides = false;
  2318. X    }
  2319. X#endif /*FIONREAD*/
  2320. X#else
  2321. X  if (kbhit ())
  2322. X    {
  2323. X      if (!flag.timeout)
  2324. X    flag.musttimeout = true;
  2325. X      flag.bothsides = false;
  2326. X    }
  2327. X#endif /* MSDOS */
  2328. X  et = (time ((long *) 0) - time0) * 100;
  2329. X  ETnodes = NodeCnt + ZNODES;
  2330. X  if (et < 0)
  2331. X    et = 0;
  2332. X  if (iop == 1)
  2333. X    {
  2334. X      if (et > ResponseTime + ExtraTime && Sdepth > MINDEPTH)
  2335. X    flag.timeout = true;
  2336. X      ETnodes = NodeCnt + ZNODES;
  2337. X      time0 = time ((long *) 0);
  2338. X    }
  2339. X#if !defined NONDSP
  2340. X#ifdef QUIETBACKGROUND
  2341. X  if (!background)
  2342. X#endif /* QUIETBACKGROUND */
  2343. X    UpdateClocks ();
  2344. X#endif
  2345. X}
  2346. X
  2347. Xvoid
  2348. XSetTimeControl (void)
  2349. X{
  2350. X  if (TCflag)
  2351. X    {
  2352. X      TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
  2353. X      TimeControl.clock[white] = TimeControl.clock[black] = 6000L * TCminutes + TCseconds * 100;
  2354. X    }
  2355. X  else
  2356. X    {
  2357. X      TimeControl.moves[white] = TimeControl.moves[black] = 0;
  2358. X      TimeControl.clock[white] = TimeControl.clock[black] = 0;
  2359. X      Level = TCminutes;
  2360. X    }
  2361. X  et = 0;
  2362. X  ElapsedTime (1);
  2363. X}
  2364. END_OF_FILE
  2365. if test 28242 -ne `wc -c <'src/dspcom.c'`; then
  2366.     echo shar: \"'src/dspcom.c'\" unpacked with wrong size!
  2367. fi
  2368. # end of 'src/dspcom.c'
  2369. fi
  2370. echo shar: End of archive 6 \(of 12\).
  2371. cp /dev/null ark6isdone
  2372. MISSING=""
  2373. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  2374.     if test ! -f ark${I}isdone ; then
  2375.     MISSING="${MISSING} ${I}"
  2376.     fi
  2377. done
  2378. if test "${MISSING}" = "" ; then
  2379.     echo You have unpacked all 12 archives.
  2380.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2381.     echo Building book file.
  2382.     cat misc/book.xaa misc/book.xab > misc/gnuchess.nunn.book
  2383.     rm misc/book.xaa misc/book.xab
  2384. else
  2385.     echo You still need to unpack the following archives:
  2386.     echo "        " ${MISSING}
  2387. fi
  2388. ##  End of shell archive.
  2389. exit 0
  2390.