📄 wzqpcgo.cpp
字号:
nCount=4;//从新记数
int Qiflag=0xfff;//判断有几个连续棋子的标志
int blankflag=0xfff;//判断有几个空格的标志
for(int xrightdown=yd+1,yrightdown=xd+1;nCount!=0;xrightdown++,yrightdown++,nCount--)//左斜下
{
switch(nCount)
{
case 4:Qiflag=0xff7;blankflag=0xeff;break;
case 3:Qiflag=0xffb;blankflag=0xeff;break;
case 2:Qiflag=0xffd;blankflag=0xeff;break;
case 1:Qiflag=0xf7e;blankflag=0xeff;break;
default:AfxMessageBox("Wzqgo::SetMax()中有错误6");break;
}
if(xd==14 || yd==14)//一开始位于最右边或最下边
{
PcBestGo[xd][yd][d]-=4;
PersonBestGo[xd][yd][d]-=4;
break;
}
else if(xrightdown==15 || yrightdown==15)//过界
{
dangerflag=dangerflag & 0xdff;
winflag=winflag &0xdff;
if(blank)
{
PcBestGo[xd][yd][d]-=nCount;
PersonBestGo[xd][yd][d]-=nCount;
}
break;
}
else
{
if(QiPan[yrightdown][xrightdown].Qizhi==0)//空格中没有下子
{
switch(nCount)
{
case 4:kongge=kongge & 0xf7;break;
case 3:kongge=kongge & 0xfb;break;
case 2:kongge=kongge & 0xfd;break;
case 1:kongge=kongge & 0xfe;break;
default:AfxMessageBox("Wzqgo::SetMax()中aaa有错误1");break;
}
if(blank)
{
PcBestGo[xd][yd][d]-=1;
PersonBestGo[xd][yd][d]-=1;
}
if(!PcStop || !PersonStop)
{
dangerflag=dangerflag & blankflag;
winflag=winflag & blankflag;
}
}
else if(QiPan[yrightdown][xrightdown].Qizhi==1)//空格中为电脑下的棋子
{
PersonStop=TRUE;
blank=FALSE;
if(!PcStop)
{
PcBestGo[xd][yd][d]+=1000;
winflag=winflag & Qiflag;
valueflag++;
}
else
{
PersonBestGo[xd][yd][d]-=valueflag*1000;
}
}
else if(QiPan[yrightdown][xrightdown].Qizhi==2)//空格为人下的棋子
{
PcStop=TRUE;
blank=FALSE;
if(!PersonStop)
{
PersonBestGo[xd][yd][d]+=1000;
dangerflag=dangerflag & Qiflag;
valueflag++;
}
else
{
PersonBestGo[xd][yd][d]-=valueflag*1000;
}
}
}
}
if(!yucheflag)
{
if(Model==2 && PcGO)
FindDangerandWin(dangerflag,winflag,kongge,xd,yd,d);
else
FindDangerandWin(winflag,dangerflag,kongge,xd,yd,d);
}
else
{
if(yuchegoflag)
FindDangerandWin(dangerflag,winflag,kongge,xd,yd,d);
else
FindDangerandWin(winflag,dangerflag,kongge,xd,yd,d);
}
}
//------------------------------------------------------------------------------
else//右斜
{
for(int xupright=yd+1,yupright=xd-1;nCount!=0;xupright++,yupright--,nCount--)//右斜上
{
switch(nCount)
{
case 4:Qiflag=0xfef;blankflag=0xbff;break;
case 3:Qiflag=0xfdf;blankflag=0xbff;break;
case 2:Qiflag=0xfbf;blankflag=0xbff;break;
case 1:Qiflag=0xf7f;blankflag=0xbff;break;
default:AfxMessageBox("Wzqgo::SetMax()中有错误1");break;
}
if(xd==0 || yd==14)//一开始位于最右边或最上边
{
PcBestGo[xd][yd][d]-=4;
PersonBestGo[xd][yd][d]-=4;
break;
}
else if(xupright==15 || yupright==-1)//过界
{
dangerflag=dangerflag & 0x7ff;
winflag=winflag & 0x7ff;
if(blank)
{
PcBestGo[xd][yd][d]-=nCount;
PersonBestGo[xd][yd][d]-=nCount;
}
break;
}
else
{
if(QiPan[yupright][xupright].Qizhi==0)//空格中没有下子
{
switch(nCount)
{
case 4:kongge=kongge & 0xef;break;
case 3:kongge=kongge & 0xdf;break;
case 2:kongge=kongge & 0xbf;break;
case 1:kongge=kongge & 0x7f;break;
default:AfxMessageBox("Wzqgo::SetMax()中aaa有错误1");break;
}
if(blank)
{
PcBestGo[xd][yd][d]-=1;
PersonBestGo[xd][yd][d]-=1;
}
if(!PcStop || !PersonStop)
{
dangerflag=dangerflag & blankflag;
winflag=winflag & blankflag;
}
}
else if(QiPan[yupright][xupright].Qizhi==1)//空格中为电脑下的棋子
{
PersonStop=TRUE;
blank=FALSE;
if(!PcStop)
{
PcBestGo[xd][yd][d]+=1000;
winflag=winflag & Qiflag;
valueflag++;
}
else
{
PersonBestGo[xd][yd][d]-=valueflag*1000;
}
}
else if(QiPan[yupright][xupright].Qizhi==2)//空格为人下的棋子
{
PcStop=TRUE;
blank=FALSE;
if(!PersonStop)
{
PersonBestGo[xd][yd][d]+=1000;
dangerflag=dangerflag & Qiflag;
valueflag++;
}
else
{
PersonBestGo[xd][yd][d]-=valueflag*1000;
}
}
}
}
blank=TRUE;
PcStop=FALSE;
PersonStop=FALSE;
valueflag=0;
nCount=4;//从新记数
int Qiflag=0xfff;//判断有几个连续棋子的标志
int blankflag=0xfff;//判断有几个空格的标志
for(int xdownright=yd-1,ydownright=xd+1;nCount!=0;xdownright--,ydownright++,nCount--)//右斜下
{
switch(nCount)
{
case 4:Qiflag=0xff7;blankflag=0xeff;break;
case 3:Qiflag=0xffb;blankflag=0xeff;break;
case 2:Qiflag=0xffd;blankflag=0xeff;break;
case 1:Qiflag=0xf7e;blankflag=0xeff;break;
default:AfxMessageBox("Wzqgo::SetMax()中有错误2");break;
}
if(xd==14 || yd==0)//一开始位于最左边或最下边
{
PcBestGo[xd][yd][d]-=4;
PersonBestGo[xd][yd][d]-=4;
break;
}
else if(xdownright==-1 || ydownright==15)//过界
{
dangerflag=dangerflag & 0xdff;
winflag=winflag &0xdff;
if(blank)
{
PcBestGo[xd][yd][d]-=nCount;
PersonBestGo[xd][yd][d]-=nCount;
}
break;
}
else
{
if(QiPan[ydownright][xdownright].Qizhi==0)//空格中没有下子
{
switch(nCount)
{
case 4:kongge=kongge & 0xf7;break;
case 3:kongge=kongge & 0xfb;break;
case 2:kongge=kongge & 0xfd;break;
case 1:kongge=kongge & 0xfe;break;
default:AfxMessageBox("Wzqgo::SetMax()中aaa有错误1");break;
}
if(blank)
{
PcBestGo[xd][yd][d]-=1;
PersonBestGo[xd][yd][d]-=1;
}
if(!PcStop || !PersonStop)
{
dangerflag=dangerflag & blankflag;
winflag=winflag & blankflag;
}
}
else if(QiPan[ydownright][xdownright].Qizhi==1)//空格中为电脑下的棋子
{
PersonStop=TRUE;
blank=FALSE;
if(!PcStop)
{
PcBestGo[xd][yd][d]+=1000;
winflag=winflag & Qiflag;
valueflag++;
}
else
{
PersonBestGo[xd][yd][d]-=valueflag*1000;
}
}
else if(QiPan[ydownright][xdownright].Qizhi==2)//空格为人下的棋子
{
PcStop=TRUE;
blank=FALSE;
if(!PersonStop)
{
PersonBestGo[xd][yd][d]+=1000;
dangerflag=dangerflag & Qiflag;
valueflag++;
}
else
{
PersonBestGo[xd][yd][d]-=valueflag*1000;
}
}
}
}
if(!yucheflag)
{
if(Model==2 && PcGO)
FindDangerandWin(dangerflag,winflag,kongge,xd,yd,d);
else
FindDangerandWin(winflag,dangerflag,kongge,xd,yd,d);
}
else
{
if(yuchegoflag)
FindDangerandWin(dangerflag,winflag,kongge,xd,yd,d);
else
FindDangerandWin(winflag,dangerflag,kongge,xd,yd,d);
}
}
}
void WzqPcGo::FindDangerandWin(int win,int danger,int kong,int xm,int ym,int d)
{
if((0xacf==(win | 0xa87) && 0xfff==(danger | 0xff7)) ||
(0xaf3==(win | 0xae1) && 0xfff==(danger | 0xfef)) ||
(0xae7==(win | 0xac3)) || (0xaf9==(win | 0x8e0) && 0xe6==(kong | 0xe6)) ||
(0xa9f==(win | 0x207) && 0x67==(kong | 0x67)) ||
(0xaf5==(win | 0x8e0) && 0xea==(kong | 0xea)) ||
(0xaeb==(win | 0xac1) && 0xd5==(kong | 0xd5)) ||
(0xaaf==(win | 0x207) && 0x57==(kong | 0x57)) ||
(0xad7==(win | 0xa83) && 0xab==(kong | 0xab)))//_ooc_ or _coo_ or _oco_ or _c_oo_ or _oo_c_ or _co_o_ or _oc_o_ or _o_oc_ or _o_co_
{
QiPan[xm][ym].YouxianPc++;
}
// if((0xacf==(win | 0xa87) && 0xfff==(danger | 0xff7)) ||
// (0xaf3==(win | 0xae1) && 0xfff==(danger | 0xfef)))
// {
// if(!yucheflag)
// PcBestGo[xm][ym][d]=50000;
// }
// if((0xbf1==(win | 0xbe1) && 0xfff==(danger | 0xfef)) ||
// (0xecb==(win | 0xec3)) || (0xbd3==(win | 0xbc3)))
// {
// if(!yucheflag)
// PcBestGo[xm][ym][d]=100000;
// }
if((0xb1f==(win | 0x31f)) || (0xef8==(win | 0xcf8)) ||
(0xe8f==(win | 0xe87) && 0xfff==(danger | 0xff7)) ||
(0xbf1==(win | 0xbe1) && 0xfff==(danger | 0xfef)) ||
(0xecb==(win | 0xec3)) || (0xbd3==(win | 0xbc3)) ||
(0xb97==(win | 0xb87)) || (0xb8f==(win | 0x30f)) ||
(0xef1==(win | 0xcf0)) || (0xec7==(win | 0xec3)) ||
(0xbe3==(win | 0xbc3)) || (0xbc7==(win | 0xb87)) || (0xee3==(win | 0xee1)))
{ //ooo_c or c_ooo or oooc_ or _cooo or ooc_o or o_coo or oc_oo or oo_co or _oooc or cooo_ or ooco_ or _ocoo or _ooco or ocoo_
QiPan[xm][ym].YouxiantPc++;
}
if((0xacf==(danger | 0xa87) && 0xfff==(win | 0xff7)) || (0xaf3==(danger | 0xae1) && 0xfff==(win | 0xfef)) ||
(0xae7==(danger | 0xac3)) || (0xaf9==(danger | 0x8e0) && 0xe6==(kong | 0xe6)) ||
(0xa9f==(danger | 0x207) && 0x67==(kong | 0x67)) ||
(0xaf5==(danger | 0x8e0) && 0xea==(kong | 0xea)) ||
(0xaeb==(danger | 0xac1) && 0xd5==(kong | 0xd5)) ||
(0xaaf==(danger | 0x207) && 0x57==(kong | 0x57)) ||
(0xad7==(danger | 0xa83) && 0xab==(kong | 0xab)))// _oox_ or _xoo_ or _oxo_ or _x_oo_ or _oo_x_ or _xo_o_ or _ox_o_ or _o_ox_ or _o_xo_
{
QiPan[xm][ym].YouxianPerson++;
}
if((0xb1f==(danger | 0x31f)) || (0xef8==(danger | 0xcf8)) ||
(0xe8f==(danger | 0xe87) && 0xfff==(win | 0xff7)) ||
(0xbf1==(danger | 0xbe1) && 0xfff==(win | 0xfef)) ||
(0xecb==(danger | 0xec3)) || (0xbd3==(danger | 0xbc3)) ||
(0xb97==(danger | 0xb87)) || (0xb8f==(danger | 0x30f)) ||
(0xef1==(danger | 0xcf0)) || (0xec7==(danger | 0xec3)) ||
(0xbe3==(danger | 0xbc3)) || (0xbc7==(danger | 0xb87)) || (0xee3==(danger | 0xee1)))
{//ooo_x or x_ooo or ooox_ or _xooo or oox_o or o_xoo or ox_oo or oo_xo
QiPan[xm][ym].YouxiantPerson++;
}
//----------------------------------------------------------------------------------------------
if(0xfc3==(win | 0xfc3) || 0xf87==(win | 0xf87) || 0xfe1==(win | 0xfe1) ||
0xf0f==(win | 0xf0f) || 0xff0==(win | 0xff0))// oocoo or oooco or ocooo or ooooc or coooo
{
/*AfxMessageBox("oooooooooooooo");*/
// char a[20];
// _gcvt(xm,3,a);
// AfxMessageBox(a);
// _gcvt(ym,3,a);
// AfxMessageBox(a);
PcBestGo[xm][ym][d]+=800000;
if(yucheflag)
{
if(yuchegoflag)
yuchedangerflag=TRUE;
else
yuchewinflag=TRUE;
}
}
//------------------------------------------------------------
else if(0xfc3==(danger | 0xfc3) ||0xf87==(danger | 0xf87) || 0xfe1==(danger | 0xfe1) ||
0xf0f==(danger | 0xf0f) || 0xff0==(danger | 0xff0))//ooxoo or oooxo or oxooo or oooox or xoooo
{
PersonBestGo[xm][ym][d]+=700000;
}
//----------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------
else if(0xa8f==(win | 0x287) && 0xfff==(danger | 0xff7) || 0xac7==(win | 0xa83) ||
0xaf1==(win | 0x8e1) && 0xfff==(danger | 0xfef) || 0xae3==(win | 0xac1))//_oooc_ or _ooco_ or _cooo_ or _ocoo_
{
/* AfxMessageBox("tttttttttttt");*/
PcBestGo[xm][ym][d]+=600000;
if(yucheflag)
{
if(yuchegoflag)
yuchedangerflag=TRUE;
else
yuchewinflag=TRUE;
}
}
//------------------------------------------------
else if(0xa8f==(danger | 0x287) && 0xfff==(win | 0xff7) || 0xac7==(danger | 0xa83) ||
0xaf1==(danger | 0x8e1) && 0xfff==(danger | 0xfef) || 0xae3==(danger | 0xac1))//_ooox_ or _ooxo_ or _xooo_ or _oxoo_
{
PersonBestGo[xm][ym][d]+=500000;
// if(yucheflag && yuchegoflag)
// {
// yuchedangerflag=TRUE;
// }
}
//-------------------------------------------------------
else if((QiPan[xm][ym].YouxiantPc>=2) || (QiPan[xm][ym].YouxianPc>=1 && QiPan[xm][ym].YouxiantPc==1))
{
/* AfxMessageBox("111111111111");*/
// char a[20];
// _gcvt(xm,3,a);
// AfxMessageBox(a);
// _gcvt(ym,3,a);
// AfxMessageBox(a);
BestGo[xm][ym]+=400000;
QiPan[xm][ym].YouxianPc=0;
QiPan[xm][ym].YouxiantPc=0;
if(yucheflag)
{
if(yuchegoflag)
yuchedangerflag=TRUE;
else
yuchewinflag=TRUE;
}
}
else if((QiPan[xm][ym].YouxiantPerson>=2) || (QiPan[xm][ym].YouxianPerson>=1 && QiPan[xm][ym].YouxiantPerson==1))
{
/* AfxMessageBox("222222222222");*/
// char a[20];
// _gcvt(xm,3,a);
// AfxMessageBox(a);
// _gcvt(ym,3,a);
// AfxMessageBox(a);
BestGo[xm][ym]+=300000;
QiPan[xm][ym].YouxianPerson=0;
QiPan[xm][ym].YouxiantPerson=0;
// if(yucheflag && yuchegoflag)
// {
// yuchedangerflag=TRUE;
// }
}
//--------------------------------------------------------
else if(QiPan[xm][ym].YouxianPc>=2)
{
// char a[20];
// _gcvt(xm,3,a);
// AfxMessageBox(a);
// _gcvt(ym,3,a);
// AfxMessageBox(a);
// AfxMessageBox("555555555555");
BestGo[xm][ym]+=200000;
QiPan[xm][ym].YouxianPc=0;
if(yucheflag)
{
if(yuchegoflag)
yuchedangerflag=TRUE;
else
yuchewinflag=TRUE;
}
}
//---------------------------------------------------------
else if(QiPan[xm][ym].YouxianPerson>=2)
{
// char a[20];
// _gcvt(xm,3,a);
// AfxMessageBox(a);
// _gcvt(ym,3,a);
// AfxMessageBox(a);
BestGo[xm][ym]+=100000;
QiPan[xm][ym].YouxianPerson=0;
// if(yucheflag && yuchegoflag)
// {
// yuchedangerflag=TRUE;
// }
}
}
void WzqPcGo::GetMax()
{
int max=0;
int xd,yd;
for(int v=0;v<15;v++)
{
for(int i=0;i<=14;i++)
{
for(int j=0;j<=14;j++)
{
if(QiPan[i][j].Qizhi==0)
{
for(int k=0;k<4;k++)
{
BestGo[i][j]+=PersonBestGo[i][j][k]+PcBestGo[i][j][k];
}
if(BestGo[i][j]>=max)
{
max=BestGo[i][j];
xd=i;
yd=j;
}
}
}
}
BestGo[xd][yd]=0;
for(int k=0;k<4;k++)
{
PersonBestGo[xd][yd][k]=0;
PcBestGo[xd][yd][k]=0;
}
yuche[v].x=xd;
yuche[v].y=yd;
max=0;
}
yucheflag=TRUE;
for(int b=0;b<15;b++)//预测优先级最高的15步棋
{
yuchegoflag=PcGO;
if(YuChe(&yuche[b]))
{
/* AfxMessageBox("3333333333");*/
xd=yuche[b].x;
yd=yuche[b].y;
break;
}
else
{
xd=yuche[0].x;
yd=yuche[0].y;
}
}
yucheflag=FALSE;
if(PcGO)
{
BuildHuiQi(xd,yd);
DownBaizhi(xd,yd);
if(WhoWin(xd,yd))
{
DrawAgain();
stophand=TRUE;
AfxMessageBox("白棋赢!");
}
}
else
{
BuildHuiQi(xd,yd);
flag=TRUE;
Downheizhi(xd,yd);
if(WhoWin(xd,yd))
{
DrawAgain();
stophand=TRUE;
AfxMessageBox("黑棋赢!");
}
}
}
void WzqPcGo::SetDC(MyCDC*tqp,MyCDC*tqzh,MyCDC*tqzb,MyCDC*tmask,MyCDC*tdead,CDC*tdc)
{
qp=tqp;
qzh=tqzh;
qzb =tqzb;
mask =tmask;
dc=tdc;
dead=tdead;
}
void WzqPcGo::DownBaizhi(int x,int y)//人下白子
{
if(PcGO)
{
PcGO=FALSE;
if(QiPan[x][y].Qizhi==0)
{
QiPan[x][y].Qizhi=2;
dc->BitBlt(y*29+7,x*29+7,28,28,mask,0,0,MERGEPAINT);
dc->BitBlt(y*29+7,x*29+7,28,28,qzb,0,0,SRCAND);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -