home *** CD-ROM | disk | FTP | other *** search
/ MORE WinGames / WINGAMES.iso / chess / mswdsp.c < prev    next >
C/C++ Source or Header  |  1991-06-16  |  7KB  |  297 lines

  1. /*
  2.   C source for GNU CHESS
  3.  
  4.   Revision: 1990-09-30
  5.  
  6.   Modified by Daryl Baker for use in MS WINDOWS environment
  7.  
  8.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  9.   Copyright (c) 1988, 1989, 1990  John Stanback
  10.  
  11.   This file is part of CHESS.
  12.  
  13.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  14.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  15.   the consequences of using it or for whether it serves any particular
  16.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  17.   General Public License for full details.
  18.  
  19.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  20.   only under the conditions described in the CHESS General Public License.
  21.   A copy of this license is supposed to have been given to you along with
  22.   CHESS so you can know your rights and responsibilities.  It should be in a
  23.   file named COPYING.  Among other things, the copyright notice and this
  24.   notice must be preserved on all copies.
  25. */
  26.  
  27. #define NOATOM 
  28. #define NOCLIPBOARD
  29. #define NOCREATESTRUCT
  30. #define NOSOUND
  31. #define NOWH
  32. #define NOCOMM
  33. #define NOKANJI
  34.  
  35. #include <windows.h>
  36. #include <string.h>
  37. #include <stdio.h>
  38.  
  39. #include "gnuchess.h"
  40. #include "chess.h"
  41. #include "defs.h"
  42. #include "stats.h"
  43.  
  44. extern short boarddraw[64];
  45. extern short colordraw[64];
  46.  
  47. extern char mvstr[4][6];
  48. extern long evrate;
  49. static char* ColorStr[2] = {"White", "Black"};
  50.  
  51. void
  52. ShowPlayers (void)
  53. {
  54.   /* display in the status line what color the computer is playing */
  55.   SetWindowText ( hComputerColor, (computer == black) ? "Computer is black" :
  56.                                                         "Computer is white" );
  57. }
  58.  
  59. void
  60. ShowDepth (char ch)
  61. {
  62.    char tmp[30];
  63.    if ( hStats ) {
  64.       wsprintf ( tmp, "%d%c", Sdepth, ch);
  65.       SetDlgItemText ( hStats, DEPTHTEXT, tmp);
  66.    }
  67. }
  68.  
  69. void
  70. ShowScore (short score)
  71. {
  72.    char tmp[30];
  73.    if ( hStats) {
  74.       wsprintf ( tmp, "%d",score);
  75.       SetDlgItemText ( hStats, SCORETEXT, tmp);
  76.    }
  77. }
  78.  
  79. void
  80. ShowMessage (HWND hWnd, char *s)
  81. {
  82.   MessageBox ( hWnd, s, "Chess", MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
  83. }
  84.  
  85. void SMessageBox ( HWND hWnd, int str_num, int str1_num )
  86. {
  87.    char str[80], str1[20];
  88.    LoadString ( GetWindowWord(hWnd,GWW_HINSTANCE), str_num, str, sizeof ( str ) );
  89.    LoadString ( GetWindowWord(hWnd,GWW_HINSTANCE), str1_num, str1, sizeof ( str1 ) );
  90.    MessageBox ( hWnd, str, str1, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL );
  91. }
  92.  
  93. void
  94. ClearMessage (void)
  95. {
  96. }
  97.  
  98. void
  99. ShowCurrentMove (short int pnt, short int f, short int t)
  100. {
  101.    char tmp[30];
  102.  
  103.    if ( hStats) {
  104.       algbr (f, t, false);
  105.       wsprintf ( tmp, "(%2d) %4s",pnt, (char far *)mvstr[0]);
  106.       SetDlgItemText ( hStats, POSITIONTEXT, tmp);
  107.    }
  108. }
  109.  
  110. void
  111. ShowSidetoMove (void)
  112. {
  113.    char tmp[30];
  114.    wsprintf ( tmp, "It is %s's turn",(char far*)ColorStr[player]);
  115.    SetWindowText ( hWhosTurn, (LPSTR) tmp);
  116.  
  117. }
  118.  
  119. void
  120. ShowPrompt (void)
  121. {
  122. }
  123.  
  124. void
  125. ShowNodeCnt (long int NodeCnt, long int evrate)
  126. {
  127.    char tmp[40];
  128.  
  129.    if ( hStats ) {
  130.       wsprintf ( tmp,"%-8ld", NodeCnt);
  131.       SetDlgItemText ( hStats, NODETEXT, tmp);
  132.       wsprintf ( tmp,"%-5ld", evrate);
  133.       SetDlgItemText ( hStats, NODESECTEXT, tmp);
  134.    }
  135. }  
  136.  
  137. void
  138. ShowResults (short int score, short unsigned int *bstline, char ch)
  139. {
  140.   unsigned char d, ply;
  141.   char str[300];
  142.   int s;
  143.  
  144.   if (flag.post)
  145.     {
  146.       ShowDepth (ch);
  147.       ShowScore (score);
  148.       d = 7; s = 0;
  149.       for (ply = 1; bstline[ply] > 0; ply++)
  150.         {
  151.          algbr ((short) bstline[ply] >> 8, (short) bstline[ply] & 0xFF, false);
  152.          if ( ply==5 || ply==9 || ply==13 || ply==17)
  153.             s += wsprintf ( str+s,"\n");
  154.          s += wsprintf ( str+s,"%-5s ", (char far *) mvstr[0]);
  155.         }
  156.       SetDlgItemText ( hStats, BSTLINETEXT, (LPSTR) str);
  157.     }
  158. }
  159.  
  160. void
  161. SearchStartStuff (short int side)
  162. {
  163. }
  164.  
  165. void
  166. OutputMove (HWND hWnd)
  167. {
  168.   char tmp[30];
  169.  
  170.   UpdateDisplay (hWnd, root->f, root->t, 0, (short) root->flags);
  171.   wsprintf ( tmp, "My move is %s",(char far *) mvstr[0]);
  172.   SetWindowText ( hComputerMove, tmp);
  173.  
  174.   if (root->flags & draw)
  175.     SMessageBox ( hWnd, IDS_DRAWGAME,IDS_CHESS);
  176.   else if (root->score == -9999)
  177.     SMessageBox ( hWnd, IDS_YOUWIN, IDS_CHESS);
  178.   else if (root->score == 9998)
  179.     SMessageBox ( hWnd, IDS_COMPUTERWIN,IDS_CHESS);
  180.   else if (root->score < -9000)
  181.     SMessageBox ( hWnd, IDS_MATESOON,IDS_CHESS);
  182.   else if (root->score > 9000)
  183.     SMessageBox ( hWnd, IDS_COMPMATE,IDS_CHESS);
  184.   if (flag.post)
  185.     {
  186.       ShowNodeCnt (NodeCnt, evrate);
  187. /*
  188.       for (i = 1999; i >= 0 && Tree[i].f == 0 && Tree[i].t == 0; i--);
  189.       printz ("Max Tree= %5d", i);
  190. */
  191.     }
  192. }
  193.  
  194. void
  195. UpdateClocks (void)
  196. {
  197.   short m, s;
  198.   char tmp[20];
  199.  
  200.   m = (short) (et / 60);
  201.   s = (short) (et - 60 * (long) m);
  202.   if (TCflag)
  203.     {
  204.       m = (short) ((TimeControl.clock[player] - et) / 60);
  205.       s = (short) (TimeControl.clock[player] - et - 60 * (long) m);
  206.     }
  207.   if (m < 0) m = 0;
  208.   if (s < 0) s = 0;
  209.  
  210.   wsprintf ( tmp, "%0d:%02d",m,s);
  211.   if ( player == white ) {
  212.       SetWindowText (hClockHuman, tmp);
  213.   } else {
  214.       SetWindowText (hClockComputer, tmp);
  215.   }
  216.  
  217.   if (flag.post)
  218.     ShowNodeCnt (NodeCnt, evrate);
  219. }
  220.  
  221. void
  222. ShowPostnValue (short int sq)
  223. {
  224. }
  225.  
  226. void
  227. ShowPostnValues (void)
  228. {
  229. }
  230.  
  231. void DrawPiece ( HWND hWnd, short int f )
  232. {
  233.    POINT aptl[4];
  234.    HRGN hRgn;
  235.    int x,y;
  236.  
  237.    if ( flag.reverse ) {
  238.      x = 7-(f%8);
  239.      y = 7-(f/8);
  240.    } else {
  241.       x = f%8;
  242.       y = f/8;
  243.    }
  244.  
  245.    QuerySqCoords ( x,y, aptl+0);
  246.    hRgn = CreatePolygonRgn( aptl, 4, WINDING);
  247.    InvalidateRgn ( hWnd, hRgn, FALSE );
  248.    DeleteObject ( hRgn);
  249. }
  250.  
  251. void
  252. UpdateDisplay (HWND hWnd, short int f, short int t, short int redraw, short int isspec)
  253. {
  254.   short sq;
  255.   
  256.   for (sq=0; sq<64; sq++) {
  257.          boarddraw[sq] = board[sq];
  258.          colordraw[sq] = color[sq];
  259.   }
  260.  
  261.   if (redraw){
  262.       InvalidateRect ( hWnd, NULL, TRUE);
  263.       ShowPlayers ();
  264.       UpdateWindow ( hWnd );
  265.   } else {
  266.       DrawPiece (hWnd, f);
  267.       DrawPiece (hWnd, t);
  268.       if (isspec & cstlmask)
  269.         if (t > f)
  270.           {
  271.             DrawPiece (hWnd, f + 3);
  272.             DrawPiece (hWnd, t - 1);
  273.           }
  274.         else
  275.           {
  276.             DrawPiece (hWnd, f - 4);
  277.             DrawPiece (hWnd, t + 1);
  278.           }
  279.       else if (isspec & epmask)
  280.         {
  281.           DrawPiece (hWnd, t - 8);
  282.           DrawPiece (hWnd, t + 8);
  283.         }
  284.       UpdateWindow (hWnd);
  285.     }
  286. }
  287.  
  288. void
  289. GiveHint (HWND hWnd)
  290. {
  291.   char s[40];
  292.   algbr ((short) (hint >> 8), (short) (hint & 0xFF), false);
  293.   strcpy (s, "try ");
  294.   strcat (s, mvstr[0]);
  295.   ShowMessage (hWnd, s);
  296. }
  297.