📄 windsp.c
字号:
/*
* windsp.c - Windows interface for CHESS
*
* Copyright (c) 1996 Conor McCarthy
* Contains code from uxdsp.c (Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation)
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "gnuchess.h"
#include "ataks.h"
#include <ctype.h>
#include <signal.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#define ESC 0x1B
extern SHORT pscore[2];
#define TAB (46)
#define VIR_C(s) ((flag.reverse) ? 7-column(s) : column(s))
#define VIR_R(s) ((flag.reverse) ? 7-row(s) : row(s))
UTSHORT MV[MAXDEPTH+1];
int MSCORE;
CHAR *DRAW;
POINT boardpg[4];
POINT squares[8][8][4];
POINT pieceloc[64];
struct bitmaps pieces[7];
SHORT origbrd[64],origcol[64];
extern char szBtnBar[];
SHORT button;
extern SHORT selected,selectX,selectY;
extern char lpStatic[];
HWND hBtnWnd;
DWORD clrBackGround;
DWORD clrBlackSquare;
DWORD clrWhiteSquare;
DWORD clrBlackPiece;
DWORD clrWhitePiece;
DWORD clrText;
DWORD clrEdge;
SHORT sqwidthF;
SHORT sqwidthB;
SHORT sqdepth;
SHORT boardsize=SMALL;
SHORT deltaX,bmsize;
void DrawButton(HDC,SHORT,BOOL,BOOL);
void
EditBoard (void)
{
UTSHORT sq,f,t;
HDC hDC;
HMENU hMainMenu,hEditMenu;
button=0;
flag.editing=true;
hBtnWnd = CreateWindow(szBtnBar,"",WS_OVERLAPPED|WS_SYSMENU,
100,0,bmsize*10+49+GetSystemMetrics(SM_CXBORDER)*2,
bmsize+4+GetSystemMetrics(SM_CYCAPTION)
+GetSystemMetrics(SM_CYBORDER),
hWnd,NULL,hInst,NULL);
ShowWindow(hBtnWnd,SW_SHOWNORMAL);
hEditMenu=LoadMenu(hInst,"EDIT");
hMainMenu=GetMenu(hWnd);
SetMenu(hWnd,hEditMenu);
flag.regularstart = true;
Book = BOOKFAIL;
do
{
while (!command)CheckMessage();
if (command==1)
{
if (flag.quit)Exit(0);
command=0;
if (strlen(move)==2)
{
t=(UTSHORT)(move[0]-'a'+(move[1]-'1')*8);
if (t>63) {ShowMessage(CP[71]); continue; }
if (!button)
{
board[t]=no_piece;
color[t]=neutral;
hDC=GetDC(hWnd);
DrawPiece(t,hDC);
ReleaseDC(hWnd,hDC);
continue;
}
else move[0]=0;
}
else t = (UTSHORT)(move[2]-'a'+(move[3]-'1')*8);
if (board[t]==king)
{
ShowMessage(CP[72]);
command=0;
continue;
}
if (button && !move[0])
/* A button is down on the button bar
and the left mouse button was pressed*/
{
board[t]=button>queen?button-5:button;
color[t]=button>queen?black:white;
hDC=GetDC(hWnd);
DrawPiece(t,hDC);
ReleaseDC(hWnd,hDC);
}
else
{
f=(UTSHORT)(move[0]-'a'+(move[1]-'1')*8);
if (f==t) /*from and to are equal - clear the square*/
{
board[f]=no_piece;
color[f]=neutral;
}
else /*make the move*/
{
board[t]=board[f];
color[t]=color[f];
board[f]=no_piece;
color[f]=neutral;
}
UpdateDisplay(f,t,0,0,0);
}
}
}
while (command!=IDM_DONE);
for (sq = 0; sq < 64; sq++)
Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
GameCnt = 0;
Game50 = 1;
ZeroRPT ();
Sdepth = 0;
InitializeStats ();
SetMenu(hWnd,hMainMenu);
DestroyMenu(hEditMenu);
DestroyWindow(hBtnWnd);
button=command=0;
flag.editing=false;
}
LRESULT WINAPI BtnWndProc(HWND hBtnWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
HDC hDC;
HPEN hOldPen;
HRGN hRgn;
PAINTSTRUCT ps;
SHORT i;
switch (message)
{
case WM_PAINT:
hDC=BeginPaint(hBtnWnd,&ps);
for (i=pawn;i<=queen+5;i++) DrawButton(hDC,i,i==button? true:false,false);
hOldPen=SelectObject(hDC,GetStockObject(BLACK_PEN));
for (i=bmsize+4;i<(bmsize+5)*10;i+=bmsize+5)
{
MoveToEx(hDC,i,0,0);
LineTo(hDC,i,bmsize+4);
}
SelectObject(hDC,hOldPen);
EndPaint(hBtnWnd,&ps);
return 0;
case WM_KEYDOWN:
if (wParam>='0' && wParam<='9')
{
wParam-='0';
if (!wParam) wParam=10;
lParam=--wParam*(bmsize+5)+pawn; /* - */
} /* | */
else break; /* | */
case WM_LBUTTONDOWN: /* | */
if (selected) /* <- */
{
selected=0;
hRgn=CreatePolygonRgn(&squares[selectX][selectY][0],
4, ALTERNATE);
hDC=GetDC(hWnd);
InvertRgn(hDC,hRgn); /*restore square to normal*/
ReleaseDC(hWnd,hDC);
DeleteObject(hRgn);
}
i=LOWORD(lParam)/(bmsize+5)+pawn;
hDC=GetDC(hBtnWnd);
if (button) DrawButton(hDC,button,false,true);
if (i!=button)
{DrawButton(hDC,i,true,true);
button=i;
}
else button=0;
ReleaseDC(hBtnWnd,hDC);
return 0;
}
return DefWindowProc(hBtnWnd,message,wParam,lParam);
}
void DrawButton(HDC hDC,SHORT bn,BOOL down,BOOL changed)
{
HPEN hDkPen,hOldPen;
HDC hMemDC;
HBITMAP hBmpOld;
SHORT x,piece;
COLORREF color;
if (bn>queen) {color=clrBlackPiece; piece=bn-5;}
else {color=clrWhitePiece; piece=bn;}
x=(bn-pawn)*(bmsize+5);
hOldPen=SelectObject(hDC,GetStockObject(NULL_PEN));
if (changed)
{
SelectObject(hDC,GetStockObject(LTGRAY_BRUSH));
Rectangle(hDC,x,0,x+bmsize+5,bmsize+5);
}
hDkPen=CreatePen(PS_SOLID,1,RGB(128,128,128));
if (!down)SelectObject(hDC,GetStockObject(WHITE_PEN));
else SelectObject(hDC,hDkPen);
MoveToEx(hDC,x,bmsize+3,0); /*MoveTo not implemented in Win32*/
LineTo(hDC,x,0);
LineTo(hDC,x+bmsize+4,0);
MoveToEx(hDC,x+1,bmsize+2+down,0);
LineTo(hDC,x+1,1);
LineTo(hDC,x+bmsize+3+down,1);
if (!down)
{
SelectObject(hDC,hDkPen);
MoveToEx(hDC,x,bmsize+3,0);
LineTo(hDC,x+bmsize+3,bmsize+3);
LineTo(hDC,x+bmsize+3,0);
MoveToEx(hDC,x+1,bmsize+2,0);
LineTo(hDC,x+bmsize+2,bmsize+2);
LineTo(hDC,x+bmsize+2,1);
}
SelectObject(hDC,hOldPen);
DeleteObject(hDkPen);
hMemDC = CreateCompatibleDC(hDC);
SetTextColor(hDC,CBLACK);
SetBkColor(hDC,CWHITE);
hBmpOld=SelectObject(hMemDC, pieces[piece].mask);
BitBlt(hDC, (bn-pawn)*(bmsize+5)+down, 2+down, bmsize, bmsize,
hMemDC, 0, 0, SRCAND);
SelectObject(hMemDC, pieces[piece].detail);
SetBkColor(hDC,color);
BitBlt(hDC, (bn-pawn)*(bmsize+5)+down, 2+down, bmsize, bmsize,
hMemDC, 0, 0, SRCPAINT);
SelectObject(hMemDC,hBmpOld);
DeleteDC(hMemDC);
}
void
ShowPlayers (void)
{
SetWindowText ( hComputerColor, (computer == black) ? CP[73] : CP[74]);
}
void
ShowDepth (CHAR ch)
{
sprintf (msg,CP[19], Sdepth, ch); /*Depth= %d%c*/
SetWindowText(hDepth,msg);
}
void
ShowScore (SHORT score)
{
sprintf (msg, "%d", (int)score);
SetDlgItemText(hStats,IDC_SCORE,msg);
}
void
ShowMessage (CHAR *s)
{
MessageBox(hWnd,s,szAppName,MB_OK);
}
void
ShowCurrentMove (SHORT pnt, SHORT f, SHORT t)
{
sprintf (msg,"(%2d) %4s", pnt, mvstr[0]);
SetDlgItemText(hStats,IDC_POS,msg);
}
void
ShowSidetoMove (void)
{
if(!flag.mate)
{
sprintf (msg,CP[75],ColorStr[player]);
SetWindowText ( hWhoseTurn, msg);
}
else SetWindowText ( hWhoseTurn, "Checkmate");
if (SqAtakd (PieceList[player][0], player^1))
{
sprintf(msg,CP[76],ColorStr[player]);
SetWindowText ( hInCheck, msg);
}
else
{
SetWindowText ( hInCheck, "");
}
}
void
ShowNodeCnt (long int NodeCnt)
{
sprintf (msg,"%ld", NodeCnt);
SetDlgItemText(hStats,IDC_NODE,msg);
sprintf(msg,"%ld", (et>=100) ? NodeCnt / (et / 100) : 0);
SetDlgItemText(hStats,IDC_NODESEC,msg);
}
void
ShowResults (SHORT score, UTSHORT *bstline, CHAR ch)
{
UCHAR d, ply;
if (flag.post)
{
SHORT len=0;
ShowDepth (ch);
ShowScore (score);
d = 7;
for (ply = 1; bstline[ply] > 0; ply++)
{
algbr ((SHORT) bstline[ply] >> 8, (SHORT) bstline[ply] & 0xFF, false);
len+=sprintf (msg+len,"%s ", mvstr[0]);
}
msg[len]='\0';
SetDlgItemText(hStats,IDC_BESTLINE,msg);
}
}
void
OutputMove (SHORT score)
{
UpdateDisplay (root->f, root->t, 0, (SHORT) root->flags, 0);
if(flag.illegal){MessageBox(hWnd,CP[58],"",MB_OK);return;}
if(mvstr[0][0])
{
sprintf (msg,CP[30], mvstr[0]); /*My move is %s*/
SetWindowText ( hComputerMove, msg);
}
if (flag.beep)
MessageBeep(0);
if (root->flags & draw)
MessageBox (hWnd,CP[21],"",MB_OK);
else if (root->score == -9999)
MessageBox (hWnd,CP[33],"",MB_OK);
else if (root->score == 9998)
MessageBox (hWnd,CP[15],"",MB_OK);
#ifdef VERYBUGGY
else if (root->score < -9000)
MessageBox (hWnd,CP[34],"",MB_OK);
else if (root->score > 9000)
MessageBox (hWnd,CP[16],"",MB_OK);
#endif /*VERYBUGGY*/
if (flag.post)
{
register SHORT h, l, t;
h = TREE;
l = 0;
t = TREE >> 1;
while (l != t)
{
if (Tree[t].f || Tree[t].t)
l = t;
else
h = t;
t = (l + h) >> 1;
}
ShowNodeCnt (NodeCnt);
sprintf (msg,"%d", (int)t); /*Max Tree=*/
SetDlgItemText(hStats,IDC_TREE,msg);
}
ShowSidetoMove ();
}
void
UpdateClocks (void)
{
SHORT m, s;
m = (SHORT) (et / 6000);
s = (SHORT) (et - 6000 * (long) m) / 100;
if (TCflag)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -