📄 globalfun.cpp
字号:
static char *str1 = " ";
static char *str2 = " ";
static char *str3 = " ";
int tmpint;
strcpy(str, " ");
if (move->movpiece != empty)
{
{
str[0] = PieceLetter[move->movpiece];
str[1] = char('a' + move->oldpos % 16);
str[2] = char('1' + move->oldpos / 16);
if (move->content == empty)
str[3] = '-';
else
str[3] = 'x';
str[4] = char('a' + move->newpos1 % 16);
str[5] = char('1' + move->newpos1 / 16);
if ((str[0] == 'K') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str0 , "帅");
if ((str[0] == 'K') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str0,"将");
if ((str[0] == 'A') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str0,"仕");
if ((str[0] == 'A')&& (ChessBoard[move->oldpos].color == black))
lstrcpy(str0,"士");
if ((str[0] == 'B')&& (ChessBoard[move->oldpos].color == red))
lstrcpy(str0,"相");
if ((str[0] == 'B')&& (ChessBoard[move->oldpos].color == black))
lstrcpy(str0,"象");
if (str[0] == 'N')
lstrcpy(str0,"马");
if (str[0] == 'R')
lstrcpy(str0,"车");
if ((str[0] == 'G') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str0,"炮");
if ((str[0] == 'G')&& (ChessBoard[move->oldpos].color == black))
lstrcpy(str0,"砲");
if ((str[0] == 'P') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str0,"兵");
if ((str[0] == 'P') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str0,"卒");
if ((str[1] == 'a') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 ,"九");
if ((str[1] == 'b') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 , "八");
if ((str[1] == 'c') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 , "七");
if ((str[1] == 'd') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 , "六");
if ((str[1] == 'e') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 , "五");
if ((str[1] == 'f') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 , "四");
if ((str[1] == 'g') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 , "三");
if ((str[1] == 'h') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 ,"二");
if ((str[1] == 'i') && (ChessBoard[move->oldpos].color == red))
lstrcpy(str1 , "一");
if ((str[1] == 'a') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1 ,"1");
if ((str[1] == 'b') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1, "2");
if ((str[1] == 'c') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1 ,"3");
if ((str[1] == 'd') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1 , "4");
if ((str[1] == 'e') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1 , "5");
if ((str[1] == 'f') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1 , "6");
if ((str[1] == 'g') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1 , "7");
if ((str[1] == 'h') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1 , "8");
if ((str[1] == 'i') && (ChessBoard[move->oldpos].color == black))
lstrcpy(str1, "9");
if ((move->newpos1 > move->oldpos) && (ChessBoard[move->oldpos].color == red))
if ((move->newpos1 >> 4) != (move->oldpos >> 4))
lstrcpy(str2 , "进");
if ((move->newpos1 < move->oldpos) && (ChessBoard[move->oldpos].color == black))
if ((move->newpos1 >> 4) != (move->oldpos >> 4))
lstrcpy(str2 , "进");
if ((move->newpos1 < move->oldpos) && (ChessBoard[move->oldpos].color == red))
if ((move->newpos1 >> 4) != (move->oldpos >> 4))
lstrcpy(str2 , "退");
if ((move->newpos1 > move->oldpos) && (ChessBoard[move->oldpos].color == black))
if ((move->newpos1 >> 4) != (move->oldpos >> 4))
lstrcpy(str2 , "退");
if (move->newpos1 > move->oldpos)
if ((move->newpos1 >> 4) == (move->oldpos >> 4))
lstrcpy(str2 , "平");
if (move->newpos1 < move->oldpos)
if ((move->newpos1 >> 4) == (move->oldpos >> 4))
lstrcpy(str2 , "平");
tmpint = 0;
if (((move->newpos1) >>4) == ((move->oldpos) >>4))
tmpint = 9 - move->newpos1 % 16 ;
if (ChessBoard[move->oldpos].color == red)
if ((move->movpiece == king ) || (move->movpiece == rook) ||
(move->movpiece == gunner) || (move->movpiece == pawn ))
{
if (tmpint == 1)
lstrcpy(str3 , "一");
if (tmpint == 2)
lstrcpy(str3 , "二");
if (tmpint == 3)
lstrcpy(str3 , "三");
if (tmpint == 4)
lstrcpy(str3 , "四");
if (tmpint == 5)
lstrcpy(str3 , "五");
if (tmpint == 6)
lstrcpy(str3 , "六");
if (tmpint == 7)
lstrcpy(str3 , "七");
if (tmpint == 8)
lstrcpy(str3 , "八");
if (tmpint == 9)
lstrcpy(str3 , "九");
}
tmpint = 0;
if (((move->newpos1) % 16) == ((move->oldpos) % 16))
tmpint = abs((move->newpos1 >>4) - (move->oldpos >> 4));
if (ChessBoard[move->oldpos].color == red)
if ((move->movpiece == king ) || (move->movpiece == rook) ||
(move->movpiece == gunner) || (move->movpiece == pawn ))
{
if (tmpint == 1)
lstrcpy(str3 , "一");
if (tmpint == 2)
lstrcpy(str3 , "二");
if (tmpint == 3)
lstrcpy(str3 , "三");
if (tmpint == 4)
lstrcpy(str3 , "四");
if (tmpint == 5)
lstrcpy(str3 , "五");
if (tmpint == 6)
lstrcpy(str3 , "六");
if (tmpint == 7)
lstrcpy(str3 , "七");
if (tmpint == 8)
lstrcpy(str3 , "八");
if (tmpint == 9)
lstrcpy(str3 , "九");
}
tmpint = 0;
if (((move->newpos1) >> 4) == ((move->oldpos) >> 4))
tmpint = (move->newpos1 % 16 + 1);
if (ChessBoard[move->oldpos].color == black )
if ((move->movpiece == king ) || (move->movpiece == rook) ||
(move->movpiece == gunner) || (move->movpiece == pawn ))
{
if (tmpint == 9)
lstrcpy(str3 , "9");
if (tmpint == 8)
lstrcpy(str3 , "8");
if (tmpint == 7)
lstrcpy(str3 , "7");
if (tmpint == 6)
lstrcpy(str3 , "6");
if (tmpint == 5)
lstrcpy(str3 , "5");
if (tmpint == 4)
lstrcpy(str3 , "4");
if (tmpint == 3)
lstrcpy(str3 , "3");
if (tmpint == 2)
lstrcpy(str3 , "2");
if (tmpint == 1)
lstrcpy(str3 , "1");
}
tmpint = 0;
if (((move->newpos1) % 16) == ((move->oldpos) % 16))
tmpint = abs((move->newpos1 >>4) - (move->oldpos >> 4));
if (ChessBoard[move->oldpos].color == black )
if ((move->movpiece == king ) || (move->movpiece == rook) ||
(move->movpiece == gunner) || (move->movpiece == pawn ))
{
if (tmpint == 9)
lstrcpy(str3 , "9");
if (tmpint == 8)
lstrcpy(str3 , "8");
if (tmpint == 7)
lstrcpy(str3 , "7");
if (tmpint == 6)
lstrcpy(str3 , "6");
if (tmpint == 5)
lstrcpy(str3 , "5");
if (tmpint == 4)
lstrcpy(str3 , "4");
if (tmpint == 3)
lstrcpy(str3 , "3");
if (tmpint == 2)
lstrcpy(str3 , "2");
if (tmpint == 1)
lstrcpy(str3 , "1");
}
tmpint = 0;
if (((move->newpos1) >>4) != ((move->oldpos) >>4) && ((move->newpos1) % 16) != ((move->oldpos) % 16))
tmpint = 9 - move->newpos1 % 16;
if (ChessBoard[move->oldpos].color == red )
if ((move->movpiece == assist ) || (move->movpiece == bishop) ||
(move->movpiece == knight ))
{
if (tmpint == 1)
lstrcpy(str3 , "一");
if (tmpint == 2)
lstrcpy(str3 , "二");
if (tmpint == 3)
lstrcpy(str3 , "三");
if (tmpint == 4)
lstrcpy(str3 , "四");
if (tmpint == 5)
lstrcpy(str3 , "五");
if (tmpint == 6)
lstrcpy(str3 , "六");
if (tmpint == 7)
lstrcpy(str3 , "七");
if (tmpint == 8)
lstrcpy(str3 , "八");
if (tmpint == 9)
lstrcpy(str3,"九");
}
tmpint = 0;
if (((move->newpos1) >>4) != ((move->oldpos) >>4) && ((move->newpos1) % 16) != ((move->oldpos) % 16))
if (ChessBoard[move->oldpos].color == black)
if ((move->movpiece == assist) || (move->movpiece == bishop)
|| (move->movpiece == knight ))
tmpint = (move->newpos1 % 16 + 1);
{
if (tmpint == 1)
lstrcpy(str3 , "1");
if (tmpint == 2)
lstrcpy(str3 , "2");
if (tmpint == 3)
lstrcpy(str3 , "3");
if (tmpint == 4)
lstrcpy(str3 , "4");
if (tmpint == 5)
lstrcpy(str3, "5");
if (tmpint == 6)
lstrcpy(str3, "6");
if (tmpint == 7)
lstrcpy(str3, "7");
if (tmpint == 8)
lstrcpy(str3, "8");
if (tmpint == 9)
lstrcpy(str3,"9");
}
lstrcpy(str,str0);
lstrcat(str,str1);
lstrcat(str,str2);
lstrcat(str,str3);
}
}
return (str);
}
/*
在信息窗口显示着法记录
*/
void PrintMove(int movenumber, COLORTYPE programcolor, MOVETYPE *move, double time)
{
int minutes;
minutes = (int)(time / 60.0);
sprintf(buffer, "%2.2d:%#04.1f %3.3d. %s", minutes, time - minutes * 60.0, movenumber / 2 + 1, MoveStr(move));
if (programcolor == red)
InfoForm->SetRedInfoText(buffer);
else
InfoForm->SetBlackInfoText(buffer);
}
/*
使用Windows API 函数画一个三维边框
*/
void DrawFrame(HDC hDC, RECT& ChessBoardRect, bool DrawBackground)
{
int x1, y1, x2, y2;
POINT pArray[3];
HPEN hPen, hOldPen;
HBRUSH hOldBrush;
x1 = ChessBoardRect.left;
x2 = ChessBoardRect.right;
y1 = ChessBoardRect.top;
y2 = ChessBoardRect.bottom ;
if (DrawBackground == false)
hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
else
hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
hOldPen = (HPEN)SelectObject(hDC, GetStockObject(WHITE_PEN));
Rectangle(hDC, x1, y1, x2 , y2);
SelectObject(hDC, hPen = CreatePen(PS_SOLID, 1, RGB(192, 192, 192)));
Rectangle(hDC, x1+1, y1+1, x2 -1, y2 -1);
DeleteObject(SelectObject(hDC, GetStockObject(WHITE_PEN)));
pArray[0].x = x1 + 2;
pArray[1].y = pArray[0].y = y2 - 3;
pArray[2].x = pArray[1].x = x2 - 3;
pArray[2].y = y1 + 2;
Polyline(hDC, pArray, 3);
hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
SelectObject(hDC, hPen);
pArray[0].x = x1;
pArray[1].y = pArray[0].y = y2-1;
pArray[2].x = pArray[1].x = x2-1;
pArray[2].y = y1;
Polyline(hDC, pArray, 3);
pArray[1].x = pArray[0].x = x1 + 2;
pArray[0].y = y2 - 3;
pArray[2].y = pArray[1].y = y1 + 2;
pArray[2].x = x2 - 3;
Polyline(hDC, pArray, 3);
SelectObject(hDC, hOldBrush);
DeleteObject(SelectObject(hDC, hOldPen));
}
/*
* 显示当前级别信息
*/
void PrintCurLevel()
{
extern bool MultiMove;
if (MultiMove)
lstrcpy(buffer, "两人对弈");
else
{
switch (Level)
{
case normal:
sprintf(buffer, "%1.0f 秒/移动", AverageTime);
break;
case fullgametime:
sprintf(buffer, "%2.2f 分钟/局", AverageTime);
break;
case easygame:
lstrcpy(buffer, "容易");
break;
case infinite :
lstrcpy(buffer, "无限制");
break;
case plysearch :
sprintf(buffer, "回合深度 = %d", MaxLevel);
break;
case matesearch:
lstrcpy(buffer, "将死搜索");
break;
case matching :
lstrcpy(buffer, "匹配用户时间");
break;
}
}
InfoForm->SetLevelText(buffer);
}
/*获取棋格坐标X,Y*/
POINT GetSquareXY(SQUARETYPE square)
{
POINT p;
if (Turned)
{
square = (char)0xff ^ square - 0x99 ;
}
p.x = ((square & 0xf)) * SQUARE_SIZE + BORDERSIZE + MYFRAMESIZE;
p.y = (9 - ((square >> 4))) * SQUARE_SIZE + BORDERSIZE + MYFRAMESIZE/16+SQUARE_SIZE;
return p;
}
/*
重画棋格子。在背景上的给定位置填充颜色且画出一个棋格
*/
void ClearSquare(SQUARETYPE square)
{
HANDLE hOldBrush;
POINT p;
HDC hDC;
int rank, line;
p = GetSquareXY(square);
if (Turned)
square = (char)0xff ^ square - 0x99 ;
line =( square % 16) ;
rank =(square >>4) ;
hDC = GetDC(Application->MainForm->Handle);
if (Turned) /*反转棋盘时*/
{
hOldBrush = SelectObject(hDC, hColorBrush);
PatBlt(hDC, p.x, p.y , SQUARE_SIZE, SQUARE_SIZE, PATCOPY);
if ((rank==0)&&(line==0))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -