嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元微信扫码支付:1 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
使用键盘上下左右进行游戏,采用贪心算法,有时限和禁手功能 ,且有最后一步提示
	
	
	bool Cchess::banchess(bool flag)//禁手算法
{
 int x;
 int y;
 x = Lpoint.x;
 y = Lpoint.y;
 int edge[2];//边界值
 edge[1]=edge[0]=0;//初始化
 int vflag,Flag;
 bool result = 0;
 bool num = 1;//用于抵消一次空子
 int total = 0;//计算连子数
 int sum = 0;//计数有多少活三,冲四等等
 if(flag == 1)
 {
 vflag = 2;
 Flag = 1;
 }
 else
 {
 vflag = 1;
 Flag = 2;
 }
 while(edge[0]==0)
 {
 x--;//竖直方向向上
     if(chessboard[x][y]==0&&num == 1&&x>0&&chessboard[x-1][y]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||x<0)
     {
     edge[0]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&chessboard[x-1][y] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&x<-1)
 {
 break;
 }
 }
 x = Lpoint.x;//回归起算点。
 while(edge[1]==0)
 {
 x  ;//竖直方向向下
     if(chessboard[x][y]==0&&num == 1&&x<17&&chessboard[x 1][y]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||x>17)
     {
     edge[1]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&chessboard[x 1][y] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&x>17)
 {
 break;
 }
 }
 if(total>3)
 sum  ;
 else if(total>2)
 sum  ;
 else if(total==2&&edge[0]==0&&edge[1]==0)
 sum  ;
 if(sum>1)
 {
 return true;
 }
 //------------------------------------------------------------------------------
 x = Lpoint.x;
 y = Lpoint.y;//坐标回归
 edge[1]=edge[0]=0;//初始化
 num = 1;//用于抵消一次空子
    total = 0;//计算连子数
 while(edge[0]==0)
 {
 y--;//水平方向向左
     if(chessboard[x][y]==0&&num == 1&&y>0&&chessboard[x][y-1]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||y<0)
     {
     edge[0]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&chessboard[x][y-1] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&y-1<0)
 {
 break;
 }
 }
 y = Lpoint.y;//回归起算点。
 while(edge[1]==0)
 {
 y  ;//竖直方向向下
     if(chessboard[x][y]==0&&num == 1&&y<17&&chessboard[x][y 1]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||y>17)
     {
     edge[1]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&chessboard[x][y 1] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&y>17)
 {
 break;
 }
 }
 if(total>3)
 sum =2;
 else if(total>2)
 sum  ;
 else if(total==2&&edge[0]==0&&edge[1]==0)
 sum  ;
 if(sum>1)
 {
 return true;
 }
 //-----------------------------------------------------------------------------------------
 x = Lpoint.x;
 y = Lpoint.y;//坐标回归
 edge[1]=edge[0]=0;//初始化
 num = 1;//用于抵消一次空子
    total = 0;//计算连子数
 while(edge[0]==0)
 {
 y--;//斜45°向右上
 x  ;
     if(chessboard[x][y]==0&&num == 1&&y>0&&x<17&&chessboard[x 1][y-1]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||y<0||x>17)
     {
     edge[0]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&chessboard[x 1][y-1] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&x>17)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&y-1<0)
 {
 break;
 }
 }
 x = Lpoint.x;
 y = Lpoint.y;//回归起算点。
 while(edge[1]==0)
 {
 x--;
 y  ;//斜45°向左下
     if(chessboard[x][y]==0&&num == 1&&y<17&&x>0&&chessboard[x-1][y 1]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||y>17||x<0)
     {
     edge[1]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&chessboard[x-1][y 1] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&x-1<0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&y>17)
 {
 break;
 }
 }
 if(total>3)
 sum =2;
 else if(total>2)
 sum  ;
 else if(total==2&&edge[0]==0&&edge[1]==0)
 sum  ;
 if(sum>1)
 {
 return true;
 }
 //-----------------------------------------------------------------------------
 x = Lpoint.x;
 y = Lpoint.y;//坐标回归
 edge[1]=edge[0]=0;//初始化
 num = 1;//用于抵消一次空子
    total = 0;//计算连子数
 while(edge[0]==0)
 {
 y--;//斜135°向左上
 x--;
     if(chessboard[x][y]==0&&num == 1&&y>0&&x>0&&chessboard[x-1][y-1]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||y<0||x<0)
     {
     edge[0]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&y>0&&x>0&&chessboard[x-1][y-1] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&x-1<0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&y-1<0)
 {
 break;
 }
 }
 x = Lpoint.x;
 y = Lpoint.y;//回归起算点。
 while(edge[1]==0)
 {
 x  ;
 y  ;//右下
     if(chessboard[x][y]==0&&num == 1&&y<17&&x<17&&chessboard[x 1][y 1]==Flag)
     {
     num = 0; 
     }
     else if(chessboard[x][y] == Flag)
     {
     total  ;
 if(total>3)
 break;
     }
     else if(chessboard[x][y] == vflag||y>17||x>17)
     {
     edge[1]=1;
     }
 else if(chessboard[x][y]==0&&num == 1&&chessboard[x 1][y 1] == 0)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&y>17)
 {
 break;
 }
 else if(chessboard[x][y]==0&&num == 1&&x>17)
 {
 break;
 }
 }
 if(total>3)
 sum =2;
 else if(total>2)
 sum  ;
 else if(total==2&&edge[0]==0&&edge[1]==0)
 sum  ;
 if(sum>1)
 {
 result = 1;
 }
 return result;
}