📄 windsp.c
字号:
m = (SHORT) ((TimeControl.clock[player] - et) / 6000);
s = (SHORT) ((TimeControl.clock[player] - et - 6000 * (long) m) / 100);
}
if (m < 0)
m = 0;
if (s < 0)
s = 0;
sprintf (msg,"%d:%02d", m, s);
(player == white)? SetWindowText (hClockWhite, msg):
SetWindowText (hClockBlack, msg);
if (flag.post && (!flag.easy || player==computer))
ShowNodeCnt (NodeCnt);
}
void
DrawPiece (SHORT sq,HDC hDC)
{
HBRUSH hBrush_lt,hBrush_dk,hOldBrush;
HPEN hOldPen;
HDC hMemDC;
HBITMAP hBMPold;
SHORT sqloc,*brdptr,*colptr;
if (flag.searching || flag.replay) {brdptr=&origbrd; colptr=&origcol;}
else {brdptr=&board; colptr=&color;}
if (flag.reverse)sqloc=63-sq;
else sqloc=sq;
hBrush_lt = CreateSolidBrush ( clrWhiteSquare );
hBrush_dk = CreateSolidBrush ( clrBlackSquare );
hOldBrush = SelectObject ( hDC, hBrush_lt);
hOldPen = SelectObject ( hDC, GetStockObject (BLACK_PEN) );
if (((sq+sq/8)&1)==0) SelectObject(hDC,hBrush_dk);
else SelectObject(hDC,hBrush_lt);
Polygon(hDC,&squares[sqloc%8][sqloc/8][0],4);
SelectObject(hDC,hOldBrush);
SelectObject(hDC,hOldPen);
DeleteObject(hBrush_lt);
DeleteObject(hBrush_dk);
if (*(brdptr+sq)!=no_piece)
{hMemDC = CreateCompatibleDC(hDC);
hBMPold = SelectObject(hMemDC, pieces[*(brdptr+sq)].mask);
SetBkColor(hDC,CWHITE);
SetTextColor(hDC,CBLACK);
BitBlt(hDC, pieceloc[sqloc].x, pieceloc[sqloc].y, bmsize, bmsize,
hMemDC, 0, 0, SRCAND);
SelectObject(hMemDC, pieces[*(brdptr+sq)].detail);
if (*(colptr+sq)==black)SetBkColor(hDC,clrBlackPiece);
else SetBkColor(hDC,clrWhitePiece);
BitBlt(hDC, pieceloc[sqloc].x, pieceloc[sqloc].y, bmsize, bmsize,
hMemDC, 0, 0, SRCPAINT);
SelectObject(hMemDC, hBMPold);
DeleteDC(hMemDC);
}
}
void
ShowPostnValue (SHORT sq)
/*
* must have called ExaminePosition() first
*/
{
/* SHORT score;
gotoXY (4 + 5 * VIR_C (sq), 5 + 2 * (7 - VIR_R (sq)));
score = ScorePosition (color[sq]);
if (color[sq] != neutral)
{sprintf (msg,"%3d ", svalue[sq]);
printz(msg);}
else
printz (" "); */
}
void
ShowPostnValues (void)
{
/* SHORT sq, score;
ExaminePosition ();
for (sq = 0; sq < 64; sq++)
ShowPostnValue (sq);
score = ScorePosition (opponent);
gotoXY (TAB, 5);
sprintf (msg,CP[35], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
printz(msg);
ClrEoln (); */
}
void
UpdateDisplay (SHORT f, SHORT t, SHORT redraw, SHORT isspec,HDC hDC)
{
SHORT i, sq;
int x, y;
HBRUSH hOldBrush, hBrush_lt, hBrush_dk;
HPEN hOldPen;
BOOL DCsupplied=true;
if (!hDC) {hDC=GetDC(hWnd); DCsupplied=false;}
if (redraw)
{
hBrush_lt = CreateSolidBrush ( clrWhiteSquare );
hBrush_dk = CreateSolidBrush ( clrBlackSquare );
hOldBrush = SelectObject ( hDC, hBrush_lt);
hOldPen = SelectObject ( hDC, GetStockObject (BLACK_PEN) );
Polygon(hDC,&boardpg,4);
SelectObject(hDC,hBrush_dk);
for (y=0;y<8;y++)
for (x=y&1;x<8;x+=2)Polygon(hDC,&squares[x][y][0],4);
SelectObject(hDC,hOldBrush);
if (flag.searching || flag.replay)
{
for (sq=0;sq<64;sq++)
if (origbrd[sq]!=no_piece)DrawPiece(sq,hDC);
}
else
{
for (sq=0;sq<64;sq++)
if (board[sq]!=no_piece)DrawPiece(sq,hDC);
}
DeleteObject(hBrush_lt);
DeleteObject(hBrush_dk);
SelectObject(hDC,hFont);
SetBkMode(hDC,TRANSPARENT);
SetTextColor(hDC,clrText);
if (flag.coords)
for (i=0;i<8;i++)
{
y=sqdepth*i+(sqdepth-LineSpace)/2;
x=LEFTMARGIN+deltaX/2-deltaX/2*y/(sqdepth*8)-CharWidth-8;
TextOut(hDC,x,y+BACKMARGIN,flag.reverse?CP[60]+i :
"87654321"+i,1);
TextOut(hDC,LEFTMARGIN+i*sqwidthF+(sqwidthF-CharWidth)/2,BACKMARGIN+
sqdepth*8+BRD_EDGE,flag.reverse?"hgfedcba"+i:CP[59]+i,1);
}
hBrush_dk=CreateSolidBrush(clrEdge);
SelectObject(hDC,hBrush_dk);
if(!squarebd)
Rectangle(hDC,boardpg[0].x,boardpg[0].y,
boardpg[1].x+1,boardpg[1].y+BRD_EDGE);
SelectObject(hDC,hOldBrush);
SelectObject(hDC,hOldPen);
DeleteObject(hBrush_dk);
}
else
{
DrawPiece (f,hDC);
DrawPiece (t,hDC);
if (isspec & cstlmask)
if (t > f)
{
DrawPiece (f + 3,hDC);
DrawPiece (t - 1,hDC);
}
else
{
DrawPiece (f - 4,hDC);
DrawPiece (t + 1,hDC);
}
else if (isspec & epmask)
{
DrawPiece (t - 8,hDC);
DrawPiece (t + 8,hDC);
}
}
if (!DCsupplied)ReleaseDC(hWnd,hDC);
}
extern CHAR *InPtr;
void
skip ()
{
while (*InPtr != ' ' && *InPtr!=0)
InPtr++;
while (*InPtr == ' ')
InPtr++;
}
void
skipb ()
{
while (*InPtr == ' ')
InPtr++;
}
void
GiveHint (void)
{
CHAR s[40];
if (hint)
{
algbr ((SHORT) (hint >> 8), (SHORT) (hint & 0xFF), false);
strcpy (s, CP[50]); /*try*/
strcat (s, mvstr[0]);
ShowMessage (s);
}
else
ShowMessage (CP[56]);
}
void Replay(void)
{
SHORT i,f,t;
HWND hReplay;
HMENU hMenu,hMainMenu;
char message[36];
flag.replay=true;
ShowWindow(hComputerColor,SW_HIDE);
ShowWindow(hWhoseTurn,SW_HIDE);
ShowWindow(hInCheck,SW_HIDE);
hReplay = CreateWindow (lpStatic, "",
WS_CHILD | SS_LEFT | WS_VISIBLE,
LEFTMARGIN, BACKMARGIN+sqdepth*8+20,
600, SLineSpace,
hWnd, (HMENU)0, hInst, NULL);
hMenu = CreateMenu ();
AppendMenu ( hMenu, MF_STRING, IDM_PREV,"&Previous");
AppendMenu ( hMenu, MF_STRING, IDM_NEXT,"&Next");
AppendMenu ( hMenu, MF_STRING, IDM_DONE,"&End");
hMainMenu = GetMenu ( hWnd);
SetMenu ( hWnd, hMenu);
EnableMenuItem(hMenu,IDM_PREV,MF_BYCOMMAND|MF_GRAYED);
for (i = 0; i < 64; i++)
{
origbrd[i] = Stboard[i];
origcol[i] = Stcolor[i];
}
UpdateDisplay(0,0,1,0,0);
i=1;
while(1)
{
DrawMenuBar(hWnd);
sprintf(message,CP[77],i);
SetWindowText(hReplay,message);
while (!command)CheckMessage();
if (command==IDM_DONE) break;
if (flag.quit)Exit(0);
if(command==IDM_NEXT)
{
f=GameList[i].gmove>>8;
t=GameList[i].gmove&255;
if (GameList[i].flags & cstlmask)
{
if (t>f)
{
origbrd[t-1]=origbrd[t+1];
origcol[t-1]=origcol[t+1];
origbrd[t+1]=no_piece;
origcol[t+1]=neutral;
}
else
{
origbrd[t+1]=origbrd[t-2];
origcol[t+1]=origcol[t-2];
origbrd[t-2]=no_piece;
origcol[t-2]=neutral;
}
}
if (GameList[i].flags & promote)
origbrd[f]=GameList[i].flags & pmask;
if (GameList[i].flags & epmask)
{
SHORT l;
l = t + ((t > f) ? -8 : 8);
board[l] = no_piece;
color[l] = neutral;
}
origbrd[t]=origbrd[f];
origcol[t]=origcol[f];
origbrd[f]=no_piece;
origcol[f]=neutral;
UpdateDisplay(f,t,0,GameList[i].flags,0);
i++;
if(i>GameCnt)EnableMenuItem(hMenu,IDM_NEXT,MF_BYCOMMAND|MF_GRAYED);
if(i==2)EnableMenuItem(hMenu,IDM_PREV,MF_BYCOMMAND|MF_ENABLED);
}
else if(command==IDM_PREV)
{
i--;
f=GameList[i].gmove>>8;
t=GameList[i].gmove&255;
if (GameList[i].flags & cstlmask)
{
if (t>f)
{
origbrd[t+1]=origbrd[t-1];
origcol[t+1]=origcol[t-1];
origbrd[t-1]=no_piece;
origcol[t-1]=neutral;
}
else
{
origbrd[t-2]=origbrd[t+1];
origcol[t-2]=origcol[t+1];
origbrd[t+1]=no_piece;
origcol[t+1]=neutral;
}
}
if (GameList[i].flags & promote)
origbrd[t]=pawn;
if (GameList[i].flags & epmask)
{
SHORT l;
l = t + ((t > f) ? -8 : 8);
board[l] = pawn;
color[l] = !GameList[i].color;
}
origbrd[f]=origbrd[t];
origcol[f]=origcol[t];
if(GameList[i].flags & capture)
{
origbrd[t]=GameList[i].piece;
origcol[t]=GameList[i].color;
}
else
{
origbrd[t]=no_piece;
origcol[t]=neutral;
}
UpdateDisplay(f,t,0,GameList[i].flags,0);
if(i==GameCnt)EnableMenuItem(hMenu,IDM_NEXT,MF_BYCOMMAND|MF_ENABLED);
if(i==1)EnableMenuItem(hMenu,IDM_PREV,MF_BYCOMMAND|MF_GRAYED);
}
command=0;
}
SetWindowText(hReplay,CP[78]);
command=0;
SetMenu(hWnd,hMainMenu);
DestroyMenu(hMenu);
flag.replay=false;
UpdateDisplay(0,0,1,0,0);
DestroyWindow(hReplay);
ShowWindow(hComputerColor,SW_SHOWNORMAL);
ShowWindow(hWhoseTurn,SW_SHOWNORMAL);
ShowWindow(hInCheck,SW_SHOWNORMAL);
}
void
DoDebug (void)
{
SHORT c, p, sq, tp, tc, tsq, score;
CHAR s[40];
ExaminePosition ();
ShowMessage (CP[22]);
scanz ("%s", s);
c = neutral;
if (s[0] == CP[7][0] || s[0] == CP[7][1]) /* w W*/
c = white;
if (s[0] == CP[7][2] || s[0] == CP[7][3]) /*b B*/
c = black;
for (p = king; p > no_piece; p--)
if ((s[1] == pxx[p]) || (s[1] == qxx[p]))
break;
for (sq = 0; sq < 64; sq++)
{
tp = board[sq];
tc = color[sq];
board[sq] = p;
color[sq] = c;
tsq = PieceList[c][1];
PieceList[c][1] = sq;
ShowPostnValue (sq);
PieceList[c][1] = tsq;
board[sq] = tp;
color[sq] = tc;
}
score = ScorePosition (opponent);
printz (CP[35], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
}
void
DoTable (SHORT table[64])
{
SHORT sq;
ExaminePosition ();
for (sq=0;sq<64;sq++){
sprintf (msg,"%3d ", table[sq]);
printz(msg);
}
}
/*SHORT LdisplayLine;
void Ldisplay1(){LdisplayLine=4; ClrScreen();UpdateDisplay (0, 0, 1, 0, 0); }
void Ldisplay2(){
refresh ();
getchar ();
ClrScreen ();
UpdateDisplay (0, 0, 1, 0, 0);
}
void Ldisplay(char *m, char *h, SHORT count)
{
gotoXY(50,LdisplayLine);
LdisplayLine++;
sprintf(msg,"%s\t%s\t%d\n",m,h,count);
printz(msg);
}
Ldisplay3()
{ClrScreen();refresh();LdisplayLine=4;}
void Ldisplay4(char *line)
{
gotoXY(10,LdisplayLine);
LdisplayLine++;
sprintf(msg,"%s",line);
printz(msg);
refresh();
} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -