home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / useful / game / think / uchess.lha / UChess / src / nondsp.c < prev    next >
C/C++ Source or Header  |  1994-01-22  |  22KB  |  994 lines

  1. /*
  2.  * nondsp.c - UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL 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.  
  24. #include <ctype.h>
  25. #include <signal.h>
  26.  
  27. #ifdef AMIGA
  28. #define __USE_SYSBASE
  29. #include <exec/types.h>
  30. #include <exec/exec.h>
  31. #include <proto/exec.h>
  32. #include <proto/dos.h>
  33. #include <proto/graphics.h>
  34. #include <proto/intuition.h>
  35. #endif
  36.  
  37. char __far HintString[80];
  38.  
  39. #define SIGQUIT SIGINT
  40.  
  41. #include "gnuchess.h"
  42. #ifdef MSDOS
  43. #include <dos.h>
  44. #include <conio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <time.h>
  48. #else
  49. #include <dos.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <time.h>
  53. /*
  54. #include <sys/param.h>
  55. #include <sys/types.h>
  56. #include <sys/file.h>
  57. #include <sys/ioctl.h>
  58. */
  59. #endif
  60.  
  61.  
  62. extern short int ISZERO;
  63. char __aligned __far IllegalString[40];
  64. extern int AmigaStarted;
  65. extern int __aligned global_tmp_score;
  66. extern int __aligned previous_score;
  67. int __aligned IllegalMove=0;
  68. int __aligned Mate=0;
  69. int __aligned DrawnGame=0;
  70. char __far __aligned MateString[40]={0};
  71. extern long OrigResponse;
  72.  
  73. #ifdef DEBUG
  74. INTSIZE int __aligned debuglevel = 0;
  75.  
  76. #endif /* DEBUG */
  77. unsigned INTSIZE int __aligned MV[MAXDEPTH];
  78. int __aligned MSCORE;
  79.  
  80. #if defined CHESSTOOL || defined XBOARD
  81. INTSIZE int __aligned chesstool = 1;
  82.  
  83. #else
  84. INTSIZE int __aligned chesstool = 0;
  85.  
  86. #endif /* CHESSTOOL */
  87. extern char mvstr[4][6];
  88. int __aligned mycnt1, mycnt2;
  89. char __aligned *DRAW;
  90. extern char *InPtr;
  91. extern INTSIZE int pscore[];
  92.  
  93. void
  94. Initialize (void)
  95. {
  96.   mycnt1 = mycnt2 = 0;
  97. #if defined CHESSTOOL || defined XBOARD
  98. #ifndef SYSV
  99. /*  setlinebuf (stdout);*/
  100. #else
  101. /*  setvbuf (stdout, NULL, _IOLBF, BUFSIZ);*/
  102. #endif
  103. /*  printf (CP[43]);*/        /*Chess*/
  104.   if (!TCflag && (MaxResponseTime == 0))
  105.     MaxResponseTime = 15L*100L;
  106. #endif /* CHESSTOOL */
  107. }
  108.  
  109.  
  110. void DoAMove(void);
  111.  
  112. void DoAMove()
  113. {
  114.  char astr[40];
  115.  int r,c,l;
  116.  char piece;
  117.  
  118.       r = mvstr[0][3] - '1';
  119.       c = mvstr[0][2] - 'a';
  120.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  121.       if (color[l] == neutral)
  122.        {
  123.     DisplayBeep(0L);
  124.         Delay(25L);
  125.     DisplayBeep(0L);
  126.         Delay(25L);
  127.     DisplayBeep(0L);
  128.         Delay(25L);
  129.         piece = ' ';
  130.        }
  131.       else if (color[l] == white)
  132.         piece = qxx[board[l]]; /* white are lower case pieces */
  133.       else
  134.         piece = pxx[board[l]]; /* black are upper case pieces */
  135.   if (computer == black)
  136.    sprintf(astr,"%d: %s",GameCnt>>1,mvstr[0]);
  137.   else
  138.    sprintf(astr,"%d: %s",(GameCnt+1)>>1,mvstr[0]);   
  139.   DisplayComputerMove(astr);
  140.   AnimateAmigaMove(mvstr[0],piece);
  141. }
  142. void
  143. ExitChess (void)
  144. {
  145. /*  signal (SIGTERM, SIG_IGN);*/
  146.   ListGame (0L);
  147. #ifdef AMIGA
  148.   if (AmigaStarted)
  149.    AmigaShutDown();
  150. #endif
  151.   exit (0);
  152. }
  153.  
  154. #ifndef MSDOS            /* never called!!! */
  155. #ifndef AMIGA
  156. void
  157. Die (int sig)
  158. {
  159.   char s[80];
  160.  
  161.   ShowMessage (CP[31]);        /*Abort?*/
  162.   scanz ("%s", s);
  163.   if (strcmp (s, CP[210]) == 0)    /*yes*/
  164.     ExitChess ();
  165. }
  166. #endif
  167. #endif /* MSDOS */
  168.  
  169. void
  170. TerminateSearch (int sig)
  171. {
  172. #ifdef MSDOS
  173.   sig++;            /* shut up the compiler */
  174. #endif /* MSDOS */
  175.   if (!flag.timeout)
  176.     flag.musttimeout = true;
  177.   flag.bothsides = false;
  178. }
  179.  
  180.  
  181. void
  182. help (void)
  183. {
  184. #ifndef AMIGA
  185.   ClrScreen ();
  186.   /*printz ("CHESS command summary\n");*/
  187.   printz (CP[40]);
  188.   printz ("----------------------------------------------------------------\n");
  189.   /*printz ("g1f3      move from g1 to f3      quit      Exit Chess\n");*/
  190.   printz (CP[158]);
  191.   /*printz ("Nf3       move knight to f3       beep      turn %s\n", (flag.beep) ? "off" : "on");*/
  192.   printz (CP[86], (flag.beep) ? CP[92] : CP[93]);
  193.   /*printz ("a7a8q     promote pawn to queen\n");*/
  194.   printz (CP[128], (flag.material) ? CP[92] : CP[93]);
  195.   /*printz ("o-o       castle king side        easy      turn %s\n", (flag.easy) ? "off" : "on");*/
  196.   printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
  197.   /*printz ("o-o-o     castle queen side       hash      turn %s\n", (flag.hash) ? "off" : "on");*/
  198.   printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
  199.   /*printz ("bd        redraw board            reverse   board display\n");*/
  200.   printz (CP[130]);
  201.   /*printz ("list      game to chess.lst       book      turn %s used %d of %d\n", (Book) ? "off" : "on", bookcount, BOOKSIZE);*/
  202.   printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
  203.   /*printz ("undo      undo last ply           remove    take back a move\n");*/
  204.   printz (CP[200]);
  205.   /*printz ("edit      edit board              force     enter game moves\n");*/
  206.   printz (CP[153]);
  207.   /*printz ("switch    sides with computer     both      computer match\n");*/
  208.   printz (CP[194]);
  209.   /*printz ("white     computer plays white    black     computer plays black\n");*/
  210.   printz (CP[202]);
  211.   /*printz ("depth     set search depth        clock     set time control\n");*/
  212.   printz (CP[149]);
  213.   /*printz ("post      principle variation     hint      suggest a move\n");*/
  214.   printz (CP[177]);
  215.   /*printz ("save      game to file            get       game from file\n");*/
  216.   printz (CP[188]);
  217.   /*printz ("random    randomize play          new       start new game\n");*/
  218.   printz (CP[181]);
  219.   printz ("----------------------------------------------------------------\n");
  220.   /*printz ("Computer: %-12s Opponent:            %s\n",*/
  221.   printz (CP[46],
  222.       ColorStr[computer], ColorStr[opponent]);
  223.   /*printz ("Depth:    %-12d Response time:       %d sec\n",*/
  224.   printz (CP[51],
  225.       MaxSearchDepth, MaxResponseTime/100);
  226.   /*printz ("Random:   %-12s Easy mode:           %s\n",*/
  227.   printz (CP[99],
  228.       (dither) ? CP[93] : CP[92], (flag.easy) ? CP[93] : CP[92]);
  229.   /*printz ("Beep:     %-12s Transposition file: %s\n",*/
  230.   printz (CP[36],
  231.       (flag.beep) ? CP[93] : CP[92], (flag.hash) ? CP[93] : CP[92]);
  232.   /*printz ("Time Control %s %d moves %d seconds %d opr %d depth\n", (TCflag) ? "ON" : "OFF",*/
  233.   printz (CP[110], (TCflag) ? CP[93] : CP[92],
  234.       TimeControl.moves[white], TimeControl.clock[white] / 100, OperatorTime, MaxSearchDepth);
  235.   signal (SIGINT, TerminateSearch);
  236. #ifndef MSDOS
  237.   signal (SIGQUIT, TerminateSearch);
  238. #endif /* MSDOS */
  239. #endif
  240. }
  241.  
  242. void
  243. EditBoard (void)
  244.  
  245. /*
  246.  * Set up a board position. Pieces are entered by typing the piece followed
  247.  * by the location. For example, Nf3 will place a knight on square f3.
  248.  */
  249.  
  250. {
  251.   INTSIZE a, r, c, sq, i, found;
  252.   int tmpcolor;
  253.   char s[80];
  254.  
  255.   flag.regularstart = false;
  256.   Book = 0;
  257. #ifndef AMIGA
  258.   /*printz (".   exit to main\n");*/
  259.   printz (CP[29]);
  260.   /*printz ("#   clear board\n");*/
  261.   printz (CP[28]);
  262.   /*printz ("c   change sides\n");*/
  263.   printz (CP[136]);
  264.   /*printz ("enter piece & location: \n");*/
  265.   printz (CP[155]);
  266. #else
  267.   if (!OpenAmigaEditWindow())
  268.    { /* open the window which will give us back text string */
  269.     DisplayBeep(0L);
  270.     Delay(25L);
  271.     DisplayBeep(0L);
  272.     return;
  273.    }
  274. #endif
  275.  
  276.   a = tmpcolor = white;
  277.   do
  278.     {
  279.       GetEditText(s,&tmpcolor); /* amiga routine to get the command from user */
  280.       found=0;
  281.       if (s[0] == CP[28][0])    /*#*/
  282.     for (sq = 0; sq < 64; sq++)
  283.       {
  284.         board[sq] = no_piece;
  285.         color[sq] = neutral;
  286.       }
  287.       if (a != tmpcolor)    /*c*/
  288.     a = otherside[a];
  289.       c = s[1] - 'a';
  290.       r = s[2] - '1';
  291.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  292.     {
  293.       sq = locn (r, c);
  294.       color[sq] = a;
  295.       board[sq] = no_piece;
  296.       for (i = no_piece; i <= king; i++)
  297.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  298.           {
  299.         board[sq] = i;
  300.         found=1;
  301.         break;
  302.           }
  303.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  304.     }
  305.   } while (s[0] != CP[29][0]);
  306.   for (sq = 0; sq < 64; sq++)
  307.     Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
  308.   CloseAmigaEditWindow(); /* Closes the edit window */
  309.   GameCnt = 0;
  310.   Game50 = 1;
  311.   ISZERO = 1;
  312.   ZeroRPT ();
  313.   Sdepth = 0;
  314.   InitializeStats ();
  315.   DrawAmigaBoard();
  316. }
  317.  
  318. void
  319. SetupBoard (void)
  320.  
  321. /*
  322.  * Compatibility with Unix chess and the nchesstool. Set up a board position.
  323.  * Eight lines of eight characters are used to setup the board. a8-h8 is the
  324.  * first line. Black pieces are  represented  by  uppercase characters.
  325.  */
  326.  
  327. {
  328. #ifdef AMIGA
  329. return;
  330. #else
  331.   INTSIZE r, c, sq, i;
  332.   char ch;
  333.   char s[80];
  334.  
  335.   NewGame ();
  336.  
  337.   gets (s);            /* skip "setup" command */
  338.   for (r = 7; r >= 0; r--)
  339.     {
  340.       gets (s);
  341.       for (c = 0; c <= 7; c++)
  342.     {
  343.       ch = s[c];
  344.       sq = locn (r, c);
  345.       color[sq] = neutral;
  346.       board[sq] = no_piece;
  347.       for (i = no_piece; i <= king; i++)
  348.         if (ch == pxx[i])
  349.           {
  350.         color[sq] = black;
  351.         board[sq] = i;
  352.         break;
  353.           }
  354.         else if (ch == qxx[i])
  355.           {
  356.         color[sq] = white;
  357.         board[sq] = i;
  358.         break;
  359.           }
  360.     }
  361.     }
  362.   for (sq = 0; sq < 64; sq++)
  363.     Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
  364.   InitializeStats ();
  365.   ClrScreen ();
  366.   UpdateDisplay (0, 0, 1, 0);
  367.   /*printz ("Setup successful\n");*/
  368.   printz (CP[106]);
  369. #endif
  370. }
  371.  
  372.  
  373. void
  374. ShowDepth (char ch)
  375. {
  376. #ifdef MSDOS
  377.   ch++;                /* shut up the compiler */
  378. #endif /* MSDOS */
  379. }
  380.  
  381.  
  382. void
  383. ShowLine (INTSIZE unsigned int *bstline,char *astr)
  384. {
  385.  
  386.       algbr ((INTSIZE) (bstline[1] >> 8), (INTSIZE) (bstline[1] & 0xFF), false);
  387.       sprintf (astr,"%s", mvstr[0]);
  388. }
  389.  
  390. void
  391. ShowResults (INTSIZE int score, INTSIZE unsigned int *bstline, char ch)
  392. {
  393.  char astr[64];
  394.  char nstr[16];
  395.  
  396. #if !defined CHESSTOOL
  397. /*printf("GameCnt = %d PrevDepth = %d\n",GameCnt,GameList[GameCnt-1].depth);*/
  398.   if ((!flag.easy)&&(ThinkAheadDepth)&&(TCflag)&&(GameCnt > 1)&&(Sdepth > 2))
  399.    { /* check for lookahead abort */
  400. //sprintf(astr,"prev = %d",previous_score);
  401. //ShowMessage(astr);
  402. //sprintf(astr,"curr = %d",global_tmp_score);
  403. //ShowMessage(astr);
  404.     if ((Sdepth >= ThinkAheadDepth)&&(Sdepth >= GameList[GameCnt-1].depth)&&
  405.         (Sdepth > GlobalTgtDepth)&&(global_tmp_score >= (previous_score-25)))
  406.      { /* a chance I may want to abort search here */
  407.         if (!flag.musttimeout)
  408.          { /* not already aborted */
  409.           if ((ThinkInARow < 4)||(Sdepth > ThinkAheadDepth))
  410.            { /* max 4 times in a row */
  411.             flag.musttimeout = true;
  412.             if (Sdepth == ThinkAheadDepth)
  413.              ThinkInARow++;
  414.             else /* you thought past thinkaheaddepth */
  415.              ThinkInARow = 0;
  416.            }
  417.          }
  418.      }
  419.    }
  420.   if (flag.post)
  421.     {
  422.       ElapsedTime (2);
  423.       sprintf (astr,"D%d S%d ", Sdepth, score);
  424.       ShowLine (bstline,nstr);
  425.       strcat(astr,nstr);
  426.       ShowMessage(astr);
  427.     }
  428. #else
  429.   REG int i;
  430.  
  431.   MSCORE = score;
  432.   MV[30] = ch;
  433.   for (i = 1; bstline[i] > 0; i++)
  434.     {
  435.       MV[i] = bstline[i];
  436.     } MV[i] = 0;
  437. #endif /* CHESSTOOL */
  438. }
  439.  
  440. void
  441. SearchStartStuff (INTSIZE int side)
  442. {
  443.  char astr[64];
  444.   signal (SIGINT, TerminateSearch);
  445. #ifndef MSDOS
  446.   signal (SIGQUIT, TerminateSearch);
  447. #endif /* MSDOS */
  448. #if !defined CHESSTOOL
  449. /*#ifndef AMIGA*/
  450.   if (flag.post)
  451.     {
  452.       sprintf (astr,"Tgt:%d  ", ResponseTime);
  453.       ShowMessage(astr);
  454.     }
  455. /*#endif*/
  456. #endif /* CHESSTOOL */
  457. }
  458. void
  459. OutputMove (cstring)
  460. char *cstring;
  461. {
  462.  int r,c,l;
  463.  char astr[40];
  464.  char piece;
  465.  
  466. #ifdef DEBUG11
  467.   if (1)
  468.     {
  469.       FILE *D;
  470.       extern unsigned INTSIZE int PrVar[];
  471.       char d[80];
  472.       int r, c, l, i;
  473.       D = fopen ("/tmp/DEBUGA", "a+");
  474.       fprintf (D, "inout move is %s\n", mvstr[0]);
  475.       strcpy (d, mvstr[0]);
  476.       for (i = 1; PrVar[i] > 0; i++)
  477.     {
  478.       algbr ((INTSIZE) (PrVar[i] >> 8), (INTSIZE) (PrVar[i] & 0xFF), false);
  479.       fprintf (D, "%5s ", mvstr[0]);
  480.     }
  481.       fprintf (D, "\n");
  482.  
  483.       fprintf (D, "\n current board is\n");
  484.       for (r = 7; r >= 0; r--)
  485.     {
  486.       for (c = 0; c <= 7; c++)
  487.         {
  488.           l = locn (r, c);
  489.           if (color[l] == neutral)
  490.         fprintf (D, " -");
  491.           else if (color[l] == white)
  492.         fprintf (D, " %c", qxx[board[l]]);
  493.           else
  494.         fprintf (D, " %c", pxx[board[l]]);
  495.         }
  496.       fprintf (D, "\n");
  497.     }
  498.       fprintf (D, "\n");
  499.       fclose (D);
  500.       strcpy (mvstr[0], d);
  501.     }
  502. #endif
  503. if(flag.illegal){
  504.  IllegalMove = 1;
  505.  sprintf(IllegalString,"%s\n",CP[225]);
  506.  return;
  507. }
  508. if (mvstr[0][0] == '\0') goto nomove;
  509. #ifndef AMIGA
  510. #if defined CHESSTOOL
  511.   if (computer == black)
  512.     printz ("%d. ... %s\n", GameCnt, mvstr[0]);
  513.   else
  514.     printz ("%d. %s\n", ++mycnt1, mvstr[0]);
  515. #else
  516. #ifdef XBOARD
  517.   printz ("%d. ... %s\n", ++mycnt1, mvstr[0]);
  518. #else
  519.   printz ("%d. ... %s\n", ++mycnt1, mvstr[0]);
  520. #endif
  521. #endif /* CHESSTOOL */
  522. #endif /* amiga */
  523. #ifdef notdef
  524.   if (flag.post)
  525.     {
  526.       REG int i;
  527.  
  528.       printz (" %6d%c ", MSCORE, MV[30]);
  529.       for (i = 1; MV[i] > 0; i++)
  530.     {
  531.       algbr ((INTSIZE) (MV[i] >> 8), (INTSIZE) (MV[i] & 0xFF), false);
  532.       printz ("%5s ", mvstr[0]);
  533.     }
  534.     }
  535.   printz ("\n");
  536. #endif
  537. nomove:
  538.   if ((root->flags & draw)||(root->score == -9999)||
  539.       (root->score == 9998)) goto summary;
  540. #if !defined CHESSTOOL
  541.   if (flag.post)
  542.     {
  543.       INTSIZE h, l, t;
  544.  
  545.       h = TREE;
  546.       l = 0;
  547.       t = TREE >> 1;
  548.       while (l != t)
  549.     {
  550.       if (Tree[t].f || Tree[t].t)
  551.         l = t;
  552.       else
  553.         h = t;
  554.       t = (l + h) >> 1;
  555.     }
  556. #ifndef AMIGA
  557.       /*printf ("Nodes %ld Tree %d Eval %ld Rate %ld RS high %ld low %ld\n",*/
  558.       printf (CP[89],
  559.            NodeCnt, t, EvalNodes, (et) ? (NodeCnt / (et / 100)) : 0, reminus, replus);
  560.       /*printf ("Hin/Hout/Coll/Fin/Fout = %ld/%ld/%ld/%ld/%ld\n",*/
  561.       printf (CP[71],
  562.            HashAdd, HashCnt, THashCol, HashCol, FHashAdd, FHashCnt);
  563. #else /* print out thinking on amiga */
  564. #endif
  565.     }
  566.   UpdateDisplay (root->f, root->t, 0, root->flags);
  567. #ifndef AMIGA
  568.   /*printf ("My move is: %s\n", mvstr[0]);*/
  569.  
  570.   printz (CP[83], mvstr[0]);
  571. #else
  572.       r = mvstr[0][3] - '1';
  573.       c = mvstr[0][2] - 'a';
  574.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  575.       if (color[l] == neutral)
  576.        {
  577.     DisplayBeep(0L);
  578.         Delay(25L);
  579.     DisplayBeep(0L);
  580.         Delay(25L);
  581.     DisplayBeep(0L);
  582.         Delay(25L);
  583.         piece = ' ';
  584.        }
  585.       else if (color[l] == white)
  586.         piece = qxx[board[l]]; /* white are lower case pieces */
  587.       else
  588.         piece = pxx[board[l]]; /* black are upper case pieces */
  589.   if (computer == black)
  590.    sprintf(astr,"%d: %s",GameCnt>>1,mvstr[0]);
  591.   else
  592.    sprintf(astr,"%d: %s",(GameCnt+1)>>1,mvstr[0]);   
  593.   DisplayComputerMove(astr);
  594.   AnimateAmigaMove(mvstr[0],piece);
  595. #endif
  596.   if ((flag.beep)&&(!flag.bothsides))
  597.    {
  598.     DisplayBeep(0L);
  599.    }
  600. #endif /* CHESSTOOL */
  601.  summary:
  602.   if (root->flags & draw)
  603.     /*    printf ("Drawn game!\n");*/
  604.    {
  605.     /*printz (CP[57]);*/
  606.     DrawnGame = 1;
  607.    }
  608.   else if (root->score == -9999)
  609.    {
  610.     Mate = 1;
  611. #ifdef OLDWAYPL58
  612.     if (flag.bothsides)
  613.      sprintf(MateString,"%s mates!",ColorStr[opponent^1]);
  614.     else
  615.      sprintf(MateString,"%s mates!",ColorStr[opponent]);
  616. #else
  617.     sprintf(MateString,"%s mates!",ColorStr[opponent]);
  618. #endif
  619. /*    printz("%s mates!\n",ColorStr[opponent]);*/
  620.    }
  621.   else if (root->score == 9998)
  622.    {
  623.     Mate = 1;
  624.     DoAMove();
  625.     if (flag.bothsides)
  626.      sprintf(MateString,"%s mates!",ColorStr[computer^1]);
  627.     else
  628.      sprintf(MateString,"%s mates!",ColorStr[computer]);
  629. /*    printz("%s mates!\n",ColorStr[computer]);*/
  630.    }
  631. #if !defined CHESSTOOL && !defined XBOARD
  632. #ifdef VERYBUGGY
  633.   else if (root->score < -9000)
  634.     /*printf("%s has a forced mate!\n",ColorStr[opponent]);*/
  635.   else if (root->score > 9000)
  636.     /*printf("%s has a forced mate!\n",ColorStr[computer]);*/
  637. #endif /*VERYBUGGY*/
  638. #endif /* CHESSTOOL */
  639. }
  640.  
  641. void
  642. ClrScreen (void)
  643. {
  644. #if !defined CHESSTOOL && !defined XBOARD && !defined AMIGA
  645.   printz ("\n");
  646. #endif
  647. #ifdef AMIGA
  648. #endif
  649. }
  650.  
  651. void
  652. UpdateDisplay (INTSIZE int f, INTSIZE int t, INTSIZE int redraw, INTSIZE int isspec)
  653. {
  654.  
  655. #ifndef AMIGA
  656.   INTSIZE r, c, l, m;
  657. #endif
  658.  
  659.   if (redraw && !chesstool)
  660.     {
  661. #ifndef AMIGA /* text clock and etc display */
  662.       printz ("\n");
  663.       r = TimeControl.clock[white] / 6000;
  664.       c = (TimeControl.clock[white] % 6000) / 100;
  665.       l = TimeControl.clock[black] / 6000;
  666.       m = (TimeControl.clock[black] % 6000) / 100;
  667.       /*printz ("White %d:%02d  Black %d:%02d\n", r, c, l, m);*/
  668.       printz (CP[116], r, c, l, m);
  669.       printz ("\n");
  670.       for (r = 7; r >= 0; r--)
  671.     {
  672.       for (c = 0; c <= 7; c++)
  673.         {
  674.           l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  675.           if (color[l] == neutral)
  676.         printz (" -");
  677.           else if (color[l] == white)
  678.         printz (" %c", qxx[board[l]]);
  679.           else
  680.         printz (" %c", pxx[board[l]]);
  681.         }
  682.       printz ("\n");
  683.     }
  684.       printz ("\n");
  685. #else /* Update intution board on the Amiga */
  686. #endif
  687.     }
  688. }
  689.  
  690. void
  691. skip ()
  692. {
  693.   while (*InPtr != ' ')
  694.     InPtr++;
  695.   while (*InPtr == ' ')
  696.     InPtr++;
  697. }
  698. void
  699. skipb ()
  700. {
  701.   while (*InPtr == ' ')
  702.     InPtr++;
  703. }
  704.  
  705. #ifndef AMIGA
  706. void
  707. ShowMessage (char *s)
  708. {
  709. #ifndef AMIGA
  710.   printf("%s\n", s);
  711. #else /* write this msg on the intuition msg screen */
  712.   DisplayComputerMove(s);
  713. #endif
  714. }
  715.  
  716. #endif
  717.  
  718. void
  719. ShowSidetoMove (void)
  720. {
  721. }
  722.  
  723. void
  724. PromptForMove (void)
  725. {
  726. #if !defined CHESSTOOL && !defined XBOARD && !defined AMIGA
  727.   /*printz ("\nYour move is? ");*/
  728.   printz (CP[124]);
  729. #endif /* CHESSTOOL */
  730. }
  731.  
  732.  
  733. void
  734. ShowCurrentMove (INTSIZE int pnt, INTSIZE int f, INTSIZE int t)
  735. {
  736. #ifdef MSDOS
  737.   f++;
  738.   t++;
  739.   pnt++;            /* shut up the compiler */
  740. #endif /* MSDOS */
  741. }
  742.  
  743. void
  744. ChangeAlphaWindow (void)
  745. {
  746. #ifndef AMIGA
  747.   printz ("WAwindow: ");
  748.   scanz ("%hd", &WAwindow);
  749.   printz ("BAwindow: ");
  750.   scanz ("%hd", &BAwindow);
  751. #endif
  752. }
  753.  
  754.  
  755. void
  756. ChangeBetaWindow (void)
  757. {
  758. #ifndef AMIGA
  759.   printz ("WBwindow: ");
  760.   scanz ("%hd", &WBwindow);
  761.   printz ("BBwindow: ");
  762.   scanz ("%hd", &BBwindow);
  763. #endif
  764. }
  765.  
  766. void
  767. GiveHint (void)
  768. {
  769.   if (hint)
  770.     {
  771.       algbr ((INTSIZE) (hint >> 8), (INTSIZE) (hint & 0xFF), false);
  772.       sprintf(HintString,CP[72], mvstr[0]);    /*hint*/
  773.     }
  774.   else
  775.     sprintf (HintString,CP[223]);
  776. #ifndef AMIGA
  777. printf(HintString);
  778. #else
  779. DisplayComputerMove(HintString);
  780. #endif
  781. }
  782.  
  783. void
  784. SelectLevel (timestring)
  785. char *timestring;
  786. {
  787.   int tmp;
  788.   char T[64], *p, *q;
  789.  
  790. #ifndef AMIGA
  791.   printz (CP[61]);
  792.   scanz ("%hd %s", &TCmoves, T);
  793. #else
  794. #ifndef LONGINTS2
  795.   sscanf(timestring,"%hd %s",&TCmoves,T);
  796. #else
  797.   sscanf(timestring,"%d %s",&TCmoves,T);
  798. #endif
  799. #endif
  800.   for (p = T; *p == ' '; p++) ;
  801.   TCminutes = strtol (p, &q, 10);
  802.   TCadd = 0;
  803.   if (TCminutes < 1)
  804.    TCminutes = 1;
  805.   if (TCmoves < 1)
  806.    TCmoves = 1;
  807.   if ((TCminutes/TCmoves) > 0)
  808.    {
  809.     EnableMoveNow();
  810.    }
  811.   else
  812.    {
  813.     DisableMoveNow();
  814.    }
  815.   if (*q == ':')
  816.     TCseconds = strtol (q + 1, (char **) NULL, 10);
  817.   else
  818.     TCseconds = 0;
  819. #ifdef OPERATORTIME
  820.   printz (CP[94]);
  821.   scanz ("%hd", &OperatorTime);
  822. #endif
  823.   if (TCmoves == 0) {
  824.     TCflag = false;
  825.     MaxResponseTime = TCminutes*60L*100L + TCseconds*100L;
  826.     TCminutes = TCseconds = 0;
  827.   } else {
  828.     TCflag = true;
  829.     MaxResponseTime = 0;
  830.     MaxSearchDepth = MAXDEPTH - 1;
  831.   }
  832.   SetTimeControl ();
  833. #ifdef AMIGA
  834.   tmp = player;
  835.   player = white;
  836.   UpdateClocks();
  837.   player = black;
  838.   UpdateClocks();
  839.   player = tmp;
  840. #endif
  841. }
  842.  
  843. #ifdef DEBUG
  844. void
  845. ChangeDbLev (void)
  846. {
  847.   printz (CP[146]);
  848.   scanz ("%hd", &debuglevel);
  849. }
  850.  
  851. #endif /* DEBUG */
  852.  
  853. void
  854. ChangeSearchDepth (void)
  855. {
  856.  int Old;
  857.  
  858.  Old = MaxSearchDepth;
  859. #ifndef AMIGA
  860.   printz ("depth= ");
  861.   scanz ("%hd", &MaxSearchDepth);
  862. #else
  863.   MaxSearchDepth = SetAmigaDepth();
  864. #endif
  865.   if (MaxSearchDepth)
  866.    {
  867.     TCflag = !(MaxSearchDepth > 0);
  868.     if (MaxSearchDepth > 2)
  869.      EnableMoveNow();
  870.    }
  871.   else
  872.    MaxSearchDepth = Old;
  873. }
  874.  
  875. void ChangeHashDepth (void)
  876. {
  877. #ifndef AMIGA
  878.   printz ("hashdepth= ");
  879.   scanz ("%hd", &HashDepth);
  880.   printz ("MoveLimit= ");
  881.   scanz ("%hd", &HashMoveLimit);
  882. #endif
  883. }
  884.  
  885. void
  886. SetContempt (void)
  887. {
  888. #ifndef AMIGA
  889.   printz ("contempt= ");
  890.   scanz ("%hd", &contempt);
  891. #endif
  892. }
  893.  
  894. void
  895. ChangeXwindow (void)
  896. {
  897. #ifndef AMIGA
  898.   printz ("xwndw= ");
  899.   scanz ("%hd", &xwndw);
  900. #endif
  901. }
  902.  
  903. void
  904. ShowPostnValue (INTSIZE int sq)
  905.  
  906. /*
  907.  * must have called ExaminePosition() first
  908.  */
  909.  
  910. {
  911.   char astr[80];
  912.   INTSIZE score;
  913.  
  914.   score = ScorePosition (color[sq]);
  915.   if (color[sq] != neutral){
  916.     sprintf (astr,"%3d%c ", svalue[sq],(color[sq] == black)?'b':'w');}
  917.   else
  918.     sprintf(astr," *   ");
  919.   ShowMessage(astr);
  920. }
  921.  
  922. void
  923. DoDebug (void)
  924. {
  925. #ifndef AMIGA
  926.   INTSIZE c, p, sq, tp, tc, tsq, score,j,k;
  927.   char s[40];
  928.  
  929.   ExaminePosition ();
  930.   ShowMessage (CP[65]);
  931.   scanz ("%s", s);
  932.   c = neutral;
  933.   if (s[0] == CP[9][0] || s[0] == CP[9][1])     /* w W*/ c = white;
  934.   if (s[0] == CP[9][2] || s[0] == CP[9][3])     /*b B*/ c = black;
  935.   for (p = king; p > no_piece; p--)
  936.     if ((s[1] == pxx[p]) || (s[1] == qxx[p])) break;
  937.   if(p > no_piece)
  938.   for(j=7;j>=0;j--){
  939.   for(k=0;k<8;k++){
  940.       sq=j*8+k;
  941.       tp = board[sq];
  942.       tc = color[sq];
  943.       board[sq] = p;
  944.       color[sq] = c;
  945.       tsq = PieceList[c][1];
  946.       PieceList[c][1] = sq;
  947.       ShowPostnValue (sq);
  948.       PieceList[c][1] = tsq;
  949.       board[sq] = tp;
  950.       color[sq] = tc;
  951.     }
  952.       printz("\n");
  953.     }
  954.   score = ScorePosition (opponent);
  955.   printz (CP[103], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  956. #endif
  957. }
  958.  
  959. void
  960. DoTable (INTSIZE table[64])
  961. {
  962.   char astr[16];
  963.   INTSIZE  sq,j,k;
  964.   ExaminePosition ();
  965.   for(j=7;j>=0;j--){
  966.   for(k=0;k<8;k++){
  967.     sq=j*8+k;
  968.     sprintf (astr,"%3d ", table[sq]);
  969.     ShowMessage(astr);
  970.   }
  971. }
  972. }
  973.  
  974. void
  975. ShowPostnValues (void)
  976. {
  977.   INTSIZE sq, score,j,k;
  978.   char astr[64];
  979.  
  980.   ExaminePosition ();
  981.   for(j=7;j>=0;j--){
  982.   for(k=0;k<8;k++){
  983.   sq=j*8+k;
  984.     ShowPostnValue (sq);
  985.   }
  986.   }
  987.   score = ScorePosition (opponent);
  988.  sprintf (astr,CP[103], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  989.  ShowMessage(astr);
  990.  sprintf(astr,"hung white %d hung black %d\n",hung[white],hung[black]);
  991.  ShowMessage(astr);
  992. }
  993.  
  994.