home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuch40.zip / gnuchess-4.0.pl79 / src / nuxdsp.c < prev    next >
C/C++ Source or Header  |  1999-01-16  |  24KB  |  1,087 lines

  1. /*
  2.  * nuxdsp.c - (new)  ALPHA interface for CHESS
  3.  *
  4.  * Copyright (c) 1985-1996 Stuart Cracraft, John Stanback,
  5.  *                         Daryl Baker, Conor McCarthy,
  6.  *                         Mike McGann, Chua Kong Sian
  7.  * Copyright (c) 1985-1996 Free Software Foundation
  8.  *
  9.  * This file is part of GNU CHESS.
  10.  *
  11.  * GNU Chess is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  *
  16.  * GNU Chess is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GNU Chess; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25. #include <ctype.h>
  26. #include <signal.h>
  27. #ifdef MSDOS
  28. #include <dos.h>
  29. /*#include <conio.h>*/
  30. #include <stdlib.h>
  31. #include <string.h>
  32.  
  33. #define ESC 0x1B
  34. #define refresh() fflush(stdout)
  35.  
  36.  
  37. #else
  38. #include <sys/param.h>
  39. #include <sys/types.h>
  40. #include <sys/file.h>
  41. #ifdef __EMX__
  42. #undef HZ
  43. #endif
  44. #ifdef DOSLIKE_ANSI_DISPLAY
  45. #define ESC 0x1B
  46. #define refresh() fflush(stdout)
  47. #else
  48. #include <curses.h>
  49. #endif
  50.  
  51. #endif /* MSDOS */
  52.  
  53. #include "gnuchess.h"
  54. static void param (SHORT n);
  55. int mycnt1, mycnt2;
  56. extern tshort sscore[];
  57.  
  58. extern SHORT pscore[2];
  59.  
  60. #define TAB (43)
  61. /* coordinates within a square for the following are ([1,5],[1,3]) */
  62. #define SQW (5)
  63. #define SQH (3)
  64. #define VIR_C(s)  ((flag.reverse) ? 7-column(s) : column(s))
  65. #define VIR_R(s)  ((flag.reverse) ? 7-row(s) : row(s))
  66. #define VSQ_X(x)  ((flag.reverse) ? SQW + 1 - (x) : (x))
  67. #define VSQ_Y(y)  ((flag.reverse) ? SQH + 1 - (y) : (y))
  68. #define Vblack(s) (!((VIR_C(s) + VIR_R(s)) % 2))
  69. /* Squares swapped */
  70. #define Vcoord(s,x,y) \
  71.     ((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(y))
  72. /* Squares and internal locations swapped */
  73. #define VcoordI(s,x,y) \
  74.     ((SQW)*(VIR_C(s)))+(VSQ_X(x)),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
  75. /* Squares and internal rows swapped */
  76. #define VcoordR(s,x,y) \
  77.     ((SQW)*(VIR_C(s)))+(x),((SQH)*(7-VIR_R(s))+(VSQ_Y(y)))
  78. CHAR Analysis[128] = "";
  79. UTSHORT MV[MAXDEPTH+1];
  80. int MSCORE;
  81. CHAR *DRAW;
  82. extern SHORT Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
  83. SHORT PositionFlag = 0;
  84.  
  85. #if (defined(MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)) && !defined(SEVENBIT)
  86. static void ONormal (void);
  87. static void OReverse (void);
  88.  
  89. #endif /* MSDOS && !SEVENBIT */
  90.  
  91. /* extern CHAR *getenv (const CHAR *);*/
  92. void TerminateSearch (int), Die (int);
  93.  
  94. void
  95. Initialize (void)
  96. {
  97.   signal (SIGINT, Die);
  98. #if !defined (MSDOS) && !defined (DOSLIKE_ANSI_DISPLAY)
  99.   signal (SIGQUIT, Die);
  100.   initscr ();
  101.   crmode ();
  102.   echo ();
  103. #else
  104.   mycnt1 = mycnt2 = 0;
  105. #endif /* MSDOS */
  106. }
  107.  
  108. void
  109. ExitChess (void)
  110. {
  111.   ListGame ();
  112.   gotoXY (1, 24);
  113. #if !defined (MSDOS) && !defined (DOSLIKE_ANSI_DISPLAY)
  114.   refresh();
  115.   nocrmode ();
  116.   endwin ();
  117. #endif /* MSDOS */
  118.   exit (0);
  119. }
  120.  
  121. void
  122. Die (int Sig)
  123. {
  124.   CHAR s[80];
  125.  
  126.   signal (SIGINT, SIG_IGN);
  127. #ifdef MSDOS
  128.   Sig++;            /* shut up the compiler */
  129. #else
  130.   signal (SIGQUIT, SIG_IGN);
  131. #endif /* MSDOS */
  132.   ShowMessage (CP[31]);        /*Abort?*/
  133.   scanz ("%s", s);
  134.   if (strcmp (s, CP[210]) == 0)    /*yes*/
  135.     ExitChess ();
  136.   signal (SIGINT, Die);
  137. #ifndef MSDOS
  138.   signal (SIGQUIT, Die);
  139. #endif /* MSDOS */
  140. }
  141.  
  142. void
  143. TerminateSearch (int Sig)
  144. {
  145.   signal (SIGINT, SIG_IGN);
  146. #ifdef MSDOS
  147.   Sig++;            /* shut up the compiler */
  148. #else
  149.   signal (SIGQUIT, SIG_IGN);
  150. #endif /* MSDOS */
  151.   if (!flag.timeout)
  152.     flag.musttimeout = true;
  153.   flag.bothsides = false;
  154.   signal (SIGINT, Die);
  155. #ifndef MSDOS
  156.   signal (SIGQUIT, Die);
  157. #endif /* MSDOS */
  158. }
  159. void
  160. ShowLine (UTSHORT *bstline)
  161. {
  162. }
  163.  
  164. void
  165. help (void)
  166. {
  167.   ClrScreen ();
  168.   /*printz ("CHESS command summary\n");*/
  169.   printz (CP[40]);
  170.   printz ("----------------------------------------------------------------\n");
  171.   /*printz ("g1f3      move from g1 to f3      quit      Exit Chess\n");*/
  172.   printz (CP[158]);
  173. #ifdef DEBUG
  174.   /*printz ("Nf3       move knight to f3       cache      turn %s\n", (flag.cache) ? "off" : "on");*/
  175.   printz (CP[86], (!flag.nocache) ? CP[92] : CP[93]);
  176. #endif
  177.   /*printz ("a7a8q     promote pawn to queen\n");*/
  178.   printz (CP[128], (flag.material) ? CP[92] : CP[93]);
  179.   /*printz ("o-o       castle king side        easy      turn %s\n", (flag.easy) ? "off" : "on");*/
  180.   printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
  181.   /*printz ("o-o-o     castle queen side       hash      turn %s\n", (flag.hash) ? "off" : "on");*/
  182.   printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
  183.   /*printz ("bd        redraw board            reverse   board display\n");*/
  184.   printz (CP[130]);
  185.   /*printz ("list      game to chess.lst       book      turn %s used %d of %d\n", (Book) ? "off" : "on", bookcount, booksize);*/
  186.   printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
  187.   /*printz ("undo      undo last ply           remove    take back a move\n");*/
  188.   printz (CP[200]);
  189.   /*printz ("edit      edit board              force     enter game moves\n");*/
  190.   printz (CP[153]);
  191.   /*printz ("switch    sides with computer     both      computer match\n");*/
  192.   printz (CP[194]);
  193.   /*printz ("white     computer plays white    black     computer plays black\n");*/
  194.   printz (CP[202]);
  195.   /*printz ("depth     set search depth        clock     set time control\n");*/
  196.   printz (CP[149]);
  197.   /*printz ("hint      suggest a move         post      turn %s principle variation\n", (flag.post) ? "off" : "on");*/
  198.   printz (CP[177], (flag.post) ? CP[92] : CP[93]);
  199.   /*printz ("save      game to file            get       game from file\n");*/
  200.   printz (CP[188]);
  201.   /*printz ("random    randomize play          new       start new game\n");*/
  202.   printz (CP[181]);
  203.   /*printz ("coords    show coords            rv        reverse video\n");*/
  204.   printz (CP[144]);
  205. #if !defined(MSDOS) || defined(SEVENBIT)
  206.   printz (CP[192]);
  207. #endif /* !MSDOS || SEVENBIT */
  208.   gotoXY (10, 20);
  209.   printz (CP[47], ColorStr[computer]);
  210.   gotoXY (10, 21);
  211.   printz (CP[97], ColorStr[opponent]);
  212.   gotoXY (10, 22);
  213.   printz (CP[79], MaxResponseTime/100);
  214.   gotoXY (10, 23);
  215.   printz (CP[59], (flag.easy) ? CP[93] : CP[92]);
  216.   gotoXY (40, 20);
  217.   printz (CP[52], MaxSearchDepth);
  218.   gotoXY (40, 21);
  219.   printz (CP[100], (dither) ? CP[93] : CP[92]);
  220.   gotoXY (40, 22);
  221.   printz (CP[112], (flag.hash) ? CP[93] : CP[92]);
  222.   gotoXY (40, 23);
  223.   printz (CP[73]);
  224.   gotoXY (10, 24);
  225. if(flag.gamein)
  226.   printz (CP[230], (TCflag) ? CP[93] : CP[92],
  227.            TimeControl.clock[white] / 100, TCadd/100, MaxSearchDepth);
  228. else
  229.   printz (CP[110], (TCflag) ? CP[93] : CP[92],
  230.           TimeControl.moves[white], TimeControl.clock[white] / 100, TCadd/100, MaxSearchDepth);
  231.   refresh ();
  232. #ifdef BOGUS
  233.   fflush (stdin); /*what is this supposed to do??*/
  234. #endif /*BOGUS*/
  235.   getchar ();
  236.   ClrScreen ();
  237.   UpdateDisplay (0, 0, 1, 0);
  238. }
  239.  
  240. void
  241. EditBoard (void)
  242.  
  243. /*
  244.  * Set up a board position. Pieces are entered by typing the piece followed
  245.  * by the location. For example, Nf3 will place a knight on square f3.
  246.  */
  247.  
  248. {
  249.   SHORT a, r, c, sq, i;
  250.   CHAR s[80];
  251.  
  252.   flag.regularstart = true;
  253.   Book = BOOKFAIL;
  254.   ClrScreen ();
  255.   UpdateDisplay (0, 0, 1, 0);
  256.   gotoXY (TAB, 3);
  257.   printz (CP[29]);
  258.   gotoXY (TAB, 4);
  259.   printz (CP[28]);
  260.   gotoXY (TAB, 5);
  261.   printz (CP[136]);
  262.   gotoXY (TAB, 7);
  263.   printz (CP[64]);
  264.   a = white;
  265.   do
  266.     {
  267.       gotoXY (TAB, 6);
  268.       printz (CP[60], ColorStr[a]);    /*Editing %s*/
  269.       gotoXY (TAB + 24, 7);
  270.       ClrEoln ();
  271.       scanz ("%s", s);
  272.       if (s[0] == CP[28][0])    /*#*/
  273.     {
  274.       for (sq = 0; sq < 64; sq++)
  275.         {
  276.           board[sq] = no_piece;
  277.           color[sq] = neutral;
  278.           DrawPiece (sq);
  279.         }
  280.     }
  281.       if (s[0] == CP[136][0])    /*c*/
  282.     a = otherside[a];
  283.       c = s[1] - 'a';
  284.       r = s[2] - '1';
  285.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  286.     {
  287.       sq = locn (r, c);
  288.       for (i = king; i > no_piece; i--)
  289.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  290.           break;
  291.       board[sq] = i;
  292.       color[sq] = ((board[sq] == no_piece) ? neutral : a);
  293.       DrawPiece (sq);
  294.     }
  295.   } while (s[0] != CP[29][0]);
  296.  
  297.   for (sq = 0; sq < 64; sq++)
  298.     Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
  299.   GameCnt = 0;
  300.   Game50 = 1;
  301.   ZeroRPT ();
  302.   Sdepth = 0;
  303.   InitializeStats ();
  304.   ClrScreen ();
  305.   UpdateDisplay (0, 0, 1, 0);
  306. }
  307.  
  308. void
  309. ShowPlayers (void)
  310. {
  311.   gotoXY (TAB, ((flag.reverse) ? 23 : 2));
  312.   printz ("%s", (computer == black) ? CP[218] : CP[74]);
  313.   gotoXY (TAB, ((flag.reverse) ? 2 : 23));
  314.   printz ("%s", (computer == white) ? CP[218] : CP[74]);
  315. }
  316.  
  317. void
  318. ShowDepth (CHAR ch)
  319. {
  320.   gotoXY (TAB, 4);
  321.   printz (CP[53], Sdepth, ch);    /*Depth= %d%c*/
  322.   ClrEoln ();
  323. }
  324.  
  325. void
  326. ShowScore (SHORT score)
  327. {
  328.   gotoXY (TAB, 5);
  329.  printz (CP[104], score);
  330.   ClrEoln ();
  331. }
  332.  
  333. void
  334. ShowMessage (CHAR *s)
  335. {
  336.   gotoXY (TAB, 6);
  337.   printz ("%s", s);
  338.   ClrEoln ();
  339. }
  340.  
  341. void
  342. ClearMessage (void)
  343. {
  344.   gotoXY (TAB, 6);
  345.   ClrEoln ();
  346. }
  347.  
  348. void
  349. ShowCurrentMove (SHORT pnt, SHORT f, SHORT t)
  350. {
  351.   algbr (f, t, false);
  352.   gotoXY (TAB, 7);
  353.   printz ("(%2d) %4s", pnt, mvstr[0]);
  354. }
  355.  
  356. void
  357. ShowHeader (void)
  358. {
  359.   gotoXY (TAB, 0);
  360. #if defined MSDOS || defined DOSLIKE_ANSI_DISPLAY
  361.   printz (CP[67]);
  362. #else
  363.   printz (CP[68]);
  364. #endif /* MSDOS */
  365. }
  366.  
  367. void
  368. ShowSidetoMove (void)
  369. {
  370.   gotoXY (TAB, 14);
  371.   printz ("%2d:   %s", 1 + GameCnt / 2, ColorStr[player]);
  372.   ClrEoln ();
  373. }
  374.  
  375. void
  376. ShowPrompt (void)
  377. {
  378.   gotoXY (TAB, 19);
  379.   printz (CP[121]);        /*Your movwe is?*/
  380.   ClrEoln ();
  381. }
  382.  
  383. void
  384. ShowNodeCnt (long int NodeCnt)
  385. {
  386.   gotoXY (TAB, 21);
  387.   printz (CP[90], NodeCnt, (et > 100) ? NodeCnt / (et / 100) : 0);
  388.   ClrEoln ();
  389. }
  390.  
  391. void
  392. ShowResults (SHORT score, UTSHORT *bstline, CHAR ch)
  393. {
  394.   UCHAR d, ply;
  395.  
  396.   if (flag.post)
  397.     {
  398.       ShowDepth (ch);
  399.       ShowScore (score);
  400.       d = 7;
  401.       for (ply = 1; bstline[ply] > 0; ply++)
  402.     {
  403.       if (ply % 4 == 1)
  404.         {
  405.           gotoXY (TAB, ++d);
  406.           ClrEoln ();
  407.         }
  408.       algbr ((SHORT) bstline[ply] >> 8, (SHORT) bstline[ply] & 0xFF, false);
  409.       printz ("%5s ", mvstr[0]);
  410.     }
  411.       ClrEoln ();
  412.       while (d < 13)
  413.     {
  414.       gotoXY (TAB, ++d);
  415.       ClrEoln ();
  416.     }
  417.     }
  418. }
  419.  
  420. void
  421. SearchStartStuff (SHORT side)
  422. {
  423.   SHORT i;
  424.  
  425.   signal (SIGINT, TerminateSearch);
  426. #ifdef MSDOS
  427.   side++;            /* shut up the compiler */
  428. #else
  429.   signal (SIGQUIT, TerminateSearch);
  430. #endif /* MSDOS */
  431.   for (i = 4; i < 14; i++)
  432.     {
  433.       gotoXY (TAB, i);
  434.       ClrEoln ();
  435.     }
  436. }
  437.  
  438. void
  439. OutputMove (SHORT score)
  440. {
  441.  
  442.   UpdateDisplay (root->f, root->t, 0, (SHORT) root->flags);
  443.   gotoXY (TAB, 17);
  444.   if(flag.illegal) {printz (CP[225]); return;}
  445.   printz (CP[84], mvstr[0]);    /*My move is %s*/
  446.   if (flag.beep)
  447.     putchar (7);
  448.   ClrEoln ();
  449.  
  450.   gotoXY (TAB, 24);
  451.   if (root->flags & draw)
  452.     printz (CP[56], DRAW);
  453.   else if (root->score == -9999)
  454.     printz (CP[95]);
  455.   else if (root->score == 9998)
  456.     printz (CP[44]);
  457. #ifdef VERYBUGGY
  458.   else if (root->score < -9000)
  459.     printz (CP[96]);
  460.   else if (root->score > 9000)
  461.     printz (CP[45]);
  462. #endif /*VERYBUGGY*/
  463.   ClrEoln ();
  464.  
  465.   if (flag.post)
  466.     {
  467.       register SHORT h, l, t;
  468.  
  469.       h = TREE;
  470.       l = 0;
  471.       t = TREE >> 1;
  472.       while (l != t)
  473.     {
  474.       if (Tree[t].f || Tree[t].t)
  475.         l = t;
  476.       else
  477.         h = t;
  478.       t = (l + h) >> 1;
  479.     }
  480.  
  481.  
  482.       ShowNodeCnt (NodeCnt);
  483.       gotoXY (TAB, 22);
  484.  
  485.       printz (CP[81], t);    /*Max Tree= %d*/
  486.       ClrEoln ();
  487.     }
  488. }
  489.  
  490. void
  491. UpdateClocks (void)
  492. {
  493.   SHORT m, s;
  494.  
  495.   m = (SHORT) (et / 6000);
  496.   s = (SHORT) (et - 6000 * (long) m) / 100;
  497.   if (TCflag)
  498.     {
  499.       m = (SHORT) ((TimeControl.clock[player] - et) / 6000);
  500.       s = (SHORT) ((TimeControl.clock[player] - et - 6000 * (long) m) / 100);
  501.     }
  502.   if (m < 0)
  503.     m = 0;
  504.   if (s < 0)
  505.     s = 0;
  506.   if (player == white)
  507.     gotoXY (60, (flag.reverse) ? 2 : 23);
  508.   else
  509.     gotoXY (60, (flag.reverse) ? 23 : 2);
  510.   printz ("%d:%02d   ", m, s);
  511.   if (flag.post)
  512.     ShowNodeCnt (NodeCnt);
  513.   refresh ();
  514. }
  515.  
  516. void
  517. gotoXY (SHORT x, SHORT y)
  518. {
  519. #if defined (MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)
  520.   putchar (ESC);
  521.   putchar ('[');
  522.   param (y);
  523.   putchar (';');
  524.   param (x);
  525.   putchar ('H');
  526. #else
  527.   move (y - 1, x - 1);
  528. #endif /* MSDOS */
  529. }
  530.  
  531. void
  532. ClrScreen (void)
  533. {
  534. #if defined (MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)
  535.   putchar (ESC);
  536.   putchar ('[');
  537.   putchar ('2');
  538.   putchar ('J');
  539. #else
  540.   clear ();
  541. #endif /* MSDOS */
  542.   refresh ();
  543. }
  544.  
  545. void
  546. ClrEoln (void)
  547. {
  548. #if defined (MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)
  549.   putchar (ESC);
  550.   putchar ('[');
  551.   putchar ('K');
  552. #else
  553.   clrtoeol ();
  554. #endif /* MSDOS */
  555.   refresh ();
  556. }
  557.  
  558. #if defined (MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)
  559. void
  560. param (SHORT n)
  561. {
  562.   if (n >= 10)
  563.     {
  564.       register SHORT d, q;
  565.  
  566.       q = n / 10;
  567.       d = n % 10;
  568.       putchar (q + '0');
  569.       putchar (d + '0');
  570.     }
  571.   else
  572.     putchar (n + '0');
  573. }
  574.  
  575. #endif /* MSDOS */
  576.  
  577. void
  578. OReverse ()
  579. {
  580. #if defined (MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)
  581.   putchar (ESC);
  582.   putchar ('[');
  583.   param (7);
  584.   putchar ('m');
  585. #else
  586.   standout ();
  587.   /* attron (A_REVERSE); */
  588. #endif /* MSDOS */
  589. }
  590.  
  591. void
  592. ONormal ()
  593. {
  594. #if defined (MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)
  595.   putchar (ESC);
  596.   putchar ('[');
  597.   param (0);
  598.   putchar ('m');
  599. #else
  600.   standend ();
  601.   /* attroff (A_REVERSE); */
  602. #endif /* MSDOS */
  603. }
  604.  
  605. void
  606. DrawPiece (SHORT sq)
  607. {
  608.   gotoXY (VcoordR (sq, 2, 2));
  609.  
  610.   switch (color[sq])
  611.     {
  612.     case black:
  613.       if (flag.rv)
  614.     OReverse ();
  615. #if defined(MSDOS) && !defined(SEVENBIT)
  616.       printz (" %c ", pxx[board[sq]]);
  617. #else
  618.       printz ((flag.stars ? "*%c*" : " %c "), pxx[board[sq]]);
  619. #endif /* MSDOS && !SEVENBIT */
  620.       ONormal ();
  621.       break;
  622.     case neutral:
  623. #if (defined(MSDOS) || defined(DOSLIKE_ANSI_DISPLAY)) && !defined(SEVENBIT)
  624.       if (flag.rv)
  625.     printz (Vblack (sq) ? "\262\262\262" : "\260\260\260");
  626.       else
  627.     printz (Vblack (sq) ? "\260\260\260" : "\262\262\262");
  628. #else
  629.       if (flag.shade)
  630.     printz (Vblack (sq) ? "///" : "   ");
  631.       else
  632.     {
  633.       if (Vblack (sq))
  634.         OReverse ();
  635.       printz ("   ");
  636.       ONormal ();
  637.     }
  638. #endif /* MSDOS && !SEVENBIT */
  639.       break;
  640.     case white:
  641. #if defined(MSDOS) && !defined(SEVENBIT)
  642.       if (!flag.rv)
  643.     OReverse ();
  644.       printz (" %c ", pxx[board[sq]]);
  645.       ONormal ();
  646. #else
  647.       printz (" %c ", pxx[board[sq]]);
  648. #endif /* MSDOS && !SEVENBIT */
  649.       break;
  650.     default:
  651.       ShowMessage (CP[55]);    /*Draw piece color[sq] err*/
  652.       break;
  653.     }
  654. }
  655.  
  656. void
  657. DrawSquare (SHORT sq)
  658. {
  659. #if (defined(MSDOS) || defined(DOSLIKE_ANSI_DISPLAY)) && !defined(SEVENBIT)
  660.   if (flag.rv)
  661.     {
  662.       gotoXY (Vcoord (sq, 1, 1));
  663.       printz (Vblack (sq) ? "\262\262\262\262\262" : "\260\260\260\260\260");
  664.       gotoXY (Vcoord (sq, 1, 2));
  665.       printz (Vblack (sq) ? "\262\262\262\262\262" : "\260\260\260\260\260");
  666.       gotoXY (Vcoord (sq, 1, 3));
  667.       printz (Vblack (sq) ? "\262\262\262\262\262" : "\260\260\260\260\260");
  668.     }
  669.   else
  670.     {
  671.       gotoXY (Vcoord (sq, 1, 1));
  672.       printz (Vblack (sq) ? "\260\260\260\260\260" : "\262\262\262\262\262");
  673.       gotoXY (Vcoord (sq, 1, 2));
  674.       printz (Vblack (sq) ? "\260\260\260\260\260" : "\262\262\262\262\262");
  675.       gotoXY (Vcoord (sq, 1, 3));
  676.       printz (Vblack (sq) ? "\260\260\260\260\260" : "\262\262\262\262\262");
  677.     }
  678. #else
  679.   if (flag.shade)
  680.     {
  681.       gotoXY (Vcoord (sq, 1, 1));
  682.       printz (Vblack (sq) ? "/////" : "     ");
  683.       gotoXY (Vcoord (sq, 1, 2));
  684.       printz (Vblack (sq) ? "/////" : "     ");
  685.       gotoXY (Vcoord (sq, 1, 3));
  686.       printz (Vblack (sq) ? "/////" : "     ");
  687.     }
  688.   else
  689.     {
  690.       if (Vblack (sq))
  691.     OReverse ();
  692.       gotoXY (Vcoord (sq, 1, 1));
  693.       printz ("     ");
  694.       gotoXY (Vcoord (sq, 1, 2));
  695.       printz ("     ");
  696.       gotoXY (Vcoord (sq, 1, 3));
  697.       printz ("     ");
  698.       ONormal ();
  699.     }
  700. #endif /* MSDOS && !SEVENBIT */
  701. }
  702.  
  703. void
  704. DrawCoords (void)
  705. {
  706.   SHORT z;
  707.  
  708.   for (z = 0; z <= 7; z++)
  709.     {
  710.       SHORT sq;
  711.  
  712.       sq = z << 3;
  713.       gotoXY (VcoordI (sq, 1, 1));
  714. #if !defined(MSDOS) || defined(SEVENBIT)
  715.       if ((Vblack (sq) || flag.shade) && flag.rv)
  716. #endif /* !MSDOS || SEVENBIT */
  717.     OReverse ();
  718.       printz ("%d", 1 + z);
  719.       ONormal ();
  720.     }
  721.  
  722.   for (z = 0; z <= 7; z++)
  723.     {
  724.       SHORT sq;
  725.  
  726.       sq = z;
  727.       gotoXY (VcoordI (sq, SQW, SQH));
  728. #if !defined(MSDOS) || defined(SEVENBIT)
  729.       if ((Vblack (sq) || flag.shade) && flag.rv)
  730. #endif /* !MSDOS || SEVENBIT */
  731.     OReverse ();
  732.       printz ("%c", cxx[z]);
  733.       ONormal ();
  734.     }
  735.  
  736. #if !defined(MSDOS) || defined(SEVENBIT)
  737.   for (z = 1; z <= (8 * SQH); z++)
  738.     {
  739.       gotoXY ((8 * SQW) + 1, z);
  740.       printz ("|");
  741.     }
  742. #endif /* MSDOS && !SEVENBIT */
  743. }
  744.  
  745. void
  746. ShowPostnValue (SHORT sq)
  747.  
  748. /*
  749.  * must have called ExaminePosition() first
  750.  */
  751.  
  752. {
  753.   SHORT score;
  754.  
  755.   gotoXY (VcoordR (sq, 2, 1));
  756.   score = ScorePosition (color[sq]);
  757. #if !defined(MSDOS) || defined(SEVENBIT)
  758.   if (Vblack (sq) && !flag.shade)
  759.     OReverse ();
  760. #endif /* !MSDOS || SEVENBIT */
  761.  
  762.   if (color[sq] != neutral)
  763.     printz ("%3d", svalue[sq]);
  764.   else
  765. #if (defined(MSDOS) || defined(DOSLIKE_ANSI_DISPLAY)) && !defined(SEVENBIT)
  766.     {
  767.       if (flag.rv)
  768.     printz (Vblack (sq) ? "\262\262\262" : "\260\260\260");
  769.       else
  770.     printz (Vblack (sq) ? "\260\260\260" : "\262\262\262");
  771.     }
  772. #else
  773.     printz (flag.shade && Vblack (sq) ? "///" : "   ");
  774. #endif /* MSDOS && !SEVENBIT */
  775.   ONormal ();
  776. }
  777.  
  778. void
  779. ShowPostnValues (void)
  780. {
  781.   SHORT sq, score;
  782.  
  783.   ExaminePosition ();
  784.   for (sq = 0; sq < 64; sq++)
  785.     ShowPostnValue (sq);
  786.   score = ScorePosition (opponent);
  787.   gotoXY (TAB, 5);
  788.  printz (CP[103], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  789.   ClrEoln ();
  790. }
  791.  
  792. void
  793. UpdateDisplay (SHORT f, SHORT t, SHORT redraw, SHORT isspec)
  794. {
  795.   SHORT sq;
  796.  
  797.   if (redraw)
  798.     {
  799.       ShowHeader ();
  800.       ShowPlayers ();
  801.       for (sq = 0; sq < 64; sq++)
  802.     {
  803.       DrawSquare (sq);
  804.       DrawPiece (sq);
  805.     }
  806.       if (flag.coords)
  807.     DrawCoords ();
  808.     }
  809.   else
  810.     {
  811.       DrawPiece (f);
  812.       DrawPiece (t);
  813.       if (isspec & cstlmask)
  814.     if (t > f)
  815.       {
  816.         DrawPiece (f + 3);
  817.         DrawPiece (t - 1);
  818.       }
  819.     else
  820.       {
  821.         DrawPiece (f - 4);
  822.         DrawPiece (t + 1);
  823.       }
  824.       else if (isspec & epmask)
  825.     {
  826.       DrawPiece (t - 8);
  827.       DrawPiece (t + 8);
  828.     }
  829.     }
  830.   if (PositionFlag)
  831.     ShowPostnValues ();
  832.   refresh ();
  833. }
  834.  
  835. extern CHAR *InPtr;
  836. void
  837. skip ()
  838. {
  839.   while (*InPtr != ' ')
  840.     InPtr++;
  841.   while (*InPtr == ' ')
  842.     InPtr++;
  843. }
  844. void
  845. skipb ()
  846. {
  847.   while (*InPtr == ' ')
  848.     InPtr++;
  849. }
  850.  
  851. void
  852. ChangeAlphaWindow (void)
  853. {
  854.   ShowMessage (CP[114]);
  855.   scanz ("%hd", &WAwindow);
  856.   ShowMessage (CP[34]);
  857.   scanz ("%hd", &BAwindow);
  858. }
  859.  
  860. void
  861. ChangeBetaWindow (void)
  862. {
  863.   ShowMessage (CP[115]);
  864.   scanz ("%hd", &WBwindow);
  865.   ShowMessage (CP[35]);
  866.   scanz ("%hd", &BBwindow);
  867. }
  868.  
  869. void
  870. GiveHint (void)
  871. {
  872.   CHAR s[40];
  873.   if (hint)
  874.     {
  875.       algbr ((SHORT) (hint >> 8), (SHORT) (hint & 0xFF), false);
  876.       strcpy (s, CP[198]);    /*try*/
  877.       strcat (s, mvstr[0]);
  878.       ShowMessage (s);
  879.     }
  880.   else
  881.     ShowMessage (CP[223]);
  882. }
  883.  
  884. void
  885. ChangeHashDepth (void)
  886. {
  887.   ShowMessage (CP[163]);
  888.   scanz ("%hd", &HashDepth);
  889.   ShowMessage (CP[82]);
  890.   scanz ("%hd", &HashMoveLimit);
  891. }
  892.  
  893. void
  894. ChangeSearchDepth (void)
  895. {
  896.   ShowMessage (CP[150]);
  897.   scanz ("%hd", &MaxSearchDepth);
  898.   TCflag = !(MaxSearchDepth > 0);
  899. }
  900.  
  901. void
  902. SetContempt (void)
  903. {
  904.   ShowMessage (CP[142]);
  905.   scanz ("%hd", &contempt);
  906. }
  907.  
  908.  
  909. void
  910. SetAnalysis (void)
  911. {
  912.   ShowMessage (CP[159]);
  913.   scanz ("%s", Analysis);
  914. }
  915.  
  916. void
  917. ChangeXwindow (void)
  918. {
  919.   ShowMessage (CP[208]);
  920.   scanz ("%hd", &xwndw);
  921. }
  922.  
  923. void
  924. SelectLevel (CHAR *sx)
  925. {
  926.  
  927.   CHAR T[64], *p, *q;
  928.   ClrScreen ();
  929.   XC = XCmore =0;
  930.  
  931.   if ((p = strstr (sx, CP[169])) != NULL) p += strlen (CP[169]);
  932.   else if ((p = strstr (sx, CP[217])) != NULL) p += strlen (CP[217]);
  933.   strcat (sx, "XX");
  934.   q = T;
  935.   *q = '\0';
  936.   for (; *p != 'X'; *q++ = *p++);
  937.   *q = '\0';
  938.   /* line empty ask for input */
  939.   while(true){
  940.   if (!T[0])
  941.     {
  942.       gotoXY(5,2);
  943.       printz(CP[61]);
  944.       refresh();
  945. #if defined (MSDOS) || defined (DOSLIKE_ANSI_DISPLAY)
  946.       T[0] = '\0';
  947.       gets (T);
  948. #else
  949.       getstr (T);
  950. #endif
  951.  
  952.     }
  953.   strcat (T, "XX");
  954.   /* skip whitespace */
  955.   for (p = T; *p == ' '; p++);
  956.   /*
  957.   Input forms are:
  958.              M    m[:s]        - M moves in m:s time
  959.           m[:s]   t    - game in m:s time increment t
  960.           m:[s]        - game in m:s time
  961.              M    m[:s]      t    - for M moves m:s time increment t then reset
  962.   */
  963.   /* could be moves or a incremental clock */
  964.       TCminutes = TCmoves = TCseconds =  TCadd = 0;
  965.       TCmoves = (SHORT) strtol (p, &q, 10);
  966.       if (*q == ':')
  967.     { /* its gamein form: m:s  or m:s t */
  968.       TCminutes = TCmoves;
  969.       TCmoves = 0;
  970.       if(*(q+1) != ' ') TCseconds = (SHORT) strtol (q + 1, &q, 10); else {q++; }
  971.       if(*q != 'X' && *q != '+'){
  972.         TCadd = (SHORT) strtol (q, &q, 10) * 100;
  973.         }
  974.     }
  975.       else
  976.     { /* m or m t or M m t*/
  977.       while (*q == ' ') q++;
  978.       if (*q == 'X' || *q == '+')
  979.         { /*  m only 1 number must be gamein */
  980.           TCminutes = TCmoves;
  981.           TCmoves = 0;
  982.         }
  983.       else
  984.         { /* M m or M m[:s] t */
  985.           TCminutes = (SHORT) strtol (q, &q, 10);
  986.           if (*q == ':')
  987.         { /* M m[:s] t */
  988.               if(*(q+1) != ' ') TCseconds = (SHORT) strtol (q + 1, &q, 10); else {q++; }
  989.           TCadd = (SHORT) strtol (q, &q, 10);
  990.         }else{/* M m or M m t */
  991.           if(*q != 'X' && *q != '+')/* its M m t*/ TCadd = (SHORT) strtol (q, &q, 10)*100;
  992.                  }
  993.          }
  994.     }
  995.     while(*q == ' ')q++;
  996.     XCmoves[XC] = TCmoves;
  997.     XCminutes[XC] = TCminutes;
  998.     XCseconds[XC] = TCseconds;
  999.     XCadd[XC] = TCadd;
  1000.     XC++;
  1001.     if(*q != '+' || XC == 3) break;
  1002.     T[0]='\0';
  1003.     }
  1004.   TimeControl.clock[white] = TimeControl.clock[black] = 0;
  1005.   SetTimeControl ();
  1006.   ClrScreen ();
  1007.   UpdateDisplay (0, 0, 1, 0);
  1008. }
  1009.  
  1010.  
  1011. void
  1012. DoDebug (void)
  1013. {
  1014.   SHORT c, p, sq, tp, tc, tsq, score;
  1015.   CHAR s[40];
  1016.  
  1017.   ExaminePosition ();
  1018.   ShowMessage (CP[65]);
  1019.   scanz ("%s", s);
  1020.   c = neutral;
  1021.   if (s[0] == CP[9][0] || s[0] == CP[9][1])    /* w W*/ c = white;
  1022.   if (s[0] == CP[9][2] || s[0] == CP[9][3])    /*b B*/ c = black;
  1023.   for (p = king; p > no_piece; p--)
  1024.     if ((s[1] == pxx[p]) || (s[1] == qxx[p])) break;
  1025.   if(p > no_piece)
  1026.   for (sq = 0; sq < 64; sq++)
  1027.     {
  1028.       tp = board[sq];
  1029.       tc = color[sq];
  1030.       board[sq] = p;
  1031.       color[sq] = c;
  1032.       tsq = PieceList[c][1];
  1033.       PieceList[c][1] = sq;
  1034.       ShowPostnValue (sq);
  1035.       PieceList[c][1] = tsq;
  1036.       board[sq] = tp;
  1037.       color[sq] = tc;
  1038.     }
  1039.   score = ScorePosition (opponent);
  1040.   gotoXY (TAB, 5);
  1041.   printz (CP[103], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  1042.   ClrEoln ();
  1043. }
  1044. void
  1045. DoTable (SHORT table[64])
  1046. {
  1047.   SHORT  sq;
  1048.   ExaminePosition ();
  1049.   for (sq=0;sq<64;sq++){
  1050.  
  1051.   gotoXY (VcoordR (sq, 2, 1));
  1052. #if !defined(MSDOS) || defined(SEVENBIT)
  1053.   if (Vblack (sq) && !flag.shade)
  1054.     OReverse ();
  1055. #endif /* !MSDOS || SEVENBIT */
  1056.  
  1057.     printz ("%3d", table[sq]);
  1058.   ONormal ();
  1059. }
  1060. }
  1061. SHORT LdisplayLine;
  1062. void Ldisplay1(){LdisplayLine=4; ClrScreen();UpdateDisplay (0, 0, 1, 0); }
  1063.  
  1064. void Ldisplay2(){
  1065.   refresh ();
  1066.   getchar ();
  1067.   ClrScreen ();
  1068.   UpdateDisplay (0, 0, 1, 0);
  1069. }
  1070.  
  1071. void Ldisplay(char *m, char *h, SHORT count)
  1072. {
  1073.         gotoXY(50,LdisplayLine);
  1074.         LdisplayLine++;
  1075.         printz("%s\t%s\t%d\n",m,h,count);
  1076. }
  1077. Ldisplay3()
  1078. {ClrScreen();refresh();LdisplayLine=4;}
  1079. void Ldisplay4(char *line)
  1080. {
  1081.         gotoXY(10,LdisplayLine);
  1082.         LdisplayLine++;
  1083.         printz("%s",line);
  1084.         refresh();
  1085. }
  1086.  
  1087.