home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / games / gnuchess / sources / mswdsp.c < prev    next >
C/C++ Source or Header  |  1990-12-01  |  8KB  |  350 lines

  1. //
  2. //  Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  3. //  Copyright (c) 1988, 1989, 1990  John Stanback
  4. //
  5. //  Project:    OS/2 PM Port of GNU CHESS 3.1 (PmChess)
  6. //
  7. //  Version:    1990-11-17
  8. //
  9. //   Module:    Window Display Logic (MswDsp.c)
  10. //
  11. //   Porter:    Ported to Windows 3.0 by Darly Baker
  12. //
  13. //   Porter:    Ported to OS/2 1.2+ by Kent Cedola
  14. //
  15. //   System:    OS2 1.2 using Microsoft C 6.0
  16. //
  17. //  Remarks:    This code converted from Windows to PM using a straight port
  18. //              method with some editing improvements.
  19. //
  20. //  License:
  21. //
  22. //    CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  23. //    WARRANTY.  No author or distributor accepts responsibility to anyone for
  24. //    the consequences of using it or for whether it serves any particular
  25. //    purpose or works at all, unless he says so in writing.  Refer to the
  26. //    CHESS General Public License for full details.
  27. //
  28. //    Everyone is granted permission to copy, modify and redistribute CHESS,
  29. //    but only under the conditions described in the CHESS General Public
  30. //    License.  A copy of this license is supposed to have been given to you
  31. //    along with CHESS so you can know your rights and responsibilities.  It
  32. //    should be in a file named COPYING.  Among other things, the copyright
  33. //    notice and this notice must be preserved on all copies.
  34. //
  35.  
  36. #define INCL_DOS
  37. #define INCL_PM
  38. #include <os2.h>
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include "PmChess.h"
  42. #include "GnuChess.h"
  43. #include "Defs.h"
  44. #include "Resource.h"
  45.  
  46.  
  47. extern short boarddraw[64];
  48. extern short colordraw[64];
  49.  
  50. extern char mvstr[4][6];
  51. extern long evrate;
  52. static char* ColorStr[2] = {"White", "Black"};
  53.  
  54. void
  55. ShowPlayers (void)
  56. {
  57.   /* display in the status line what color the computer is playing */
  58.   WinSetWindowText ( hComputerColor, (computer == black) ? "Computer is black" :
  59.                                                         "Computer is white" );
  60. }
  61.  
  62. void
  63. ShowDepth (char ch)
  64. {
  65.    char tmp[30];
  66.    if ( hStats ) {
  67.       sprintf ( tmp, "%d%c", Sdepth, ch);
  68.       WinSetDlgItemText ( hStats, IDC_STATS_DEPTH, tmp);
  69.    }
  70. }
  71.  
  72. void
  73. ShowScore (short score)
  74. {
  75.    char tmp[30];
  76.    if ( hStats) {
  77.       sprintf ( tmp, "%d",score);
  78.       WinSetDlgItemText ( hStats, IDC_STATS_SCORE, tmp);
  79.    }
  80. }
  81.  
  82.  
  83. //***************************************************************************
  84. //
  85. //  Routine: ShowMessage(In, In)
  86. //
  87. //  Remarks: This subroutine is called to display the specified text to the
  88. //           user in a message box.
  89. //
  90. //  Returns: None.
  91. //
  92. void ShowMessage(HWND hWnd, PSZ pszText)
  93.   {
  94.   WinMessageBox(HWND_DESKTOP, hWnd, pszText, szAppName, 0,
  95.                 MB_OK | MB_ICONEXCLAMATION);
  96.   }
  97.  
  98.  
  99. //***************************************************************************
  100. //
  101. //  Routine: SMessageBox(In, In, In)
  102. //
  103. //  Remarks: This subroutine is called to display a the specified string
  104. //           resource text to the user.
  105. //
  106. //  Returns: None.
  107. //
  108. void SMessageBox(HWND hWnd, SHORT str_num, SHORT str1_num)
  109.   {
  110.   char str[100], str1[100];
  111.  
  112.  
  113.   WinLoadString(hab, 0, str_num,  sizeof(str),  str);
  114.   WinLoadString(hab, 0, str1_num, sizeof(str1), str1);
  115.  
  116.   WinMessageBox(HWND_DESKTOP, hWnd, str, str1, 0, MB_OK | MB_ICONEXCLAMATION);
  117.   }
  118.  
  119.  
  120. void
  121. ClearMessage (void)
  122. {
  123. }
  124.  
  125. void
  126. ShowCurrentMove (short int pnt, short int f, short int t)
  127. {
  128.    char tmp[30];
  129.  
  130.    if ( hStats) {
  131.       algbr (f, t, false);
  132.       sprintf ( tmp, "(%2d) %4s",pnt, (char *)mvstr[0]);
  133.       WinSetDlgItemText ( hStats, IDC_STATS_POSITION, tmp);
  134.    }
  135. }
  136.  
  137. void
  138. ShowSidetoMove (void)
  139. {
  140.    char tmp[30];
  141.    sprintf ( tmp, "It is %s's turn",(char *)ColorStr[player]);
  142.    WinSetWindowText ( hWhosTurn, tmp);
  143.  
  144. }
  145.  
  146. void
  147. ShowPrompt (void)
  148. {
  149. }
  150.  
  151. void
  152. ShowNodeCnt (long int NodeCnt, long int evrate)
  153. {
  154.    char tmp[40];
  155.  
  156.    if ( hStats ) {
  157.       sprintf ( tmp,"%-8ld", NodeCnt);
  158.       WinSetDlgItemText ( hStats, IDC_STATS_NODES, tmp);
  159.       sprintf ( tmp,"%-5ld", evrate);
  160.       WinSetDlgItemText ( hStats, IDC_STATS_RATE, tmp);
  161.    }
  162. }  
  163.  
  164. void
  165. ShowResults (short int score, short unsigned int *bstline, char ch)
  166. {
  167.   unsigned char d, ply;
  168.   char str[300];
  169.   int s;
  170.  
  171.   if (flag.post)
  172.     {
  173.       ShowDepth (ch);
  174.       ShowScore (score);
  175.       d = 7; s = 0;
  176.       for (ply = 1; bstline[ply] > 0; ply++)
  177.         {
  178.          algbr ((short) bstline[ply] >> 8, (short) bstline[ply] & 0xFF, false);
  179.          if ( ply==5 || ply==9 || ply==13 || ply==17)
  180.             s += sprintf ( str+s,"\n");
  181.          s += sprintf ( str+s,"%-5s ", (char *) mvstr[0]);
  182.         }
  183.       WinSetDlgItemText ( hStats, IDC_STATS_BEST, str);
  184.     }
  185. }
  186.  
  187. void
  188. SearchStartStuff (short int side)
  189. {
  190. }
  191.  
  192. void
  193. OutputMove (HWND hWnd)
  194. {
  195.   char tmp[30];
  196.  
  197.   UpdateDisplay (hWnd, root->f, root->t, 0, (short) root->flags);
  198.   sprintf ( tmp, "My move is %s",(char *) mvstr[0]);
  199.   WinSetWindowText ( hComputerMove, tmp);
  200.  
  201.   if (root->flags & draw)
  202.     SMessageBox ( hWnd, IDS_DRAWGAME,IDS_CHESS);
  203.   else if (root->score == -9999)
  204.     SMessageBox ( hWnd, IDS_YOUWIN, IDS_CHESS);
  205.   else if (root->score == 9998)
  206.     SMessageBox ( hWnd, IDS_COMPUTERWIN,IDS_CHESS);
  207.   else if (root->score < -9000)
  208.     SMessageBox ( hWnd, IDS_MATESOON,IDS_CHESS);
  209.   else if (root->score > 9000)
  210.     SMessageBox ( hWnd, IDS_COMPMATE,IDS_CHESS);
  211.   if (flag.post)
  212.     {
  213.       ShowNodeCnt (NodeCnt, evrate);
  214. /*
  215.       for (i = 1999; i >= 0 && Tree[i].f == 0 && Tree[i].t == 0; i--);
  216.       printz ("Max Tree= %5d", i);
  217. */
  218.     }
  219. }
  220.  
  221. void
  222. UpdateClocks (void)
  223. {
  224.   short m, s;
  225.   char tmp[20];
  226.  
  227.   m = (short) (et / 60);
  228.   s = (short) (et - 60 * (long) m);
  229.   if (TCflag)
  230.     {
  231.       m = (short) ((TimeControl.clock[player] - et) / 60);
  232.       s = (short) (TimeControl.clock[player] - et - 60 * (long) m);
  233.     }
  234.   if (m < 0) m = 0;
  235.   if (s < 0) s = 0;
  236.  
  237.   sprintf ( tmp, "%0d:%02d",m,s);
  238.   if ( player == computer ) {
  239.       WinSetWindowText (hClockComputer, tmp);
  240.   } else {
  241.       WinSetWindowText (hClockHuman, tmp);
  242.   }
  243.  
  244.   if (flag.post)
  245.     ShowNodeCnt (NodeCnt, evrate);
  246. }
  247.  
  248. void
  249. ShowPostnValue (short int sq)
  250. {
  251. }
  252.  
  253. void
  254. ShowPostnValues (void)
  255. {
  256. }
  257.  
  258. //***************************************************************************
  259. //
  260. //  Routine: DrawPiece(In, In)
  261. //
  262. //  Remarks: This subroutine is called to display a piece by invalidating
  263. //           it's region and letting the paint logic draw it in.
  264. //
  265. //  Returns: None.
  266. //
  267. void DrawPiece(HWND hWnd, short f)
  268.   {
  269.   POINTL aptl[4];
  270.   RECTL  rcl;
  271.   short  x,y;
  272.  
  273.  
  274.   //
  275.   //  Compute the (x,y) coordinate of the piece to draw.
  276.   //
  277.   if (flag.reverse)
  278.     {
  279.     x = 7 - (f % 8);
  280.     y = 7 - (f / 8);
  281.     }
  282.    else
  283.     {
  284.     x = f % 8;
  285.     y = f / 8;
  286.     }
  287.  
  288.   //
  289.   //  Retrieve the corners of the piece to redraw.
  290.   //
  291.   QuerySqCoords(x, y, aptl);
  292.  
  293.   //
  294.   //  Invalidate the area around the piece to redraw.
  295.   //
  296.   rcl.xLeft   = aptl[0].x - 1;
  297.   rcl.yBottom = aptl[0].y;
  298.   rcl.xRight  = aptl[2].x + 1;
  299.   rcl.yTop    = aptl[2].y;
  300.   WinInvalidateRect(hWnd, &rcl, FALSE);
  301.   }
  302.  
  303.  
  304. void
  305. UpdateDisplay (HWND hWnd, short int f, short int t, short int redraw, short int isspec)
  306. {
  307.   short sq;
  308.   
  309.   for (sq=0; sq<64; sq++) {
  310.          boarddraw[sq] = board[sq];
  311.          colordraw[sq] = color[sq];
  312.   }
  313.  
  314.   if (redraw){
  315.       WinInvalidateRect ( hWnd, NULL, TRUE);
  316.       ShowPlayers ();
  317.       WinUpdateWindow ( hWnd );
  318.   } else {
  319.       DrawPiece (hWnd, f);
  320.       DrawPiece (hWnd, t);
  321.       if (isspec & cstlmask)
  322.         if (t > f)
  323.           {
  324.             DrawPiece (hWnd, f + 3);
  325.             DrawPiece (hWnd, t - 1);
  326.           }
  327.         else
  328.           {
  329.             DrawPiece (hWnd, f - 4);
  330.             DrawPiece (hWnd, t + 1);
  331.           }
  332.       else if (isspec & epmask)
  333.         {
  334.           DrawPiece (hWnd, t - 8);
  335.           DrawPiece (hWnd, t + 8);
  336.         }
  337.       WinUpdateWindow (hWnd);
  338.     }
  339. }
  340.  
  341. void
  342. GiveHint (HWND hWnd)
  343. {
  344.   char s[40];
  345.   algbr ((short) (hint >> 8), (short) (hint & 0xFF), false);
  346.   strcpy (s, "try ");
  347.   strcat (s, mvstr[0]);
  348.   ShowMessage (hWnd, s);
  349. }
  350.