📄 chessdlg.cpp
字号:
m_pSE=new CIDAlphabetaEngine;
break;
case 6:
m_pSE=new CAlphaBeta_TTEngine;
break;
case 7:
m_pSE=new CAlphabeta_HHEngine;
break;
case 8:
m_pSE=new CMTD_fEngine;
break;
default:
m_pSE=new CNegaMaxEngine;
break;
}
m_pMG=new CMoveGenerator;//创建走法产生器
m_pEvel=new CEveluation; //创建估值核心
m_pSE->SetSearchDepth(m_SetDlg.GetSelectedPly());
m_pSE->SetUserChessColor(m_nUserChessColor);
m_pSE->SetMoveGenerator(m_pMG);//将走法产生器传给搜索引擎
m_pSE->SetEveluator(m_pEvel); //将估值核心传给搜索引擎
m_pSE->SetThinkProgress(&m_progressThink);
//设定进度条
m_pEvel->ClearAccessCount();
}
void CChessDlg::OnAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlg;
dlg.DoModal();
}
void CChessDlg::OnOpenfile()
{
// TODO: Add your command handler code here
CFileDialog m_OpenDlg(TRUE,NULL,"",0,"棋谱(*.cm)|*.cm||");
if(m_OpenDlg.DoModal()==IDCANCEL)
return;
CString strCMFile;
char* pCMFile;
FILE* fp;
int i,j;
int nUserChessColor;
strCMFile=m_OpenDlg.GetPathName();
pCMFile=(LPSTR)(LPCTSTR)strCMFile;
fp=fopen(pCMFile,"r");
if(fp==NULL)
{
MessageBox("打开文件出错","错误提示",MB_ICONWARNING);
return;
}
if(MessageBox("是否覆盖当前棋局?","友情提醒",MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2)==IDNO)
return;
for(i=0;i<10;i++)
for(j=0;j<9;j++)
fscanf(fp,"%3d",&m_byChessBoard[i][j]);
fclose(fp);
for(i=7;i<10;i++)
for(j=3;j<6;j++)
{
if(m_byChessBoard[i][j]==B_KING)
{
nUserChessColor=BLACKCHESS;
break;
}
if(m_byChessBoard[i][j]==R_KING)
{
nUserChessColor=REDCHESS;
break;
}
}
if(nUserChessColor!=m_nUserChessColor)
this->InvertChessBoard(m_byChessBoard);
m_bIsBegin=false;
//刷新屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnSavefile()
{
// TODO: Add your command handler code here
CFileDialog m_SaveDlg(false,NULL,"",0,"棋谱(*.cm)|*.cm||");
if(m_SaveDlg.DoModal()==IDCANCEL)
return;
CString strCMFile;
char* pCMFile;
FILE* fp;
int i,j;
strCMFile=m_SaveDlg.GetPathName();
pCMFile=(LPSTR)(LPCTSTR)strCMFile;
fp=fopen(pCMFile,"w");
if(fp==NULL)
{
MessageBox("打开文件出错","错误提示",MB_ICONWARNING);
return;
}
for(i=0;i<10;i++)
{
for(j=0;j<9;j++)
fprintf(fp,"%-3d",m_byChessBoard[i][j]);
fprintf(fp,"\n");
}
fclose(fp);
}
void CChessDlg::OnScbover()
{
// TODO: Add your command handler code here
m_Status=Chessing;
m_strOutputInfo=m_strWelcome;
UpdateData(false);
}
void CChessDlg::OnRpawn()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(R_PAWN))
{
m_strOutputInfo="兵已用完";
UpdateData(false);
return;
}
if(((y==6 || y==5) && (x==0 || x==2 || x==4 || x==6 || x==8)) || y<5)
m_byChessBoard[y][x]=R_PAWN;
else
{
m_strOutputInfo="该处不能放兵";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnRcanon()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(R_CANON))
{
m_strOutputInfo="炮已用完";
UpdateData(false);
return;
}
m_byChessBoard[y][x]=R_CANON;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnRcar()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(R_CAR))
{
m_strOutputInfo="车已用完";
UpdateData(false);
return;
}
m_byChessBoard[y][x]=R_CAR;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnRhorse()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(R_HORSE))
{
m_strOutputInfo="马已用完";
UpdateData(false);
return;
}
m_byChessBoard[y][x]=R_HORSE;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnRelephant()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(R_ELEPHANT))
{
m_strOutputInfo="相已用完";
UpdateData(false);
return;
}
if((y==9 && (x==2 || x==6)) || (y==7 && (x==0 || x==8)) || (y==7 && x==4) || (y==5 && (x==2 || x==6)))
m_byChessBoard[y][x]=R_ELEPHANT;
else
{
m_strOutputInfo="该处不能放相";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnRbishop()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(R_BISHOP))
{
m_strOutputInfo="士已用完";
UpdateData(false);
return;
}
if(y>=7 && y<=9 && x>=3 && x<=5)
m_byChessBoard[y][x]=R_BISHOP;
else
{
m_strOutputInfo="该处不能放士";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnRking()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(R_KING))
{
m_strOutputInfo="帅已用完";
UpdateData(false);
return;
}
if(y>=7 && y<=9 && x>=3 && x<=5)
m_byChessBoard[y][x]=R_KING;
else
{
m_strOutputInfo="该处不能放帅";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnBpawn()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(B_PAWN))
{
m_strOutputInfo="卒已用完";
UpdateData(false);
return;
}
if(((y==3 || y==4) && (x==0 || x==2 || x==4 || x==6 || x==8)) || y>4)
m_byChessBoard[y][x]=B_PAWN;
else
{
m_strOutputInfo="该处不能放卒";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnBcanon()
{
// TODO: Add your command handler code here
int x,y;
if(IsChessOver(B_CANON))
{
m_strOutputInfo="炮已用完";
UpdateData(false);
return;
}
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
m_byChessBoard[y][x]=B_CANON;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnBcar()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(B_CAR))
{
m_strOutputInfo="车已用完";
UpdateData(false);
return;
}
m_byChessBoard[y][x]=B_CAR;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnBhorse()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(B_HORSE))
{
m_strOutputInfo="马已用完";
UpdateData(false);
return;
}
m_byChessBoard[y][x]=B_HORSE;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnBelephant()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(B_ELEPHANT))
{
m_strOutputInfo="象已用完";
UpdateData(false);
return;
}
if((y==0 && (x==2 || x==6)) || (y==2 && (x==0 || x==8)) || (y==2 && x==4) || (y==4 && (x==2 || x==6)))
m_byChessBoard[y][x]=B_ELEPHANT;
else
{
m_strOutputInfo="该处不能放象";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnBbishop()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(B_BISHOP))
{
m_strOutputInfo="士已用完";
UpdateData(false);
return;
}
if(y>=0 && y<=2 && x>=3 && x<=5)
m_byChessBoard[y][x]=B_BISHOP;
else
{
m_strOutputInfo="该处不能放士";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnBking()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
if(IsChessOver(B_KING))
{
m_strOutputInfo="将已用完";
UpdateData(false);
return;
}
if(y>=0 && y<=2 && x>=3 && x<=5)
m_byChessBoard[y][x]=B_KING;
else
{
m_strOutputInfo="该处不能放将";
UpdateData(false);
}
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
void CChessDlg::OnDelete()
{
// TODO: Add your command handler code here
int x,y;
//将坐标换算成棋盘上的格子
y=(m_MousePoint.y-14)/GRILLEHEIGHT;
x=(m_MousePoint.x-15)/GRILLEWIDTH;
//判断鼠标是否在棋盘内,并且点中了棋子
if(m_MousePoint.x>0 && m_MousePoint.y>0 && m_MousePoint.x<m_nBoardWidth && m_MousePoint.y<m_nBoardHeight)
m_byChessBoard[y][x]=NOCHESS;
//重绘屏幕
InvalidateRect(NULL,FALSE);
UpdateWindow();
}
bool CChessDlg::IsChessOver(int nChessSort)
{
int i,j;
UINT uiCount=0;
for(i=0;i<10;i++)
for(j=0;j<9;j++)
if(nChessSort==m_byChessBoard[i][j])
uiCount++;
if(nChessSort==B_PAWN || nChessSort==R_PAWN)
if(uiCount<5)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -