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