home *** CD-ROM | disk | FTP | other *** search
/ Más de 2,500 Juegos / CD1.iso / ZIPDAT / 0153 / 0153.ZIP / SRC / WINDSP.C < prev   
Encoding:
C/C++ Source or Header  |  1998-08-05  |  20.3 KB  |  827 lines

  1. /*
  2.  * windsp.c - Windows interface for CHESS
  3.  *
  4.  * Copyright (c) 1996 Conor McCarthy
  5.  * Contains code from uxdsp.c (Copyright (c) 1988,1989,1990 John Stanback
  6.  *                             Copyright (c) 1992 Free Software Foundation)
  7.  *
  8.  * This file is part of GNU CHESS.
  9.  *
  10.  * GNU Chess is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * GNU Chess is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with GNU Chess; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24. #include "gnuchess.h"
  25. #include "ataks.h"
  26. #include <ctype.h>
  27. #include <signal.h>
  28. #include <dos.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31.  
  32. #define ESC 0x1B
  33.  
  34. extern SHORT pscore[2];
  35.  
  36. #define TAB (46)
  37. #define VIR_C(s)  ((flag.reverse) ? 7-column(s) : column(s))
  38. #define VIR_R(s)  ((flag.reverse) ? 7-row(s) : row(s))
  39.  
  40. UTSHORT MV[MAXDEPTH+1];
  41. int MSCORE;
  42. CHAR *DRAW;
  43.  
  44. POINT boardpg[4];
  45. POINT squares[8][8][4];
  46. POINT pieceloc[64];
  47. struct bitmaps pieces[7];
  48. SHORT origbrd[64],origcol[64];
  49. extern char szBtnBar[];
  50. SHORT button;
  51. extern SHORT selected,selectX,selectY;
  52. extern char lpStatic[];
  53. HWND hBtnWnd;
  54.  
  55. DWORD clrBackGround;
  56. DWORD clrBlackSquare;
  57. DWORD clrWhiteSquare;
  58. DWORD clrBlackPiece;
  59. DWORD clrWhitePiece;
  60. DWORD clrText;
  61. DWORD clrEdge;
  62.  
  63. SHORT sqwidthF;
  64. SHORT sqwidthB;
  65. SHORT sqdepth;
  66. SHORT boardsize=SMALL;
  67. SHORT deltaX,bmsize;
  68.  
  69. void DrawButton(HDC,SHORT,BOOL,BOOL);
  70.  
  71. void
  72. EditBoard (void)
  73.  
  74. {
  75.   UTSHORT sq,f,t;
  76.   HDC hDC;
  77.   HMENU hMainMenu,hEditMenu;
  78.  
  79.   button=0;
  80.   flag.editing=true;
  81.   hBtnWnd = CreateWindow(szBtnBar,"",WS_OVERLAPPED|WS_SYSMENU,
  82.                100,0,bmsize*10+49+GetSystemMetrics(SM_CXBORDER)*2,
  83.                bmsize+4+GetSystemMetrics(SM_CYCAPTION)
  84.                  +GetSystemMetrics(SM_CYBORDER),
  85.                hWnd,NULL,hInst,NULL);
  86.   ShowWindow(hBtnWnd,SW_SHOWNORMAL);
  87.   hEditMenu=LoadMenu(hInst,"EDIT");
  88.   hMainMenu=GetMenu(hWnd);
  89.   SetMenu(hWnd,hEditMenu);
  90.   flag.regularstart = true;
  91.   Book = BOOKFAIL;
  92.   do
  93.   {
  94.    while (!command)CheckMessage();
  95.    if (command==1)
  96.     {
  97.      if (flag.quit)Exit(0);
  98.      command=0;
  99.      if (strlen(move)==2)
  100.       {
  101.        t=(UTSHORT)(move[0]-'a'+(move[1]-'1')*8);
  102.        if (t>63) {ShowMessage(CP[71]); continue; }
  103.        if (!button)
  104.         {
  105.          board[t]=no_piece;
  106.          color[t]=neutral;
  107.          hDC=GetDC(hWnd);
  108.          DrawPiece(t,hDC);
  109.          ReleaseDC(hWnd,hDC);
  110.          continue;
  111.         }
  112.        else move[0]=0;
  113.       }
  114.      else t = (UTSHORT)(move[2]-'a'+(move[3]-'1')*8);
  115.      if (board[t]==king)
  116.       {
  117.        ShowMessage(CP[72]);
  118.        command=0;
  119.        continue;
  120.       }
  121.      if (button && !move[0])
  122.       /* A button is down on the button bar
  123.          and the left mouse button was pressed*/
  124.       {
  125.        board[t]=button>queen?button-5:button;
  126.        color[t]=button>queen?black:white;
  127.        hDC=GetDC(hWnd);
  128.        DrawPiece(t,hDC);
  129.        ReleaseDC(hWnd,hDC);
  130.       }
  131.      else
  132.       {
  133.        f=(UTSHORT)(move[0]-'a'+(move[1]-'1')*8);
  134.        if (f==t)  /*from and to are equal - clear the square*/
  135.         {
  136.          board[f]=no_piece;
  137.          color[f]=neutral;
  138.         }
  139.        else    /*make the move*/
  140.         {
  141.          board[t]=board[f];
  142.          color[t]=color[f];
  143.          board[f]=no_piece;
  144.          color[f]=neutral;
  145.         }
  146.        UpdateDisplay(f,t,0,0,0);
  147.       }
  148.     }
  149.   }
  150.   while (command!=IDM_DONE);
  151.   for (sq = 0; sq < 64; sq++)
  152.     Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
  153.   GameCnt = 0;
  154.   Game50 = 1;
  155.   ZeroRPT ();
  156.   Sdepth = 0;
  157.   InitializeStats ();
  158.   SetMenu(hWnd,hMainMenu);
  159.   DestroyMenu(hEditMenu);
  160.   DestroyWindow(hBtnWnd);
  161.   button=command=0;
  162.   flag.editing=false;
  163. }
  164.  
  165. LRESULT WINAPI BtnWndProc(HWND hBtnWnd, UINT message, WPARAM wParam,
  166.                         LPARAM lParam)
  167. {
  168.  HDC hDC;
  169.  HPEN hOldPen;
  170.  HRGN hRgn;
  171.  PAINTSTRUCT ps;
  172.  SHORT i;
  173.  
  174.  switch (message)
  175.   {
  176.    case WM_PAINT:
  177.      hDC=BeginPaint(hBtnWnd,&ps);
  178.      for (i=pawn;i<=queen+5;i++) DrawButton(hDC,i,i==button? true:false,false);
  179.      hOldPen=SelectObject(hDC,GetStockObject(BLACK_PEN));
  180.      for (i=bmsize+4;i<(bmsize+5)*10;i+=bmsize+5)
  181.       {
  182.        MoveToEx(hDC,i,0,0);
  183.        LineTo(hDC,i,bmsize+4);
  184.       }
  185.      SelectObject(hDC,hOldPen);
  186.      EndPaint(hBtnWnd,&ps);
  187.      return 0;
  188.  
  189.    case WM_KEYDOWN:
  190.      if (wParam>='0' && wParam<='9')
  191.       {
  192.        wParam-='0';
  193.        if (!wParam) wParam=10;
  194.        lParam=--wParam*(bmsize+5)+pawn;  /*   -   */
  195.       }                                  /*    |  */
  196.      else break;                         /*    |  */
  197.    case WM_LBUTTONDOWN:                  /*    |  */
  198.      if (selected)                       /*  <-   */
  199.       {
  200.        selected=0;
  201.        hRgn=CreatePolygonRgn(&squares[selectX][selectY][0],
  202.               4, ALTERNATE);
  203.        hDC=GetDC(hWnd);
  204.        InvertRgn(hDC,hRgn);  /*restore square to normal*/
  205.        ReleaseDC(hWnd,hDC);
  206.        DeleteObject(hRgn);
  207.       }
  208.      i=LOWORD(lParam)/(bmsize+5)+pawn;
  209.      hDC=GetDC(hBtnWnd);
  210.      if (button) DrawButton(hDC,button,false,true);
  211.      if (i!=button)
  212.       {DrawButton(hDC,i,true,true);
  213.        button=i;
  214.       }
  215.      else button=0;
  216.      ReleaseDC(hBtnWnd,hDC);
  217.      return 0;
  218.   }
  219.  return DefWindowProc(hBtnWnd,message,wParam,lParam);
  220. }
  221.  
  222. void DrawButton(HDC hDC,SHORT bn,BOOL down,BOOL changed)
  223. {
  224.  HPEN hDkPen,hOldPen;
  225.  HDC hMemDC;
  226.  HBITMAP hBmpOld;
  227.  SHORT x,piece;
  228.  COLORREF color;
  229.  
  230.  if (bn>queen) {color=clrBlackPiece; piece=bn-5;}
  231.  else {color=clrWhitePiece; piece=bn;}
  232.  x=(bn-pawn)*(bmsize+5);
  233.  hOldPen=SelectObject(hDC,GetStockObject(NULL_PEN));
  234.  if (changed)
  235.   {
  236.    SelectObject(hDC,GetStockObject(LTGRAY_BRUSH));
  237.    Rectangle(hDC,x,0,x+bmsize+5,bmsize+5);
  238.   }
  239.  hDkPen=CreatePen(PS_SOLID,1,RGB(128,128,128));
  240.  if (!down)SelectObject(hDC,GetStockObject(WHITE_PEN));
  241.  else SelectObject(hDC,hDkPen);
  242.  MoveToEx(hDC,x,bmsize+3,0); /*MoveTo not implemented in Win32*/
  243.  LineTo(hDC,x,0);
  244.  LineTo(hDC,x+bmsize+4,0);
  245.  MoveToEx(hDC,x+1,bmsize+2+down,0);
  246.  LineTo(hDC,x+1,1);
  247.  LineTo(hDC,x+bmsize+3+down,1);
  248.  if (!down)
  249.   {
  250.    SelectObject(hDC,hDkPen);
  251.    MoveToEx(hDC,x,bmsize+3,0);
  252.    LineTo(hDC,x+bmsize+3,bmsize+3);
  253.    LineTo(hDC,x+bmsize+3,0);
  254.    MoveToEx(hDC,x+1,bmsize+2,0);
  255.    LineTo(hDC,x+bmsize+2,bmsize+2);
  256.    LineTo(hDC,x+bmsize+2,1);
  257.   }
  258.  SelectObject(hDC,hOldPen);
  259.  DeleteObject(hDkPen);
  260.  hMemDC = CreateCompatibleDC(hDC);
  261.  SetTextColor(hDC,CBLACK);
  262.  SetBkColor(hDC,CWHITE);
  263.  hBmpOld=SelectObject(hMemDC, pieces[piece].mask);
  264.  BitBlt(hDC, (bn-pawn)*(bmsize+5)+down, 2+down, bmsize, bmsize,
  265.         hMemDC, 0, 0, SRCAND);
  266.  SelectObject(hMemDC, pieces[piece].detail);
  267.  SetBkColor(hDC,color);
  268.  BitBlt(hDC, (bn-pawn)*(bmsize+5)+down, 2+down, bmsize, bmsize,
  269.         hMemDC, 0, 0, SRCPAINT);
  270.  SelectObject(hMemDC,hBmpOld);
  271.  DeleteDC(hMemDC);
  272. }
  273.  
  274. void
  275. ShowPlayers (void)
  276. {
  277.   SetWindowText ( hComputerColor, (computer == black) ? CP[73] : CP[74]);
  278. }
  279.  
  280. void
  281. ShowDepth (CHAR ch)
  282. {
  283.   sprintf (msg,CP[19], Sdepth, ch); /*Depth= %d%c*/
  284.   SetWindowText(hDepth,msg);
  285. }
  286.  
  287. void
  288. ShowScore (SHORT score)
  289. {
  290.   sprintf (msg, "%d", (int)score);
  291.   SetDlgItemText(hStats,IDC_SCORE,msg);
  292. }
  293.  
  294. void
  295. ShowMessage (CHAR *s)
  296. {
  297.   MessageBox(hWnd,s,szAppName,MB_OK);
  298. }
  299.  
  300. void
  301. ShowCurrentMove (SHORT pnt, SHORT f, SHORT t)
  302. {
  303.   sprintf (msg,"(%2d) %4s", pnt, mvstr[0]);
  304.   SetDlgItemText(hStats,IDC_POS,msg);
  305. }
  306.  
  307. void
  308. ShowSidetoMove (void)
  309. {
  310.  if(!flag.mate)
  311.   {
  312.    sprintf (msg,CP[75],ColorStr[player]);
  313.    SetWindowText ( hWhoseTurn, msg);
  314.   }
  315.  else SetWindowText ( hWhoseTurn, "Checkmate");
  316.  if (SqAtakd (PieceList[player][0], player^1))
  317.   {
  318.    sprintf(msg,CP[76],ColorStr[player]);
  319.    SetWindowText ( hInCheck, msg);
  320.   }
  321.  else
  322.   {
  323.    SetWindowText ( hInCheck, "");
  324.   }
  325. }
  326.  
  327. void
  328. ShowNodeCnt (long int NodeCnt)
  329. {
  330.  sprintf (msg,"%ld", NodeCnt);
  331.  SetDlgItemText(hStats,IDC_NODE,msg);
  332.  sprintf(msg,"%ld", (et>=100) ? NodeCnt / (et / 100) : 0);
  333.  SetDlgItemText(hStats,IDC_NODESEC,msg);
  334. }
  335.  
  336. void
  337. ShowResults (SHORT score, UTSHORT *bstline, CHAR ch)
  338. {
  339.   UCHAR d, ply;
  340.  
  341.   if (flag.post)
  342.     {
  343.       SHORT len=0;
  344.       ShowDepth (ch);
  345.       ShowScore (score);
  346.       d = 7;
  347.       for (ply = 1; bstline[ply] > 0; ply++)
  348.    {
  349.      algbr ((SHORT) bstline[ply] >> 8, (SHORT) bstline[ply] & 0xFF, false);
  350.      len+=sprintf (msg+len,"%s ", mvstr[0]);
  351.    }
  352.       msg[len]='\0';
  353.       SetDlgItemText(hStats,IDC_BESTLINE,msg);
  354.     }
  355. }
  356.  
  357. void
  358. OutputMove (SHORT score)
  359. {
  360.   UpdateDisplay (root->f, root->t, 0, (SHORT) root->flags, 0);
  361.   if(flag.illegal){MessageBox(hWnd,CP[58],"",MB_OK);return;}
  362.   if(mvstr[0][0])
  363.    {
  364.     sprintf (msg,CP[30], mvstr[0]); /*My move is %s*/
  365.     SetWindowText ( hComputerMove, msg);
  366.    }
  367.  
  368.   if (flag.beep)
  369.     MessageBeep(0);
  370.  
  371.   if (root->flags & draw)
  372.     MessageBox (hWnd,CP[21],"",MB_OK);
  373.   else if (root->score == -9999)
  374.     MessageBox (hWnd,CP[33],"",MB_OK);
  375.   else if (root->score == 9998)
  376.     MessageBox (hWnd,CP[15],"",MB_OK);
  377. #ifdef VERYBUGGY
  378.   else if (root->score < -9000)
  379.     MessageBox (hWnd,CP[34],"",MB_OK);
  380.   else if (root->score > 9000)
  381.     MessageBox (hWnd,CP[16],"",MB_OK);
  382. #endif /*VERYBUGGY*/
  383.   if (flag.post)
  384.     {
  385.       register SHORT h, l, t;
  386.  
  387.       h = TREE;
  388.       l = 0;
  389.       t = TREE >> 1;
  390.       while (l != t)
  391.    {
  392.      if (Tree[t].f || Tree[t].t)
  393.        l = t;
  394.      else
  395.        h = t;
  396.      t = (l + h) >> 1;
  397.    }
  398.  
  399.       ShowNodeCnt (NodeCnt);
  400.       sprintf (msg,"%d", (int)t);   /*Max Tree=*/
  401.       SetDlgItemText(hStats,IDC_TREE,msg);
  402.     }
  403.   ShowSidetoMove ();
  404. }
  405.  
  406. void
  407. UpdateClocks (void)
  408. {
  409.   SHORT m, s;
  410.  
  411.   m = (SHORT) (et / 6000);
  412.   s = (SHORT) (et - 6000 * (long) m) / 100;
  413.   if (TCflag)
  414.     {
  415.       m = (SHORT) ((TimeControl.clock[player] - et) / 6000);
  416.       s = (SHORT) ((TimeControl.clock[player] - et - 6000 * (long) m) / 100);
  417.     }
  418.   if (m < 0)
  419.     m = 0;
  420.   if (s < 0)
  421.     s = 0;
  422.   sprintf (msg,"%d:%02d", m, s);
  423.   (player == white)? SetWindowText (hClockWhite, msg):
  424.                      SetWindowText (hClockBlack, msg);
  425.   if (flag.post && (!flag.easy || player==computer))
  426.     ShowNodeCnt (NodeCnt);
  427. }
  428.  
  429. void
  430. DrawPiece (SHORT sq,HDC hDC)
  431. {
  432.  HBRUSH hBrush_lt,hBrush_dk,hOldBrush;
  433.  HPEN hOldPen;
  434.  HDC hMemDC;
  435.  HBITMAP hBMPold;
  436.  SHORT sqloc,*brdptr,*colptr;
  437.  
  438.  if (flag.searching || flag.replay) {brdptr=&origbrd; colptr=&origcol;}
  439.  else {brdptr=&board; colptr=&color;}
  440.  if (flag.reverse)sqloc=63-sq;
  441.    else sqloc=sq;
  442.  hBrush_lt = CreateSolidBrush ( clrWhiteSquare );
  443.  hBrush_dk = CreateSolidBrush ( clrBlackSquare );
  444.  hOldBrush = SelectObject ( hDC, hBrush_lt);
  445.  hOldPen   = SelectObject ( hDC, GetStockObject (BLACK_PEN) );
  446.  if (((sq+sq/8)&1)==0) SelectObject(hDC,hBrush_dk);
  447.     else SelectObject(hDC,hBrush_lt);
  448.  Polygon(hDC,&squares[sqloc%8][sqloc/8][0],4);
  449.  SelectObject(hDC,hOldBrush);
  450.  SelectObject(hDC,hOldPen);
  451.  DeleteObject(hBrush_lt);
  452.  DeleteObject(hBrush_dk);
  453.  if (*(brdptr+sq)!=no_piece)
  454.   {hMemDC = CreateCompatibleDC(hDC);
  455.    hBMPold = SelectObject(hMemDC, pieces[*(brdptr+sq)].mask);
  456.    SetBkColor(hDC,CWHITE);
  457.    SetTextColor(hDC,CBLACK);
  458.    BitBlt(hDC, pieceloc[sqloc].x, pieceloc[sqloc].y, bmsize, bmsize,
  459.           hMemDC, 0, 0, SRCAND);
  460.    SelectObject(hMemDC, pieces[*(brdptr+sq)].detail);
  461.    if (*(colptr+sq)==black)SetBkColor(hDC,clrBlackPiece);
  462.       else SetBkColor(hDC,clrWhitePiece);
  463.    BitBlt(hDC, pieceloc[sqloc].x, pieceloc[sqloc].y, bmsize, bmsize,
  464.           hMemDC, 0, 0, SRCPAINT);
  465.    SelectObject(hMemDC, hBMPold);
  466.    DeleteDC(hMemDC);
  467.   }
  468. }
  469.  
  470. void
  471. ShowPostnValue (SHORT sq)
  472.  
  473. /*
  474.  * must have called ExaminePosition() first
  475.  */
  476.  
  477. {
  478. /*  SHORT score;
  479.  
  480.   gotoXY (4 + 5 * VIR_C (sq), 5 + 2 * (7 - VIR_R (sq)));
  481.   score = ScorePosition (color[sq]);
  482.   if (color[sq] != neutral)
  483.     {sprintf (msg,"%3d ", svalue[sq]);
  484.      printz(msg);}
  485.   else
  486.     printz ("   ");  */
  487. }
  488.  
  489. void
  490. ShowPostnValues (void)
  491. {
  492. /*  SHORT sq, score;
  493.  
  494.   ExaminePosition ();
  495.   for (sq = 0; sq < 64; sq++)
  496.     ShowPostnValue (sq);
  497.   score = ScorePosition (opponent);
  498.   gotoXY (TAB, 5);
  499.   sprintf (msg,CP[35], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  500.   printz(msg);
  501.  
  502.   ClrEoln (); */
  503. }
  504.  
  505. void
  506. UpdateDisplay (SHORT f, SHORT t, SHORT redraw, SHORT isspec,HDC hDC)
  507. {
  508.   SHORT i, sq;
  509.   int x, y;
  510.   HBRUSH hOldBrush, hBrush_lt, hBrush_dk;
  511.   HPEN hOldPen;
  512.   BOOL DCsupplied=true;
  513.  
  514.   if (!hDC) {hDC=GetDC(hWnd); DCsupplied=false;}
  515.   if (redraw)
  516.     {
  517.    hBrush_lt = CreateSolidBrush ( clrWhiteSquare );
  518.    hBrush_dk = CreateSolidBrush ( clrBlackSquare );
  519.  
  520.    hOldBrush = SelectObject ( hDC, hBrush_lt);
  521.    hOldPen   = SelectObject ( hDC, GetStockObject (BLACK_PEN) );
  522.  
  523.    Polygon(hDC,&boardpg,4);
  524.    SelectObject(hDC,hBrush_dk);
  525.    for (y=0;y<8;y++)
  526.       for (x=y&1;x<8;x+=2)Polygon(hDC,&squares[x][y][0],4);
  527.    SelectObject(hDC,hOldBrush);
  528.    if (flag.searching || flag.replay)
  529.     {
  530.      for (sq=0;sq<64;sq++)
  531.      if (origbrd[sq]!=no_piece)DrawPiece(sq,hDC);
  532.     }
  533.    else
  534.     {
  535.      for (sq=0;sq<64;sq++)
  536.      if (board[sq]!=no_piece)DrawPiece(sq,hDC);
  537.     }
  538.    DeleteObject(hBrush_lt);
  539.    DeleteObject(hBrush_dk);
  540.    SelectObject(hDC,hFont);
  541.    SetBkMode(hDC,TRANSPARENT);
  542.    SetTextColor(hDC,clrText);
  543.    if (flag.coords)
  544.    for (i=0;i<8;i++)
  545.     {
  546.      y=sqdepth*i+(sqdepth-LineSpace)/2;
  547.      x=LEFTMARGIN+deltaX/2-deltaX/2*y/(sqdepth*8)-CharWidth-8;
  548.      TextOut(hDC,x,y+BACKMARGIN,flag.reverse?CP[60]+i :
  549.              "87654321"+i,1);
  550.      TextOut(hDC,LEFTMARGIN+i*sqwidthF+(sqwidthF-CharWidth)/2,BACKMARGIN+
  551.          sqdepth*8+BRD_EDGE,flag.reverse?"hgfedcba"+i:CP[59]+i,1);
  552.     }
  553.    hBrush_dk=CreateSolidBrush(clrEdge);
  554.    SelectObject(hDC,hBrush_dk);
  555.    if(!squarebd)
  556.      Rectangle(hDC,boardpg[0].x,boardpg[0].y,
  557.          boardpg[1].x+1,boardpg[1].y+BRD_EDGE);
  558.    SelectObject(hDC,hOldBrush);
  559.    SelectObject(hDC,hOldPen);
  560.    DeleteObject(hBrush_dk);
  561.     }
  562.   else
  563.     {
  564.       DrawPiece (f,hDC);
  565.       DrawPiece (t,hDC);
  566.       if (isspec & cstlmask)
  567.    if (t > f)
  568.      {
  569.        DrawPiece (f + 3,hDC);
  570.        DrawPiece (t - 1,hDC);
  571.      }
  572.    else
  573.      {
  574.        DrawPiece (f - 4,hDC);
  575.        DrawPiece (t + 1,hDC);
  576.      }
  577.       else if (isspec & epmask)
  578.    {
  579.      DrawPiece (t - 8,hDC);
  580.      DrawPiece (t + 8,hDC);
  581.    }
  582.     }
  583.   if (!DCsupplied)ReleaseDC(hWnd,hDC);
  584. }
  585.  
  586. extern CHAR *InPtr;
  587. void
  588. skip ()
  589. {
  590.   while (*InPtr != ' ' && *InPtr!=0)
  591.     InPtr++;
  592.   while (*InPtr == ' ')
  593.     InPtr++;
  594. }
  595. void
  596. skipb ()
  597. {
  598.   while (*InPtr == ' ')
  599.     InPtr++;
  600. }
  601.  
  602. void
  603. GiveHint (void)
  604. {
  605.   CHAR s[40];
  606.   if (hint)
  607.     {
  608.       algbr ((SHORT) (hint >> 8), (SHORT) (hint & 0xFF), false);
  609.       strcpy (s, CP[50]);  /*try*/
  610.       strcat (s, mvstr[0]);
  611.       ShowMessage (s);
  612.     }
  613.   else
  614.     ShowMessage (CP[56]);
  615. }
  616.  
  617. void Replay(void)
  618. {
  619.  SHORT i,f,t;
  620.  HWND hReplay;
  621.  HMENU hMenu,hMainMenu;
  622.  char message[36];
  623.  
  624.  flag.replay=true;
  625.  ShowWindow(hComputerColor,SW_HIDE);
  626.  ShowWindow(hWhoseTurn,SW_HIDE);
  627.  ShowWindow(hInCheck,SW_HIDE);
  628.  hReplay = CreateWindow (lpStatic, "",
  629.                    WS_CHILD | SS_LEFT | WS_VISIBLE,
  630.                    LEFTMARGIN, BACKMARGIN+sqdepth*8+20,
  631.                    600, SLineSpace,
  632.                    hWnd, (HMENU)0, hInst, NULL);
  633.  hMenu = CreateMenu ();
  634.  AppendMenu ( hMenu, MF_STRING, IDM_PREV,"&Previous");
  635.  AppendMenu ( hMenu, MF_STRING, IDM_NEXT,"&Next");
  636.  AppendMenu ( hMenu, MF_STRING, IDM_DONE,"&End");
  637.  hMainMenu = GetMenu ( hWnd);
  638.  SetMenu ( hWnd, hMenu);
  639.  EnableMenuItem(hMenu,IDM_PREV,MF_BYCOMMAND|MF_GRAYED);
  640.  for (i = 0; i < 64; i++)
  641.     {
  642.       origbrd[i] = Stboard[i];
  643.       origcol[i] = Stcolor[i];
  644.     }
  645.  UpdateDisplay(0,0,1,0,0);
  646.  i=1;
  647.  while(1)
  648.   {
  649.    DrawMenuBar(hWnd);
  650.    sprintf(message,CP[77],i);
  651.    SetWindowText(hReplay,message);
  652.    while (!command)CheckMessage();
  653.    if (command==IDM_DONE) break;
  654.    if (flag.quit)Exit(0);
  655.    if(command==IDM_NEXT)
  656.     {
  657.      f=GameList[i].gmove>>8;
  658.      t=GameList[i].gmove&255;
  659.      if (GameList[i].flags & cstlmask)
  660.       {
  661.        if (t>f)
  662.         {
  663.          origbrd[t-1]=origbrd[t+1];
  664.          origcol[t-1]=origcol[t+1];
  665.          origbrd[t+1]=no_piece;
  666.          origcol[t+1]=neutral;
  667.         }
  668.        else
  669.         {
  670.          origbrd[t+1]=origbrd[t-2];
  671.          origcol[t+1]=origcol[t-2];
  672.          origbrd[t-2]=no_piece;
  673.          origcol[t-2]=neutral;
  674.         }
  675.       }
  676.      if (GameList[i].flags & promote)
  677.        origbrd[f]=GameList[i].flags & pmask;
  678.      if (GameList[i].flags & epmask)
  679.       {
  680.        SHORT l;
  681.        l = t + ((t > f) ? -8 : 8);
  682.        board[l] = no_piece;
  683.        color[l] = neutral;
  684.       }
  685.      origbrd[t]=origbrd[f];
  686.      origcol[t]=origcol[f];
  687.      origbrd[f]=no_piece;
  688.      origcol[f]=neutral;
  689.      UpdateDisplay(f,t,0,GameList[i].flags,0);
  690.      i++;
  691.      if(i>GameCnt)EnableMenuItem(hMenu,IDM_NEXT,MF_BYCOMMAND|MF_GRAYED);
  692.      if(i==2)EnableMenuItem(hMenu,IDM_PREV,MF_BYCOMMAND|MF_ENABLED);
  693.     }
  694.    else if(command==IDM_PREV)
  695.     {
  696.      i--;
  697.      f=GameList[i].gmove>>8;
  698.      t=GameList[i].gmove&255;
  699.      if (GameList[i].flags & cstlmask)
  700.       {
  701.        if (t>f)
  702.         {
  703.          origbrd[t+1]=origbrd[t-1];
  704.          origcol[t+1]=origcol[t-1];
  705.          origbrd[t-1]=no_piece;
  706.          origcol[t-1]=neutral;
  707.         }
  708.        else
  709.         {
  710.          origbrd[t-2]=origbrd[t+1];
  711.          origcol[t-2]=origcol[t+1];
  712.          origbrd[t+1]=no_piece;
  713.          origcol[t+1]=neutral;
  714.         }
  715.       }
  716.      if (GameList[i].flags & promote)
  717.        origbrd[t]=pawn;
  718.      if (GameList[i].flags & epmask)
  719.       {
  720.        SHORT l;
  721.        l = t + ((t > f) ? -8 : 8);
  722.        board[l] = pawn;
  723.        color[l] = !GameList[i].color;
  724.       }
  725.      origbrd[f]=origbrd[t];
  726.      origcol[f]=origcol[t];
  727.      if(GameList[i].flags & capture)
  728.       {
  729.        origbrd[t]=GameList[i].piece;
  730.        origcol[t]=GameList[i].color;
  731.       }
  732.      else
  733.       {
  734.        origbrd[t]=no_piece;
  735.        origcol[t]=neutral;
  736.       }
  737.      UpdateDisplay(f,t,0,GameList[i].flags,0);
  738.      if(i==GameCnt)EnableMenuItem(hMenu,IDM_NEXT,MF_BYCOMMAND|MF_ENABLED);
  739.      if(i==1)EnableMenuItem(hMenu,IDM_PREV,MF_BYCOMMAND|MF_GRAYED);
  740.     }
  741.    command=0;
  742.   }
  743.  SetWindowText(hReplay,CP[78]);
  744.  command=0;
  745.  SetMenu(hWnd,hMainMenu);
  746.  DestroyMenu(hMenu);
  747.  flag.replay=false;
  748.  UpdateDisplay(0,0,1,0,0);
  749.  DestroyWindow(hReplay);
  750.  ShowWindow(hComputerColor,SW_SHOWNORMAL);
  751.  ShowWindow(hWhoseTurn,SW_SHOWNORMAL);
  752.  ShowWindow(hInCheck,SW_SHOWNORMAL);
  753. }
  754.  
  755. void
  756. DoDebug (void)
  757. {
  758.   SHORT c, p, sq, tp, tc, tsq, score;
  759.   CHAR s[40];
  760.  
  761.   ExaminePosition ();
  762.   ShowMessage (CP[22]);
  763.   scanz ("%s", s);
  764.   c = neutral;
  765.   if (s[0] == CP[7][0] || s[0] == CP[7][1])  /* w W*/
  766.     c = white;
  767.   if (s[0] == CP[7][2] || s[0] == CP[7][3])  /*b B*/
  768.     c = black;
  769.   for (p = king; p > no_piece; p--)
  770.     if ((s[1] == pxx[p]) || (s[1] == qxx[p]))
  771.       break;
  772.   for (sq = 0; sq < 64; sq++)
  773.     {
  774.       tp = board[sq];
  775.       tc = color[sq];
  776.       board[sq] = p;
  777.       color[sq] = c;
  778.       tsq = PieceList[c][1];
  779.       PieceList[c][1] = sq;
  780.       ShowPostnValue (sq);
  781.       PieceList[c][1] = tsq;
  782.       board[sq] = tp;
  783.       color[sq] = tc;
  784.     }
  785.   score = ScorePosition (opponent);
  786.   printz (CP[35], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  787.  
  788. }
  789. void
  790. DoTable (SHORT table[64])
  791. {
  792.   SHORT  sq;
  793.   ExaminePosition ();
  794.   for (sq=0;sq<64;sq++){
  795.   sprintf (msg,"%3d ", table[sq]);
  796.   printz(msg);
  797.  
  798. }
  799. }
  800. /*SHORT LdisplayLine;
  801. void Ldisplay1(){LdisplayLine=4; ClrScreen();UpdateDisplay (0, 0, 1, 0, 0); }
  802.  
  803. void Ldisplay2(){
  804.   refresh ();
  805.   getchar ();
  806.   ClrScreen ();
  807.   UpdateDisplay (0, 0, 1, 0, 0);
  808. }
  809.  
  810. void Ldisplay(char *m, char *h, SHORT count)
  811. {
  812.    gotoXY(50,LdisplayLine);
  813.    LdisplayLine++;
  814.    sprintf(msg,"%s\t%s\t%d\n",m,h,count);
  815.    printz(msg);
  816. }
  817. Ldisplay3()
  818. {ClrScreen();refresh();LdisplayLine=4;}
  819. void Ldisplay4(char *line)
  820. {
  821.         gotoXY(10,LdisplayLine);
  822.         LdisplayLine++;
  823.         sprintf(msg,"%s",line);
  824.         printz(msg);
  825.    refresh();
  826. }  */
  827.