home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / RiscPc / jeux / ArcBoard004.arc / !GNUChessX / src / misc / nuxdsp_c < prev    next >
Text File  |  1995-07-02  |  22KB  |  1,076 lines

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