home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / szachy / gnu / gnu_4_0_74 / gnuchess-4.0.pl74 / src / uxdsp.c < prev    next >
C/C++ Source or Header  |  1994-11-21  |  19KB  |  929 lines

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