五子棋核心算法
来源:互联网 发布:unity3d寻路插件 编辑:程序博客网 时间:2024/05/02 00:32
写了一周!终于实现了最基本的最核心的算法!
但是,由于算法本身的原因!所以这当然是个三流的实现方式!由于我的这个算法思路很复杂化!所以,应该没人能看懂!呵呵!
/////////五子棋////////////
#include<iostream>
//#include <alloc.h> //使用free函数
//#include <alloc.h> //使用free函数
#define NUM 20
#define MAXPRI 100
#define DEFENPRI 90
#define NULL 0
///////////优先级定义////////////
#define PRI_0 0
#define PRI_1 1
#define PRI_2 2
#define PRI_3 3
#define PRI_4 4
#define PRI_5 5
/////////////////////////////////
using namespace std;
#define MAXPRI 100
#define DEFENPRI 90
#define NULL 0
///////////优先级定义////////////
#define PRI_0 0
#define PRI_1 1
#define PRI_2 2
#define PRI_3 3
#define PRI_4 4
#define PRI_5 5
/////////////////////////////////
using namespace std;
typedef struct
{
int x; //棋盘的x坐标
int y; //棋盘的y坐标
}Point;
{
int x; //棋盘的x坐标
int y; //棋盘的y坐标
}Point;
typedef struct two
{
Point TWO[2];
struct two *next;
}*TwoChessman; //棋盘上所有两个连续的棋子坐标
typedef struct three
{
Point THREE[3];
struct three *next;
}*ThreeChessman; //棋盘上所有三个连续的棋子坐标
typedef struct four
{
Point FOUR[4];
struct four *next;
}*FourChessman; //棋盘上所有四个连续的棋子坐标
typedef struct Co
{
TwoChessman two;
int CountTwo;
ThreeChessman three;
int CountThree;
FourChessman four;
int CountFour;
}ContinuumChessman; //棋盘上所有连续的棋子坐标(2-4个棋子连续)
typedef struct po
{
Point point;
struct po *next;
}*LPoint; //某一个优先级上的所有下一步可能下法
{
Point TWO[2];
struct two *next;
}*TwoChessman; //棋盘上所有两个连续的棋子坐标
typedef struct three
{
Point THREE[3];
struct three *next;
}*ThreeChessman; //棋盘上所有三个连续的棋子坐标
typedef struct four
{
Point FOUR[4];
struct four *next;
}*FourChessman; //棋盘上所有四个连续的棋子坐标
typedef struct Co
{
TwoChessman two;
int CountTwo;
ThreeChessman three;
int CountThree;
FourChessman four;
int CountFour;
}ContinuumChessman; //棋盘上所有连续的棋子坐标(2-4个棋子连续)
typedef struct po
{
Point point;
struct po *next;
}*LPoint; //某一个优先级上的所有下一步可能下法
typedef struct
{
LPoint PRI[MAXPRI];
}NextPri; //在优先级0~MAXPRI-1上的所有下一步可能下法
{
LPoint PRI[MAXPRI];
}NextPri; //在优先级0~MAXPRI-1上的所有下一步可能下法
class Computer
{
private:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Point ComExistChessman[(NUM*NUM)/2+1]; //棋盘上所有电脑已有棋子坐标
ContinuumChessman continuumChessmanCom; //棋盘上所有电脑的连续棋子坐标
int ComCount;//棋盘上所有电脑已有棋子个数
NextPri ComNext; //电脑一方下一步的所有可能下法,按优先级存储(用于计算下一步棋的进攻下法)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Point OppExistChessman[(NUM*NUM)/2+1];//棋盘上所有对手已有棋子坐标
ContinuumChessman continuumChessmanOpp; //棋盘上所有对手的连续棋子坐标
int OppCount;//棋盘上所有对手已有棋子个数
NextPri OppNext; //对方下一步的所有可能下法,按优先级存储(用于计算防御下法)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int Result;//表示胜利的为哪一方。初始值为0,表示比赛正在进行;如果电脑胜利者值为1;对手胜利则为2;
public:
Computer();//构造函数,初始化该类的各数据成员
bool JudgeCoordinate(int x,int y);//判断一个坐标是否已经被占用(没有占用返回true)
bool EnsureNext();//结合进攻下一步和防御下一步的所有情况,确定真正的下一步坐标,并且保存到RealNext数据成员中//////////////
bool AddToComNext(int x,int y,int pri); //添加新的棋子到ComNext成员
bool JudgeComNext(int x,int y);//判断一个坐标是否已经被加入到ComNext里面
bool ContinuumNum(int x,int y,int &left,int &right,
int &top,int &bottom,int &leftT,int &leftB,int &rightT,int &rightB);//计算一个点在各个方向上各有几个点相连
int Max(int a,int b,int c,int d,int &count);//函数返回4各数的最大值,并计算出有几个值并列为最大值
bool AddToContinuumChessman(int x,int y);//添加一个点到ContinuumChessman数据成员中
bool DeleConCheTwo(TwoChessman two);//删除continuumChessman中连续两个棋子的一个节点
bool DeleConCheThree(ThreeChessman three); //删除continuumChessman中连续三个棋子的一个节点
bool DeleComNext();//清空ComNext数据成员中的所有内容
///////////////////computer核心算法///////////////////////////
bool AttackNextPri0(); //计算出进攻下一步棋的所有可能情况,并加入到ComNext数据成员中的第0优先级
bool RecoveryNext();//计算出防御下一步棋的所有可能情况,并加入到OppNext数据成员中///////////////////
bool AttackNextPri1(); //在ComNext数据成员的第0优先级中提取更高的优先级坐标,并加入到ComNext数据成员中的更高优先级
bool AddNewChessman(); //确定并添加棋子到ComExistChessman和continuumChessman
///////////////////computer核心算法///////////////////////////
///////////////////Opp核心算法///////////////////////////
bool AddNewChessmanOpp();//添加新的棋子到OppExistChessman和continuumChessmanOpp数据成员
bool AddToContinuumChessmanOpp(int x,int y);//添加一个点到continuumChessmanOpp数据成员中
bool DeleConCheTwoOpp(TwoChessman two);//删除continuumChessmanOpp中连续两个棋子的一个节点
bool DeleConCheThreeOpp(ThreeChessman three); //删除continuumChessmanOpp中连续三个棋子的一个节点
bool AddDefenNewCh();//在continuumChessmanOpp中确定防御下一步棋
bool JudgeComCoordinate(int x,int y);//判断一个坐标是否已经被Computer的棋子所占用(没有占用返回true)
///////////////////Opp核心算法///////////////////////////
int GetResult();
};
int Computer::GetResult()
{
return Result;
}
//////////////////////////////////////////////////////////////////////////////
// JudgeComCoordinate函数定义——开始 //
//判断一个坐标是否已经被Computer的棋子所占用(没有占用返回true)//
/////////////////////////////////////////////////////////////////////////////
bool Computer::JudgeComCoordinate(int x,int y)
{
int temp=0;
for(int i=0;i<ComCount;i++)
{
if(x==ComExistChessman[i].x&&y==ComExistChessman[i].y)
temp++;
}
if(temp==0&&x<NUM&&x>=0&&y<NUM&&y>=0)
return true;
else
return false;
}
//////////////////////////////////////////////////////////////////////////////
// JudgeComCoordinate函数定义——结束 //
//判断一个坐标是否已经被Computer的棋子所占用(没有占用返回true)//
/////////////////////////////////////////////////////////////////////////////
{
return Result;
}
//////////////////////////////////////////////////////////////////////////////
// JudgeComCoordinate函数定义——开始 //
//判断一个坐标是否已经被Computer的棋子所占用(没有占用返回true)//
/////////////////////////////////////////////////////////////////////////////
bool Computer::JudgeComCoordinate(int x,int y)
{
int temp=0;
for(int i=0;i<ComCount;i++)
{
if(x==ComExistChessman[i].x&&y==ComExistChessman[i].y)
temp++;
}
if(temp==0&&x<NUM&&x>=0&&y<NUM&&y>=0)
return true;
else
return false;
}
//////////////////////////////////////////////////////////////////////////////
// JudgeComCoordinate函数定义——结束 //
//判断一个坐标是否已经被Computer的棋子所占用(没有占用返回true)//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// AddDefenNewCh函数定义——开始 //
// 在continuumChessmanOpp中确定防御下一步棋 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddDefenNewCh()
{
ContinuumChessman temp;
temp.two=(TwoChessman)malloc(sizeof(struct two));
temp.three=(ThreeChessman)malloc(sizeof(struct three));
temp.four=(FourChessman)malloc(sizeof(struct four));
temp=continuumChessmanOpp;
/////////////////如果有四个点连续,且有一端有空余位置,则将该位置设为相应优先级——开始///////////////
if(temp.CountFour!=0)
{
if(temp.four->FOUR[0].x==2*NUM&&temp.four->FOUR[0].y==2*NUM)//跳过头节点
temp.four=temp.four->next;
while(temp.four!=NULL)
{
int XChang=temp.four->FOUR[0].x-temp.four->FOUR[1].x;
int YChang=temp.four->FOUR[0].y-temp.four->FOUR[1].y;
if( JudgeCoordinate(temp.four->FOUR[0].x+XChang,temp.four->FOUR[0].y+YChang))
AddToComNext(temp.four->FOUR[0].x+XChang,temp.four->FOUR[0].y+YChang,DEFENPRI);
XChang=temp.four->FOUR[3].x-temp.four->FOUR[2].x;
YChang=temp.four->FOUR[3].y-temp.four->FOUR[2].y;
if( JudgeCoordinate(temp.four->FOUR[3].x+XChang,temp.four->FOUR[3].y+YChang))
AddToComNext(temp.four->FOUR[3].x+XChang,temp.four->FOUR[3].y+YChang,DEFENPRI);
temp.four=temp.four->next;
}
}
/////////////////如果有四个点连续,且有一端有空余位置,则将该位置设为相应优先级——结束///////////////
// AddDefenNewCh函数定义——开始 //
// 在continuumChessmanOpp中确定防御下一步棋 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddDefenNewCh()
{
ContinuumChessman temp;
temp.two=(TwoChessman)malloc(sizeof(struct two));
temp.three=(ThreeChessman)malloc(sizeof(struct three));
temp.four=(FourChessman)malloc(sizeof(struct four));
temp=continuumChessmanOpp;
/////////////////如果有四个点连续,且有一端有空余位置,则将该位置设为相应优先级——开始///////////////
if(temp.CountFour!=0)
{
if(temp.four->FOUR[0].x==2*NUM&&temp.four->FOUR[0].y==2*NUM)//跳过头节点
temp.four=temp.four->next;
while(temp.four!=NULL)
{
int XChang=temp.four->FOUR[0].x-temp.four->FOUR[1].x;
int YChang=temp.four->FOUR[0].y-temp.four->FOUR[1].y;
if( JudgeCoordinate(temp.four->FOUR[0].x+XChang,temp.four->FOUR[0].y+YChang))
AddToComNext(temp.four->FOUR[0].x+XChang,temp.four->FOUR[0].y+YChang,DEFENPRI);
XChang=temp.four->FOUR[3].x-temp.four->FOUR[2].x;
YChang=temp.four->FOUR[3].y-temp.four->FOUR[2].y;
if( JudgeCoordinate(temp.four->FOUR[3].x+XChang,temp.four->FOUR[3].y+YChang))
AddToComNext(temp.four->FOUR[3].x+XChang,temp.four->FOUR[3].y+YChang,DEFENPRI);
temp.four=temp.four->next;
}
}
/////////////////如果有四个点连续,且有一端有空余位置,则将该位置设为相应优先级——结束///////////////
/////////////////如果有三个点连续,且两端都有空余位置,则将该位置设为相应优先级——开始///////////////
temp=continuumChessmanOpp;
if(temp.CountThree!=0)
{
if(temp.three->THREE[0].x==2*NUM&&temp.three->THREE[0].y==2*NUM)//跳过头节点
temp.three=temp.three->next;
while(temp.three!=NULL)
{
int XChangA=temp.three->THREE[0].x-temp.three->THREE[1].x;
int YChangA=temp.three->THREE[0].y-temp.three->THREE[1].y;
int XChangB=temp.three->THREE[2].x-temp.three->THREE[1].x;
int YChangB=temp.three->THREE[2].y-temp.three->THREE[1].y;
if(JudgeCoordinate(temp.three->THREE[0].x+XChangA,temp.three->THREE[0].y+YChangA)&&
JudgeCoordinate(temp.three->THREE[2].x+XChangB,temp.three->THREE[2].y+XChangB))
{
AddToComNext(temp.three->THREE[0].x+XChangA,temp.three->THREE[0].y+YChangA,DEFENPRI+1);
AddToComNext(temp.three->THREE[2].x+XChangB,temp.three->THREE[2].y+YChangB,DEFENPRI+1);
}
temp.three=temp.three->next;
}//while
}
/////////////////如果有三个点连续,且两端都有空余位置,则将该位置设为相应优先级——结束///////////////
temp=continuumChessmanOpp;
if(temp.CountThree!=0)
{
if(temp.three->THREE[0].x==2*NUM&&temp.three->THREE[0].y==2*NUM)//跳过头节点
temp.three=temp.three->next;
while(temp.three!=NULL)
{
int XChangA=temp.three->THREE[0].x-temp.three->THREE[1].x;
int YChangA=temp.three->THREE[0].y-temp.three->THREE[1].y;
int XChangB=temp.three->THREE[2].x-temp.three->THREE[1].x;
int YChangB=temp.three->THREE[2].y-temp.three->THREE[1].y;
if(JudgeCoordinate(temp.three->THREE[0].x+XChangA,temp.three->THREE[0].y+YChangA)&&
JudgeCoordinate(temp.three->THREE[2].x+XChangB,temp.three->THREE[2].y+XChangB))
{
AddToComNext(temp.three->THREE[0].x+XChangA,temp.three->THREE[0].y+YChangA,DEFENPRI+1);
AddToComNext(temp.three->THREE[2].x+XChangB,temp.three->THREE[2].y+YChangB,DEFENPRI+1);
}
temp.three=temp.three->next;
}//while
}
/////////////////如果有三个点连续,且两端都有空余位置,则将该位置设为相应优先级——结束///////////////
/////////////////如果存在一个点使得两组或多组三个连续点产生,且这多组中至少有两组的两端都有空余位置,则将该位置设为相应优先级——开始///////////////
for(int a=0;a<NUM;a++)
for(int b=0;b<NUM;b++)
{
temp=continuumChessmanOpp;
int count=0;
if(JudgeCoordinate(a,b))
{
if(temp.two->TWO[0].x==2*NUM&&temp.two->TWO[0].y==2*NUM)//跳过头节点
temp.two=temp.two->next;
while(temp.two!=NULL)
{
int XChangA=temp.two->TWO[1].x-temp.two->TWO[0].x;
int YChangA=temp.two->TWO[1].y-temp.two->TWO[0].y;
int XChangB=temp.two->TWO[0].x-temp.two->TWO[1].x;
int YChangB=temp.two->TWO[0].y-temp.two->TWO[1].y;
if(XChangA==(temp.two->TWO[0].x-a)&& YChangA==(temp.two->TWO[0].y-b)&&
JudgeCoordinate(temp.two->TWO[0].x+XChangB,temp.two->TWO[0].y+XChangB)&&
JudgeCoordinate(temp.two->TWO[1].x+XChangA,temp.two->TWO[1].y+XChangA))
count++;
temp.two=temp.two->next;
}
}
if(count>=2)
AddToComNext(a,b,DEFENPRI+2);
}
/////////////////如果存在一个点使得两组或多组三个连续点产生,且这多组中至少有两组的两端都有空余位置,则将该位置设为相应优先级——结束///////////////
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddDefenNewCh函数定义——结束 //
// 在continuumChessmanOpp中确定防御下一步棋 //
////////////////////////////////////////////////////////////////////////////
for(int a=0;a<NUM;a++)
for(int b=0;b<NUM;b++)
{
temp=continuumChessmanOpp;
int count=0;
if(JudgeCoordinate(a,b))
{
if(temp.two->TWO[0].x==2*NUM&&temp.two->TWO[0].y==2*NUM)//跳过头节点
temp.two=temp.two->next;
while(temp.two!=NULL)
{
int XChangA=temp.two->TWO[1].x-temp.two->TWO[0].x;
int YChangA=temp.two->TWO[1].y-temp.two->TWO[0].y;
int XChangB=temp.two->TWO[0].x-temp.two->TWO[1].x;
int YChangB=temp.two->TWO[0].y-temp.two->TWO[1].y;
if(XChangA==(temp.two->TWO[0].x-a)&& YChangA==(temp.two->TWO[0].y-b)&&
JudgeCoordinate(temp.two->TWO[0].x+XChangB,temp.two->TWO[0].y+XChangB)&&
JudgeCoordinate(temp.two->TWO[1].x+XChangA,temp.two->TWO[1].y+XChangA))
count++;
temp.two=temp.two->next;
}
}
if(count>=2)
AddToComNext(a,b,DEFENPRI+2);
}
/////////////////如果存在一个点使得两组或多组三个连续点产生,且这多组中至少有两组的两端都有空余位置,则将该位置设为相应优先级——结束///////////////
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddDefenNewCh函数定义——结束 //
// 在continuumChessmanOpp中确定防御下一步棋 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// DeleConCheTwoOpp函数定义——开始 //
// 删除continuumChessmanOpp中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheTwoOpp(TwoChessman two)
{
ContinuumChessman temp=continuumChessmanOpp;
// DeleConCheTwoOpp函数定义——开始 //
// 删除continuumChessmanOpp中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheTwoOpp(TwoChessman two)
{
ContinuumChessman temp=continuumChessmanOpp;
if(temp.CountTwo==0)
{
std::cout<<"There is no continuumTwo data in continuumChessmanOpp/n";
return true;
}
while(temp.two!=NULL)
{
if(temp.two->next->TWO[0].x==two->TWO[0].x&&temp.two->next->TWO[0].y==two->TWO[0].y
&&temp.two->next->TWO[1].x==two->TWO[1].x&&temp.two->next->TWO[1].y==two->TWO[1].y)
{
TwoChessman TTwo=temp.two->next;
temp.two->next=temp.two->next->next;
free(TTwo);//释放temp.two->next所指的内存空间
continuumChessmanOpp.CountTwo--;
return true;
}
temp.two=temp.two->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheTwoOpp构造函数定义——开始 //
// 删除continuumChessmanOpp中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
{
std::cout<<"There is no continuumTwo data in continuumChessmanOpp/n";
return true;
}
while(temp.two!=NULL)
{
if(temp.two->next->TWO[0].x==two->TWO[0].x&&temp.two->next->TWO[0].y==two->TWO[0].y
&&temp.two->next->TWO[1].x==two->TWO[1].x&&temp.two->next->TWO[1].y==two->TWO[1].y)
{
TwoChessman TTwo=temp.two->next;
temp.two->next=temp.two->next->next;
free(TTwo);//释放temp.two->next所指的内存空间
continuumChessmanOpp.CountTwo--;
return true;
}
temp.two=temp.two->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheTwoOpp构造函数定义——开始 //
// 删除continuumChessmanOpp中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// DeleConCheThreeOpp构造函数定义——开始 //
// 删除continuumChessmanOpp中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheThreeOpp(ThreeChessman three)
{
ContinuumChessman temp=continuumChessmanOpp;
if(temp.CountThree==0)
{
std::cout<<"There is no continuumThree data in continuumChessmanOpp/n";
return true;
}
while(temp.three!=NULL)
{
if(temp.three->next->THREE[0].x==three->THREE[0].x&&temp.three->next->THREE[0].y==three->THREE[0].y&&
temp.three->next->THREE[1].x==three->THREE[1].x&&temp.three->next->THREE[1].y==three->THREE[1].y&&
temp.three->next->THREE[2].x==three->THREE[2].x&&temp.three->next->THREE[2].y==three->THREE[2].y)
{
ThreeChessman TThree=temp.three->next;
temp.three->next=temp.three->next->next;
free(TThree);//释放temp.three->next所指的内存空间
continuumChessmanOpp.CountThree--;
return true;
}
temp.three=temp.three->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheThreeOpp构造函数定义——结束 //
// 删除continuumChessmanOpp中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
// DeleConCheThreeOpp构造函数定义——开始 //
// 删除continuumChessmanOpp中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheThreeOpp(ThreeChessman three)
{
ContinuumChessman temp=continuumChessmanOpp;
if(temp.CountThree==0)
{
std::cout<<"There is no continuumThree data in continuumChessmanOpp/n";
return true;
}
while(temp.three!=NULL)
{
if(temp.three->next->THREE[0].x==three->THREE[0].x&&temp.three->next->THREE[0].y==three->THREE[0].y&&
temp.three->next->THREE[1].x==three->THREE[1].x&&temp.three->next->THREE[1].y==three->THREE[1].y&&
temp.three->next->THREE[2].x==three->THREE[2].x&&temp.three->next->THREE[2].y==three->THREE[2].y)
{
ThreeChessman TThree=temp.three->next;
temp.three->next=temp.three->next->next;
free(TThree);//释放temp.three->next所指的内存空间
continuumChessmanOpp.CountThree--;
return true;
}
temp.three=temp.three->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheThreeOpp构造函数定义——结束 //
// 删除continuumChessmanOpp中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// AddToContinuumChessmanOpp构造函数定义——开始 //
// 添加一个点到continuumChessmanOpp数据成员中 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddToContinuumChessmanOpp(int x,int y)
{
ContinuumChessman temp;
temp.two=(TwoChessman)malloc(sizeof(struct two));
temp.three=(ThreeChessman)malloc(sizeof(struct three));
temp.four=(FourChessman)malloc(sizeof(struct four));
temp=continuumChessmanOpp;
// if(temp.CountTwo==0&&temp.CountThree==0&&temp.CountFour==0)//如果没有连续的点,判断可不可以与其他的分散点组成连续的点
// {
/////////////////没有连续的点-开始////////////////////////////////////////////
for(int i=0;i<OppCount;i++)
{
if(x-1==OppExistChessman[i].x&&y==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=OppExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
// AddToContinuumChessmanOpp构造函数定义——开始 //
// 添加一个点到continuumChessmanOpp数据成员中 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddToContinuumChessmanOpp(int x,int y)
{
ContinuumChessman temp;
temp.two=(TwoChessman)malloc(sizeof(struct two));
temp.three=(ThreeChessman)malloc(sizeof(struct three));
temp.four=(FourChessman)malloc(sizeof(struct four));
temp=continuumChessmanOpp;
// if(temp.CountTwo==0&&temp.CountThree==0&&temp.CountFour==0)//如果没有连续的点,判断可不可以与其他的分散点组成连续的点
// {
/////////////////没有连续的点-开始////////////////////////////////////////////
for(int i=0;i<OppCount;i++)
{
if(x-1==OppExistChessman[i].x&&y==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=OppExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
for(int i=0;i<OppCount;i++)
{
if(x+1==OppExistChessman[i].x&&y==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
{
if(x+1==OppExistChessman[i].x&&y==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
for(int i=0;i<OppCount;i++)
{
if(x==OppExistChessman[i].x&&y-1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=OppExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
{
if(x==OppExistChessman[i].x&&y-1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=OppExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
for(int i=0;i<OppCount;i++)
{
if(x==OppExistChessman[i].x&&y+1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
{
if(x==OppExistChessman[i].x&&y+1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
for(int i=0;i<OppCount;i++)
{
if(x-1==OppExistChessman[i].x&&y-1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=OppExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
{
if(x-1==OppExistChessman[i].x&&y-1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=OppExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
for(int i=0;i<OppCount;i++)
{
if(x+1==OppExistChessman[i].x&&y+1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
{
if(x+1==OppExistChessman[i].x&&y+1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
for(int i=0;i<OppCount;i++)
{
if(x+1==OppExistChessman[i].x&&y-1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
{
if(x+1==OppExistChessman[i].x&&y-1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
for(int i=0;i<OppCount;i++)
{
if(x-1==OppExistChessman[i].x&&y+1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
/////////////////没有连续的点-结束////////////////////////////////////////////
//}
// else//有连续的点
// {
///////////////两个连续的棋子-开始////////////////////////
temp=continuumChessmanOpp;
TwoChessman DeleTwo[NUM*NUM];
int DeleCountTwo=0;
if(temp.two->TWO[0].x==2*NUM&&temp.two->TWO[0].y==2*NUM)//跳过头节点
temp.two=temp.two->next;
while(temp.two!=NULL)
{
if((temp.two->TWO[1].x-temp.two->TWO[0].x)==(temp.two->TWO[0].x-x)&&
(temp.two->TWO[1].y-temp.two->TWO[0].y)==(temp.two->TWO[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.three->next!=NULL)temp.three=temp.three->next;
ThreeChessman tempThree_0=(ThreeChessman)malloc(sizeof(struct three));
tempThree_0->THREE[0].x=x;
tempThree_0->THREE[0].y=y;
tempThree_0->THREE[1]=temp.two->TWO[0];
tempThree_0->THREE[2]=temp.two->TWO[1];
tempThree_0->next=NULL;
temp.three->next=tempThree_0;
continuumChessmanOpp.CountThree++;
//////////////加入到删除列表////////////////
DeleTwo[DeleCountTwo]=temp.two;
DeleCountTwo++;
//////////////加入到删除列表////////////////
// TwoChessman TwoTemp1=temp.two;
// temp.two=temp.two->next;
// DeleConCheTwoOpp(TwoTemp1); //删除temp.two这个链表节点
// DeleConCheTwoOpp(temp.two);
// goto LABLE1;
// continuumChessmanCom.CountTwo--;
}
if((temp.two->TWO[0].x-temp.two->TWO[1].x)==(temp.two->TWO[1].x-x)&&
(temp.two->TWO[0].y-temp.two->TWO[1].y)==(temp.two->TWO[1].y-y))//新的点加在temp.two->TWO[1]的后面
{
while(temp.three->next!=NULL)temp.three=temp.three->next;
ThreeChessman tempThree_1=(ThreeChessman)malloc(sizeof(struct three));
tempThree_1->THREE[0]=temp.two->TWO[0];
tempThree_1->THREE[1]=temp.two->TWO[1];
tempThree_1->THREE[2].x=x;
tempThree_1->THREE[2].y=y;
tempThree_1->next=NULL;
temp.three->next=tempThree_1;
continuumChessmanOpp.CountThree++;
//////////////加入到删除列表////////////////
DeleTwo[DeleCountTwo]=temp.two;
DeleCountTwo++;
//////////////加入到删除列表////////////////
}
temp.two=temp.two->next;
}//while
while(DeleCountTwo!=0)
{
DeleConCheTwoOpp(DeleTwo[DeleCountTwo-1]);
DeleCountTwo--;
}
///////////////两个连续的棋子-结束////////////////////////
//LABLE1:
///////////////三个连续的棋子-开始////////////////////////
temp=continuumChessmanOpp;
ThreeChessman DeleThree[NUM*NUM];
int DeleCountThree=0;
if(temp.three->THREE[0].x==2*NUM&&temp.three->THREE[0].y==2*NUM)
temp.three=temp.three->next;
while(temp.three!=NULL)
{
if((temp.three->THREE[2].x-temp.three->THREE[1].x)==(temp.three->THREE[0].x-x)&&
(temp.three->THREE[2].y-temp.three->THREE[1].y)==(temp.three->THREE[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0].x=x;
tempFour_0->FOUR[0].y=y;
tempFour_0->FOUR[1]=temp.three->THREE[0];
tempFour_0->FOUR[2]=temp.three->THREE[1];
tempFour_0->FOUR[3]=temp.three->THREE[2];
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanOpp.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
}
if((temp.three->THREE[0].x-temp.three->THREE[1].x)==(temp.three->THREE[2].x-x)&&
(temp.three->THREE[0].y-temp.three->THREE[1].y)==(temp.three->THREE[2].y-y))//新的点加在temp.two->TWO[2]的后面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0]=temp.three->THREE[0];
tempFour_0->FOUR[1]=temp.three->THREE[1];
tempFour_0->FOUR[2]=temp.three->THREE[2];
tempFour_0->FOUR[3].x=x;
tempFour_0->FOUR[3].y=y;
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanOpp.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
}
temp.three=temp.three->next;
}//while
while(DeleCountThree!=0)
{
DeleConCheThreeOpp(DeleThree[DeleCountThree-1]);
DeleCountThree--;
}
///////////////三个连续的棋子-结束////////////////////////
{
if(x-1==OppExistChessman[i].x&&y+1==OppExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=OppExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanOpp.CountTwo++;
}
}
/////////////////没有连续的点-结束////////////////////////////////////////////
//}
// else//有连续的点
// {
///////////////两个连续的棋子-开始////////////////////////
temp=continuumChessmanOpp;
TwoChessman DeleTwo[NUM*NUM];
int DeleCountTwo=0;
if(temp.two->TWO[0].x==2*NUM&&temp.two->TWO[0].y==2*NUM)//跳过头节点
temp.two=temp.two->next;
while(temp.two!=NULL)
{
if((temp.two->TWO[1].x-temp.two->TWO[0].x)==(temp.two->TWO[0].x-x)&&
(temp.two->TWO[1].y-temp.two->TWO[0].y)==(temp.two->TWO[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.three->next!=NULL)temp.three=temp.three->next;
ThreeChessman tempThree_0=(ThreeChessman)malloc(sizeof(struct three));
tempThree_0->THREE[0].x=x;
tempThree_0->THREE[0].y=y;
tempThree_0->THREE[1]=temp.two->TWO[0];
tempThree_0->THREE[2]=temp.two->TWO[1];
tempThree_0->next=NULL;
temp.three->next=tempThree_0;
continuumChessmanOpp.CountThree++;
//////////////加入到删除列表////////////////
DeleTwo[DeleCountTwo]=temp.two;
DeleCountTwo++;
//////////////加入到删除列表////////////////
// TwoChessman TwoTemp1=temp.two;
// temp.two=temp.two->next;
// DeleConCheTwoOpp(TwoTemp1); //删除temp.two这个链表节点
// DeleConCheTwoOpp(temp.two);
// goto LABLE1;
// continuumChessmanCom.CountTwo--;
}
if((temp.two->TWO[0].x-temp.two->TWO[1].x)==(temp.two->TWO[1].x-x)&&
(temp.two->TWO[0].y-temp.two->TWO[1].y)==(temp.two->TWO[1].y-y))//新的点加在temp.two->TWO[1]的后面
{
while(temp.three->next!=NULL)temp.three=temp.three->next;
ThreeChessman tempThree_1=(ThreeChessman)malloc(sizeof(struct three));
tempThree_1->THREE[0]=temp.two->TWO[0];
tempThree_1->THREE[1]=temp.two->TWO[1];
tempThree_1->THREE[2].x=x;
tempThree_1->THREE[2].y=y;
tempThree_1->next=NULL;
temp.three->next=tempThree_1;
continuumChessmanOpp.CountThree++;
//////////////加入到删除列表////////////////
DeleTwo[DeleCountTwo]=temp.two;
DeleCountTwo++;
//////////////加入到删除列表////////////////
}
temp.two=temp.two->next;
}//while
while(DeleCountTwo!=0)
{
DeleConCheTwoOpp(DeleTwo[DeleCountTwo-1]);
DeleCountTwo--;
}
///////////////两个连续的棋子-结束////////////////////////
//LABLE1:
///////////////三个连续的棋子-开始////////////////////////
temp=continuumChessmanOpp;
ThreeChessman DeleThree[NUM*NUM];
int DeleCountThree=0;
if(temp.three->THREE[0].x==2*NUM&&temp.three->THREE[0].y==2*NUM)
temp.three=temp.three->next;
while(temp.three!=NULL)
{
if((temp.three->THREE[2].x-temp.three->THREE[1].x)==(temp.three->THREE[0].x-x)&&
(temp.three->THREE[2].y-temp.three->THREE[1].y)==(temp.three->THREE[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0].x=x;
tempFour_0->FOUR[0].y=y;
tempFour_0->FOUR[1]=temp.three->THREE[0];
tempFour_0->FOUR[2]=temp.three->THREE[1];
tempFour_0->FOUR[3]=temp.three->THREE[2];
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanOpp.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
}
if((temp.three->THREE[0].x-temp.three->THREE[1].x)==(temp.three->THREE[2].x-x)&&
(temp.three->THREE[0].y-temp.three->THREE[1].y)==(temp.three->THREE[2].y-y))//新的点加在temp.two->TWO[2]的后面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0]=temp.three->THREE[0];
tempFour_0->FOUR[1]=temp.three->THREE[1];
tempFour_0->FOUR[2]=temp.three->THREE[2];
tempFour_0->FOUR[3].x=x;
tempFour_0->FOUR[3].y=y;
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanOpp.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
}
temp.three=temp.three->next;
}//while
while(DeleCountThree!=0)
{
DeleConCheThreeOpp(DeleThree[DeleCountThree-1]);
DeleCountThree--;
}
///////////////三个连续的棋子-结束////////////////////////
///////////////四个连续的棋子-开始////////////////////////
temp=continuumChessmanOpp;
if(temp.four->FOUR[0].x==2*NUM&&temp.four->FOUR[0].y==2*NUM)
temp.four=temp.four->next;
while(temp.four!=NULL)
{
if((temp.four->FOUR[3].x-temp.four->FOUR[2].x)==(temp.four->FOUR[0].x-x)&&
(temp.four->FOUR[3].y-temp.four->FOUR[2].y)==(temp.four->FOUR[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
Result=2;
std::cout<<"You have win !/n";
return true;
//执行一方胜利的函数
}
if((temp.four->FOUR[0].x-temp.four->FOUR[1].x)==(temp.four->FOUR[3].x-x)&&
(temp.four->FOUR[0].y-temp.four->FOUR[1].y)==(temp.four->FOUR[3].y-y))//新的点加在temp.two->TWO[2]的后面
{
Result=2;
std::cout<<"You have win !/n";
//执行一方胜利的函数
return true;
}
temp.four=temp.four->next;
}
///////////////四个连续的棋子-结束////////////////////////
// }//else
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddToContinuumChessmanOpp构造函数定义——结束 //
// 添加一个点到continuumChessmanOpp数据成员中 //
////////////////////////////////////////////////////////////////////////////
temp=continuumChessmanOpp;
if(temp.four->FOUR[0].x==2*NUM&&temp.four->FOUR[0].y==2*NUM)
temp.four=temp.four->next;
while(temp.four!=NULL)
{
if((temp.four->FOUR[3].x-temp.four->FOUR[2].x)==(temp.four->FOUR[0].x-x)&&
(temp.four->FOUR[3].y-temp.four->FOUR[2].y)==(temp.four->FOUR[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
Result=2;
std::cout<<"You have win !/n";
return true;
//执行一方胜利的函数
}
if((temp.four->FOUR[0].x-temp.four->FOUR[1].x)==(temp.four->FOUR[3].x-x)&&
(temp.four->FOUR[0].y-temp.four->FOUR[1].y)==(temp.four->FOUR[3].y-y))//新的点加在temp.two->TWO[2]的后面
{
Result=2;
std::cout<<"You have win !/n";
//执行一方胜利的函数
return true;
}
temp.four=temp.four->next;
}
///////////////四个连续的棋子-结束////////////////////////
// }//else
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddToContinuumChessmanOpp构造函数定义——结束 //
// 添加一个点到continuumChessmanOpp数据成员中 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// AddNewChessmanOpp构造函数定义——开始 //
// 添加新的棋子到OppExistChessman和 //
// continuumChessmanOpp数据成员 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddNewChessmanOpp()
{
int tempX=2*NUM,tempY=2*NUM;
std::cout<<"输入新棋子的x坐标:";
std::cin>>tempX;
std::cout<<"输入新棋子的y坐标:";
std::cin>>tempY;
if(JudgeCoordinate(tempX,tempY))//检查该点是否已经被占用
{
OppExistChessman[OppCount].x=tempX;
OppExistChessman[OppCount].y=tempY;
AddToContinuumChessmanOpp(tempX,tempY);
OppCount++;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddNewChessmanOpp构造函数定义——结束 //
// 添加新的棋子到OppExistChessman和 //
// continuumChessmanOpp数据成员 //
////////////////////////////////////////////////////////////////////////////
// AddNewChessmanOpp构造函数定义——开始 //
// 添加新的棋子到OppExistChessman和 //
// continuumChessmanOpp数据成员 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddNewChessmanOpp()
{
int tempX=2*NUM,tempY=2*NUM;
std::cout<<"输入新棋子的x坐标:";
std::cin>>tempX;
std::cout<<"输入新棋子的y坐标:";
std::cin>>tempY;
if(JudgeCoordinate(tempX,tempY))//检查该点是否已经被占用
{
OppExistChessman[OppCount].x=tempX;
OppExistChessman[OppCount].y=tempY;
AddToContinuumChessmanOpp(tempX,tempY);
OppCount++;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddNewChessmanOpp构造函数定义——结束 //
// 添加新的棋子到OppExistChessman和 //
// continuumChessmanOpp数据成员 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Computer构造函数定义开始 //
// 构造函数,初始化该类的各数据成员 //
////////////////////////////////////////////////////////////////////////////
Computer::Computer()
{
///////////初始化OppExistChessman成员-开始/////////////
for(int i=0;i<(NUM*NUM)/2+1;i++)
{
OppExistChessman[i].x=2*NUM; //表示这个值一定不会是坐标
OppExistChessman[i].y=2*NUM;
}
///////////初始化OppExistChessman成员-结束/////////////
///////////初始化continuumChessmanCom成员-开始/////////////
continuumChessmanCom.two=(TwoChessman)malloc(sizeof(struct two)); //分配该链表的头结点
continuumChessmanCom.two->TWO[0].x=2*NUM;
continuumChessmanCom.two->TWO[0].y=2*NUM;
continuumChessmanCom.two->TWO[1].x=2*NUM;
continuumChessmanCom.two->TWO[1].y=2*NUM;
continuumChessmanCom.two->next=NULL;
continuumChessmanCom.CountTwo=0;
continuumChessmanCom.three=(ThreeChessman)malloc(sizeof(struct three));//分配该链表的头结点
continuumChessmanCom.three->THREE[0].x=2*NUM;
continuumChessmanCom.three->THREE[0].y=2*NUM;
continuumChessmanCom.three->THREE[1].x=2*NUM;
continuumChessmanCom.three->THREE[1].y=2*NUM;
continuumChessmanCom.three->THREE[2].x=2*NUM;
continuumChessmanCom.three->THREE[2].y=2*NUM;
continuumChessmanCom.three->next=NULL;
continuumChessmanCom.CountThree=0;
continuumChessmanCom.four=(FourChessman)malloc(sizeof(struct four));//分配该链表的头结点
continuumChessmanCom.four->FOUR[0].x=2*NUM;
continuumChessmanCom.four->FOUR[0].y=2*NUM;
continuumChessmanCom.four->FOUR[1].x=2*NUM;
continuumChessmanCom.four->FOUR[1].y=2*NUM;
continuumChessmanCom.four->FOUR[2].x=2*NUM;
continuumChessmanCom.four->FOUR[2].y=2*NUM;
continuumChessmanCom.four->FOUR[3].x=2*NUM;
continuumChessmanCom.four->FOUR[3].y=2*NUM;
continuumChessmanCom.four->next=NULL;
continuumChessmanCom.CountFour=0;
///////////初始化continuumChessmanCom成员-结束/////////////
///////////初始化ComCount成员-开始/////////////
ComCount=0;
///////////初始化ComCount成员-结束/////////////
///////////初始化ComNext成员-开始/////////////
for(int i=0;i<MAXPRI;i++)
{
ComNext.PRI[i]=(LPoint)malloc(sizeof(struct po));//分配该链表的头结点
ComNext.PRI[i]->point.x=3*NUM;
ComNext.PRI[i]->point.y=3*NUM;
ComNext.PRI[i]->next=NULL;
}
///////////初始化ComNext成员-结束/////////////
//**********************************************************//
///////////初始化ComExistChessman成员-开始/////////////
for(int i=0;i<(NUM*NUM)/2+1;i++)
{
ComExistChessman[i].x=2*NUM;
ComExistChessman[i].y=2*NUM;
}
///////////初始化ComExistChessman成员-结束/////////////
///////////初始化continuumChessmanOpp成员-开始/////////////
continuumChessmanOpp.two=(TwoChessman)malloc(sizeof(struct two));//分配该链表的头结点
continuumChessmanOpp.two->TWO[0].x=2*NUM;
continuumChessmanOpp.two->TWO[0].y=2*NUM;
continuumChessmanOpp.two->TWO[1].x=2*NUM;
continuumChessmanOpp.two->TWO[1].y=2*NUM;
continuumChessmanOpp.two->next=NULL;
continuumChessmanOpp.CountTwo=0;
continuumChessmanOpp.three=(ThreeChessman)malloc(sizeof(struct three));//分配该链表的头结点
continuumChessmanOpp.three->THREE[0].x=2*NUM;
continuumChessmanOpp.three->THREE[0].y=2*NUM;
continuumChessmanOpp.three->THREE[1].x=2*NUM;
continuumChessmanOpp.three->THREE[1].y=2*NUM;
continuumChessmanOpp.three->THREE[2].x=2*NUM;
continuumChessmanOpp.three->THREE[2].y=2*NUM;
continuumChessmanOpp.three->next=NULL;
continuumChessmanOpp.CountThree=0;
continuumChessmanOpp.four=(FourChessman)malloc(sizeof(struct four));//分配该链表的头结点
continuumChessmanOpp.four->FOUR[0].x=2*NUM;
continuumChessmanOpp.four->FOUR[0].y=2*NUM;
continuumChessmanOpp.four->FOUR[1].x=2*NUM;
continuumChessmanOpp.four->FOUR[1].y=2*NUM;
continuumChessmanOpp.four->FOUR[2].x=2*NUM;
continuumChessmanOpp.four->FOUR[2].y=2*NUM;
continuumChessmanOpp.four->FOUR[3].x=2*NUM;
continuumChessmanOpp.four->FOUR[3].y=2*NUM;
continuumChessmanOpp.four->next=NULL;
continuumChessmanOpp.CountFour=0;
///////////初始化continuumChessmanOpp成员-结束/////////////
///////////初始化OppCount成员-开始/////////////
OppCount=0;
///////////初始化OppCount成员-结束/////////////
///////////初始化OppNext成员-开始/////////////
for(int i=0;i<MAXPRI;i++)
{
OppNext.PRI[i]=(LPoint)malloc(sizeof(struct po));//分配该链表的头结点
OppNext.PRI[i]->point.x=3*NUM;
OppNext.PRI[i]->point.y=3*NUM;
OppNext.PRI[i]->next=NULL;
}
///////////初始化OppNext成员-结束/////////////
///////////初始化Result成员-开始/////////////
Result=0;
///////////初始化Result成员-结束/////////////
}
/////////////////////////////////////////////////////////////////////////////
// Computer构造函数定义结束 //
// 构造函数,初始化该类的各数据成员 //
////////////////////////////////////////////////////////////////////////////
// Computer构造函数定义开始 //
// 构造函数,初始化该类的各数据成员 //
////////////////////////////////////////////////////////////////////////////
Computer::Computer()
{
///////////初始化OppExistChessman成员-开始/////////////
for(int i=0;i<(NUM*NUM)/2+1;i++)
{
OppExistChessman[i].x=2*NUM; //表示这个值一定不会是坐标
OppExistChessman[i].y=2*NUM;
}
///////////初始化OppExistChessman成员-结束/////////////
///////////初始化continuumChessmanCom成员-开始/////////////
continuumChessmanCom.two=(TwoChessman)malloc(sizeof(struct two)); //分配该链表的头结点
continuumChessmanCom.two->TWO[0].x=2*NUM;
continuumChessmanCom.two->TWO[0].y=2*NUM;
continuumChessmanCom.two->TWO[1].x=2*NUM;
continuumChessmanCom.two->TWO[1].y=2*NUM;
continuumChessmanCom.two->next=NULL;
continuumChessmanCom.CountTwo=0;
continuumChessmanCom.three=(ThreeChessman)malloc(sizeof(struct three));//分配该链表的头结点
continuumChessmanCom.three->THREE[0].x=2*NUM;
continuumChessmanCom.three->THREE[0].y=2*NUM;
continuumChessmanCom.three->THREE[1].x=2*NUM;
continuumChessmanCom.three->THREE[1].y=2*NUM;
continuumChessmanCom.three->THREE[2].x=2*NUM;
continuumChessmanCom.three->THREE[2].y=2*NUM;
continuumChessmanCom.three->next=NULL;
continuumChessmanCom.CountThree=0;
continuumChessmanCom.four=(FourChessman)malloc(sizeof(struct four));//分配该链表的头结点
continuumChessmanCom.four->FOUR[0].x=2*NUM;
continuumChessmanCom.four->FOUR[0].y=2*NUM;
continuumChessmanCom.four->FOUR[1].x=2*NUM;
continuumChessmanCom.four->FOUR[1].y=2*NUM;
continuumChessmanCom.four->FOUR[2].x=2*NUM;
continuumChessmanCom.four->FOUR[2].y=2*NUM;
continuumChessmanCom.four->FOUR[3].x=2*NUM;
continuumChessmanCom.four->FOUR[3].y=2*NUM;
continuumChessmanCom.four->next=NULL;
continuumChessmanCom.CountFour=0;
///////////初始化continuumChessmanCom成员-结束/////////////
///////////初始化ComCount成员-开始/////////////
ComCount=0;
///////////初始化ComCount成员-结束/////////////
///////////初始化ComNext成员-开始/////////////
for(int i=0;i<MAXPRI;i++)
{
ComNext.PRI[i]=(LPoint)malloc(sizeof(struct po));//分配该链表的头结点
ComNext.PRI[i]->point.x=3*NUM;
ComNext.PRI[i]->point.y=3*NUM;
ComNext.PRI[i]->next=NULL;
}
///////////初始化ComNext成员-结束/////////////
//**********************************************************//
///////////初始化ComExistChessman成员-开始/////////////
for(int i=0;i<(NUM*NUM)/2+1;i++)
{
ComExistChessman[i].x=2*NUM;
ComExistChessman[i].y=2*NUM;
}
///////////初始化ComExistChessman成员-结束/////////////
///////////初始化continuumChessmanOpp成员-开始/////////////
continuumChessmanOpp.two=(TwoChessman)malloc(sizeof(struct two));//分配该链表的头结点
continuumChessmanOpp.two->TWO[0].x=2*NUM;
continuumChessmanOpp.two->TWO[0].y=2*NUM;
continuumChessmanOpp.two->TWO[1].x=2*NUM;
continuumChessmanOpp.two->TWO[1].y=2*NUM;
continuumChessmanOpp.two->next=NULL;
continuumChessmanOpp.CountTwo=0;
continuumChessmanOpp.three=(ThreeChessman)malloc(sizeof(struct three));//分配该链表的头结点
continuumChessmanOpp.three->THREE[0].x=2*NUM;
continuumChessmanOpp.three->THREE[0].y=2*NUM;
continuumChessmanOpp.three->THREE[1].x=2*NUM;
continuumChessmanOpp.three->THREE[1].y=2*NUM;
continuumChessmanOpp.three->THREE[2].x=2*NUM;
continuumChessmanOpp.three->THREE[2].y=2*NUM;
continuumChessmanOpp.three->next=NULL;
continuumChessmanOpp.CountThree=0;
continuumChessmanOpp.four=(FourChessman)malloc(sizeof(struct four));//分配该链表的头结点
continuumChessmanOpp.four->FOUR[0].x=2*NUM;
continuumChessmanOpp.four->FOUR[0].y=2*NUM;
continuumChessmanOpp.four->FOUR[1].x=2*NUM;
continuumChessmanOpp.four->FOUR[1].y=2*NUM;
continuumChessmanOpp.four->FOUR[2].x=2*NUM;
continuumChessmanOpp.four->FOUR[2].y=2*NUM;
continuumChessmanOpp.four->FOUR[3].x=2*NUM;
continuumChessmanOpp.four->FOUR[3].y=2*NUM;
continuumChessmanOpp.four->next=NULL;
continuumChessmanOpp.CountFour=0;
///////////初始化continuumChessmanOpp成员-结束/////////////
///////////初始化OppCount成员-开始/////////////
OppCount=0;
///////////初始化OppCount成员-结束/////////////
///////////初始化OppNext成员-开始/////////////
for(int i=0;i<MAXPRI;i++)
{
OppNext.PRI[i]=(LPoint)malloc(sizeof(struct po));//分配该链表的头结点
OppNext.PRI[i]->point.x=3*NUM;
OppNext.PRI[i]->point.y=3*NUM;
OppNext.PRI[i]->next=NULL;
}
///////////初始化OppNext成员-结束/////////////
///////////初始化Result成员-开始/////////////
Result=0;
///////////初始化Result成员-结束/////////////
}
/////////////////////////////////////////////////////////////////////////////
// Computer构造函数定义结束 //
// 构造函数,初始化该类的各数据成员 //
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// AttackNextPri0函数定义——开始 //
// 计算出进攻下一步棋的所有可能情况,并加入到ComNext数据成员中 //
////////////////////////////////////////////////////////////////////////////////////////
bool Computer::AttackNextPri0()
{
ContinuumChessman TContinuumChessman=continuumChessmanCom;
if(ComCount==0)//如果这是第一步棋子
{
AddToComNext(5,6,PRI_0);
}
else//一下为这不是第一步棋的情况
{
/////////////如果所有电脑棋子都不连续-开始//////////////////////////////////////////////////////////////////
if(TContinuumChessman.CountTwo==0&&TContinuumChessman.CountThree==0&&TContinuumChessman.CountFour==0)
{
for(int i=0;i<ComCount;i++)//ComExistChessman[0]到ComExistChessman[ComCount-1]存储的是已经有了的棋子
{
if(JudgeCoordinate(ComExistChessman[i].x-1,ComExistChessman[i].y)&&JudgeComNext(ComExistChessman[i].x-1,ComExistChessman[i].y))
{
AddToComNext(ComExistChessman[i].x-1,ComExistChessman[i].y,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x+1,ComExistChessman[i].y)&&JudgeComNext(ComExistChessman[i].x+1,ComExistChessman[i].y))
{
AddToComNext(ComExistChessman[i].x+1,ComExistChessman[i].y,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x,ComExistChessman[i].y-1)&&JudgeComNext(ComExistChessman[i].x,ComExistChessman[i].y-1))
{
AddToComNext(ComExistChessman[i].x,ComExistChessman[i].y-1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x,ComExistChessman[i].y+1)&&JudgeComNext(ComExistChessman[i].x,ComExistChessman[i].y+1))
{
AddToComNext(ComExistChessman[i].x,ComExistChessman[i].y+1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x-1,ComExistChessman[i].y-1)&&JudgeComNext(ComExistChessman[i].x-1,ComExistChessman[i].y-1))
{
AddToComNext(ComExistChessman[i].x-1,ComExistChessman[i].y-1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x+1,ComExistChessman[i].y+1)&&JudgeComNext(ComExistChessman[i].x+1,ComExistChessman[i].y+1))
{
AddToComNext(ComExistChessman[i].x+1,ComExistChessman[i].y+1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x-1,ComExistChessman[i].y+1)&&JudgeComNext(ComExistChessman[i].x-1,ComExistChessman[i].y+1))
{
AddToComNext(ComExistChessman[i].x-1,ComExistChessman[i].y+1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x+1,ComExistChessman[i].y-1)&&JudgeComNext(ComExistChessman[i].x+1,ComExistChessman[i].y-1))
{
AddToComNext(ComExistChessman[i].x+1,ComExistChessman[i].y-1,PRI_0);
}
}
}
/////////////如果所有电脑棋子都不连续-结束//////////////////////////////////////////////////////////////////
else//以下为电脑的棋子有为连续的情况
{
/////////////////////////////计算连续两个棋子为一组的可能下一步——开始//////////////////////////
if(TContinuumChessman.CountTwo!=0)
{
if(TContinuumChessman.two->TWO[0].x==2*NUM&&
TContinuumChessman.two->TWO[0].y==2*NUM)//跳跃过头节点
TContinuumChessman.two=TContinuumChessman.two->next;
while(TContinuumChessman.two!=NULL)
{
for(int i=0;i<2;i++)
{
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y))
{
AddToComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y))
{
AddToComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y-1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y-1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y+1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y+1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y-1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y-1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y+1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y+1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y+1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y+1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y-1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y-1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y-1,PRI_0);
}
}//for
TContinuumChessman.two= TContinuumChessman.two->next;
}
}
///////////////////////////计算连续两个棋子为一组的可能下一步——结束//////////////////////////
// AttackNextPri0函数定义——开始 //
// 计算出进攻下一步棋的所有可能情况,并加入到ComNext数据成员中 //
////////////////////////////////////////////////////////////////////////////////////////
bool Computer::AttackNextPri0()
{
ContinuumChessman TContinuumChessman=continuumChessmanCom;
if(ComCount==0)//如果这是第一步棋子
{
AddToComNext(5,6,PRI_0);
}
else//一下为这不是第一步棋的情况
{
/////////////如果所有电脑棋子都不连续-开始//////////////////////////////////////////////////////////////////
if(TContinuumChessman.CountTwo==0&&TContinuumChessman.CountThree==0&&TContinuumChessman.CountFour==0)
{
for(int i=0;i<ComCount;i++)//ComExistChessman[0]到ComExistChessman[ComCount-1]存储的是已经有了的棋子
{
if(JudgeCoordinate(ComExistChessman[i].x-1,ComExistChessman[i].y)&&JudgeComNext(ComExistChessman[i].x-1,ComExistChessman[i].y))
{
AddToComNext(ComExistChessman[i].x-1,ComExistChessman[i].y,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x+1,ComExistChessman[i].y)&&JudgeComNext(ComExistChessman[i].x+1,ComExistChessman[i].y))
{
AddToComNext(ComExistChessman[i].x+1,ComExistChessman[i].y,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x,ComExistChessman[i].y-1)&&JudgeComNext(ComExistChessman[i].x,ComExistChessman[i].y-1))
{
AddToComNext(ComExistChessman[i].x,ComExistChessman[i].y-1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x,ComExistChessman[i].y+1)&&JudgeComNext(ComExistChessman[i].x,ComExistChessman[i].y+1))
{
AddToComNext(ComExistChessman[i].x,ComExistChessman[i].y+1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x-1,ComExistChessman[i].y-1)&&JudgeComNext(ComExistChessman[i].x-1,ComExistChessman[i].y-1))
{
AddToComNext(ComExistChessman[i].x-1,ComExistChessman[i].y-1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x+1,ComExistChessman[i].y+1)&&JudgeComNext(ComExistChessman[i].x+1,ComExistChessman[i].y+1))
{
AddToComNext(ComExistChessman[i].x+1,ComExistChessman[i].y+1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x-1,ComExistChessman[i].y+1)&&JudgeComNext(ComExistChessman[i].x-1,ComExistChessman[i].y+1))
{
AddToComNext(ComExistChessman[i].x-1,ComExistChessman[i].y+1,PRI_0);
}
if(JudgeCoordinate(ComExistChessman[i].x+1,ComExistChessman[i].y-1)&&JudgeComNext(ComExistChessman[i].x+1,ComExistChessman[i].y-1))
{
AddToComNext(ComExistChessman[i].x+1,ComExistChessman[i].y-1,PRI_0);
}
}
}
/////////////如果所有电脑棋子都不连续-结束//////////////////////////////////////////////////////////////////
else//以下为电脑的棋子有为连续的情况
{
/////////////////////////////计算连续两个棋子为一组的可能下一步——开始//////////////////////////
if(TContinuumChessman.CountTwo!=0)
{
if(TContinuumChessman.two->TWO[0].x==2*NUM&&
TContinuumChessman.two->TWO[0].y==2*NUM)//跳跃过头节点
TContinuumChessman.two=TContinuumChessman.two->next;
while(TContinuumChessman.two!=NULL)
{
for(int i=0;i<2;i++)
{
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y))
{
AddToComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y))
{
AddToComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y-1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y-1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y+1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y+1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x,TContinuumChessman.two->TWO[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y-1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y-1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y+1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y+1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y+1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y+1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x-1,TContinuumChessman.two->TWO[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y-1)&&
JudgeComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y-1))
{
AddToComNext(TContinuumChessman.two->TWO[i].x+1,TContinuumChessman.two->TWO[i].y-1,PRI_0);
}
}//for
TContinuumChessman.two= TContinuumChessman.two->next;
}
}
///////////////////////////计算连续两个棋子为一组的可能下一步——结束//////////////////////////
///////////////////////////计算连续三个棋子为一组的可能下一步——开始//////////////////////////
if(TContinuumChessman.CountThree!=0)
{
if(TContinuumChessman.three->THREE[0].x==2*NUM&&
TContinuumChessman.three->THREE[0].y==2*NUM)//跳跃过头节点
TContinuumChessman.three=TContinuumChessman.three->next;
while(TContinuumChessman.three!=NULL)
{
for(int i=0;i<3;i++)
{
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y))
{
AddToComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y))
{
AddToComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y-1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y-1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y+1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y+1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y-1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y-1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y+1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y+1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y+1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y+1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y-1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y-1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y-1,PRI_0);
}
}//for
TContinuumChessman.three=TContinuumChessman.three->next;
}
}
////////////////////////////计算连续三个棋子为一组的可能下一步——结束//////////////////////////
if(TContinuumChessman.CountThree!=0)
{
if(TContinuumChessman.three->THREE[0].x==2*NUM&&
TContinuumChessman.three->THREE[0].y==2*NUM)//跳跃过头节点
TContinuumChessman.three=TContinuumChessman.three->next;
while(TContinuumChessman.three!=NULL)
{
for(int i=0;i<3;i++)
{
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y))
{
AddToComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y))
{
AddToComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y-1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y-1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y+1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y+1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x,TContinuumChessman.three->THREE[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y-1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y-1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y+1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y+1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y+1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y+1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x-1,TContinuumChessman.three->THREE[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y-1)&&
JudgeComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y-1))
{
AddToComNext(TContinuumChessman.three->THREE[i].x+1,TContinuumChessman.three->THREE[i].y-1,PRI_0);
}
}//for
TContinuumChessman.three=TContinuumChessman.three->next;
}
}
////////////////////////////计算连续三个棋子为一组的可能下一步——结束//////////////////////////
////////////////////////////计算连续四个棋子为一组的可能下一步——开始//////////////////////////
if(TContinuumChessman.CountFour!=0)
{
if(TContinuumChessman.four->FOUR[0].x==2*NUM&&
TContinuumChessman.four->FOUR[0].y==2*NUM)//跳过头节点
TContinuumChessman.four=TContinuumChessman.four->next;
while(TContinuumChessman.four!=NULL)
{
for(int i=0;i<4;i++)
{
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y-1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y-1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y+1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y+1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y-1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y-1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y+1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y+1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y+1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y+1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y-1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y-1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y-1,PRI_0);
}
}//for
TContinuumChessman.four= TContinuumChessman.four->next;
}
}
//////////////////////////计算连续四个棋子为一组的可能下一步——结束//////////////////////////
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////
// AttackNextPri0函数定义——结束 //
// 计算出进攻下一步棋的所有可能情况,并加入到ComNext数据成员中 //
////////////////////////////////////////////////////////////////////////////////////////
if(TContinuumChessman.CountFour!=0)
{
if(TContinuumChessman.four->FOUR[0].x==2*NUM&&
TContinuumChessman.four->FOUR[0].y==2*NUM)//跳过头节点
TContinuumChessman.four=TContinuumChessman.four->next;
while(TContinuumChessman.four!=NULL)
{
for(int i=0;i<4;i++)
{
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y-1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y-1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y+1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y+1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x,TContinuumChessman.four->FOUR[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y-1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y-1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y-1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y+1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y+1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y+1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y+1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x-1,TContinuumChessman.four->FOUR[i].y+1,PRI_0);
}
if(JudgeCoordinate(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y-1)&&
JudgeComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y-1))
{
AddToComNext(TContinuumChessman.four->FOUR[i].x+1,TContinuumChessman.four->FOUR[i].y-1,PRI_0);
}
}//for
TContinuumChessman.four= TContinuumChessman.four->next;
}
}
//////////////////////////计算连续四个棋子为一组的可能下一步——结束//////////////////////////
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////
// AttackNextPri0函数定义——结束 //
// 计算出进攻下一步棋的所有可能情况,并加入到ComNext数据成员中 //
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// AttackNextPri1函数定义——开始 //
// 在ComNext数据成员的第0优先级中提取更高的优先级坐标,并加入到 //
// ComNext数据成员中的更高优先级 //
///////////////////////////////////////////////////////////////////////////////////////
bool Computer::AttackNextPri1()
{
int left=0,right=0,top=0,bottom=0,leftT=0,leftB=0,rightT=0,rightB=0,count=0,maxC=0,pri=0;
NextPri temp=ComNext;
//temp.PRI[PRI_0]=temp.PRI[PRI_0]->next;
if(temp.PRI[PRI_0]->point.x==3*NUM&&temp.PRI[PRI_0]->point.y==3*NUM)
temp.PRI[PRI_0]=temp.PRI[PRI_0]->next;
while(temp.PRI[PRI_0]!=NULL)//头节点可能会有问题!!!!!
{
ContinuumNum(temp.PRI[PRI_0]->point.x,temp.PRI[PRI_0]->point.y,
left,right,top,bottom,leftT,leftB,rightT,rightB);
maxC=Max(left*9+right*9,top*9+bottom*9,leftT*9+rightB*9,leftB*9+rightT*9,count); //返回各排中的最大值,计算有个并列为最大值 (当全部都相等是count为5)
pri=maxC+count; //计算该点的优先级
if(pri>0)//要优先级有所提高的才运行一下函数
AddToComNext(temp.PRI[PRI_0]->point.x,temp.PRI[PRI_0]->point.y,pri); //将该点加入到指定的ComNext的优先级队列中
temp.PRI[PRI_0]=temp.PRI[PRI_0]->next;
count=0;maxC=0;pri=0;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////
// AttackNextPri1函数定义——结束 //
// 在ComNext数据成员的第0优先级中提取更高的优先级坐标,并加入到 //
// ComNext数据成员中的更高优先级 //
///////////////////////////////////////////////////////////////////////////////////////
// AttackNextPri1函数定义——开始 //
// 在ComNext数据成员的第0优先级中提取更高的优先级坐标,并加入到 //
// ComNext数据成员中的更高优先级 //
///////////////////////////////////////////////////////////////////////////////////////
bool Computer::AttackNextPri1()
{
int left=0,right=0,top=0,bottom=0,leftT=0,leftB=0,rightT=0,rightB=0,count=0,maxC=0,pri=0;
NextPri temp=ComNext;
//temp.PRI[PRI_0]=temp.PRI[PRI_0]->next;
if(temp.PRI[PRI_0]->point.x==3*NUM&&temp.PRI[PRI_0]->point.y==3*NUM)
temp.PRI[PRI_0]=temp.PRI[PRI_0]->next;
while(temp.PRI[PRI_0]!=NULL)//头节点可能会有问题!!!!!
{
ContinuumNum(temp.PRI[PRI_0]->point.x,temp.PRI[PRI_0]->point.y,
left,right,top,bottom,leftT,leftB,rightT,rightB);
maxC=Max(left*9+right*9,top*9+bottom*9,leftT*9+rightB*9,leftB*9+rightT*9,count); //返回各排中的最大值,计算有个并列为最大值 (当全部都相等是count为5)
pri=maxC+count; //计算该点的优先级
if(pri>0)//要优先级有所提高的才运行一下函数
AddToComNext(temp.PRI[PRI_0]->point.x,temp.PRI[PRI_0]->point.y,pri); //将该点加入到指定的ComNext的优先级队列中
temp.PRI[PRI_0]=temp.PRI[PRI_0]->next;
count=0;maxC=0;pri=0;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////
// AttackNextPri1函数定义——结束 //
// 在ComNext数据成员的第0优先级中提取更高的优先级坐标,并加入到 //
// ComNext数据成员中的更高优先级 //
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
// AddNewChessman函数定义——开始 //
// 确定并添加棋子到ComExistChessman和continuumChessman //
//////////////////////////////////////////////////////////////////////////////////////
bool Computer::AddNewChessman()
{
if(Result==1)return true;
NextPri temp=ComNext;
for(int i=MAXPRI-1;i>=0;i--)
{
if(temp.PRI[i]->next!=NULL)
{
ComExistChessman[ComCount]=temp.PRI[i]->next->point; //将新的点加入到ComExistChessman成员
AddToContinuumChessman(temp.PRI[i]->next->point.x,temp.PRI[i]->next->point.y);//将新的点加入到ContinuumChessman成员
ComCount++;
std::cout<<"x="<<temp.PRI[i]->next->point.x<<" y="<<temp.PRI[i]->next->point.y<<endl;
LPoint TLPoint=temp.PRI[i]->next;
temp.PRI[i]->next=temp.PRI[i]->next->next;//在ComNext中删除刚刚加入的这个点
free(TLPoint);
DeleComNext();//清空ComNext的函数
return true;//该点加入后结束此函数
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
// AddNewChessman函数定义——结束 //
// 确定并添加棋子到ComExistChessman和continuumChessman //
//////////////////////////////////////////////////////////////////////////////////////
// AddNewChessman函数定义——开始 //
// 确定并添加棋子到ComExistChessman和continuumChessman //
//////////////////////////////////////////////////////////////////////////////////////
bool Computer::AddNewChessman()
{
if(Result==1)return true;
NextPri temp=ComNext;
for(int i=MAXPRI-1;i>=0;i--)
{
if(temp.PRI[i]->next!=NULL)
{
ComExistChessman[ComCount]=temp.PRI[i]->next->point; //将新的点加入到ComExistChessman成员
AddToContinuumChessman(temp.PRI[i]->next->point.x,temp.PRI[i]->next->point.y);//将新的点加入到ContinuumChessman成员
ComCount++;
std::cout<<"x="<<temp.PRI[i]->next->point.x<<" y="<<temp.PRI[i]->next->point.y<<endl;
LPoint TLPoint=temp.PRI[i]->next;
temp.PRI[i]->next=temp.PRI[i]->next->next;//在ComNext中删除刚刚加入的这个点
free(TLPoint);
DeleComNext();//清空ComNext的函数
return true;//该点加入后结束此函数
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
// AddNewChessman函数定义——结束 //
// 确定并添加棋子到ComExistChessman和continuumChessman //
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// DeleComNext构造函数定义——开始 //
// 清空ComNext数据成员中的所有内容 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleComNext()
{
NextPri TComN=ComNext;
for(int i=0;i<MAXPRI;i++)
{
while(TComN.PRI[i]->next!=NULL)
{
LPoint temp=TComN.PRI[i]->next;
TComN.PRI[i]->next=TComN.PRI[i]->next->next;
free(temp);
}
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleComNext构造函数定义——结束 //
// 清空ComNext数据成员中的所有内容 //
////////////////////////////////////////////////////////////////////////////
// DeleComNext构造函数定义——开始 //
// 清空ComNext数据成员中的所有内容 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleComNext()
{
NextPri TComN=ComNext;
for(int i=0;i<MAXPRI;i++)
{
while(TComN.PRI[i]->next!=NULL)
{
LPoint temp=TComN.PRI[i]->next;
TComN.PRI[i]->next=TComN.PRI[i]->next->next;
free(temp);
}
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleComNext构造函数定义——结束 //
// 清空ComNext数据成员中的所有内容 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// DeleConCheTwo函数定义开始 //
// 删除continuumChessman中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheTwo(TwoChessman two)
{
ContinuumChessman temp=continuumChessmanCom;
if(temp.CountTwo==0)
{
std::cout<<"There is no continuumTwo data in continuumChessmanCom/n";
return true;
}
while(temp.two!=NULL)
{
if(temp.two->next->TWO[0].x==two->TWO[0].x&&temp.two->next->TWO[0].y==two->TWO[0].y
&&temp.two->next->TWO[1].x==two->TWO[1].x&&temp.two->next->TWO[1].y==two->TWO[1].y)
{
TwoChessman TTwo=temp.two->next;
temp.two->next=temp.two->next->next;
free(TTwo);//释放temp.two->next所指的内存空间
continuumChessmanCom.CountTwo--;
return true;
}
temp.two=temp.two->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheTwo函数定义结束 //
// 删除continuumChessman中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
// DeleConCheTwo函数定义开始 //
// 删除continuumChessman中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheTwo(TwoChessman two)
{
ContinuumChessman temp=continuumChessmanCom;
if(temp.CountTwo==0)
{
std::cout<<"There is no continuumTwo data in continuumChessmanCom/n";
return true;
}
while(temp.two!=NULL)
{
if(temp.two->next->TWO[0].x==two->TWO[0].x&&temp.two->next->TWO[0].y==two->TWO[0].y
&&temp.two->next->TWO[1].x==two->TWO[1].x&&temp.two->next->TWO[1].y==two->TWO[1].y)
{
TwoChessman TTwo=temp.two->next;
temp.two->next=temp.two->next->next;
free(TTwo);//释放temp.two->next所指的内存空间
continuumChessmanCom.CountTwo--;
return true;
}
temp.two=temp.two->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheTwo函数定义结束 //
// 删除continuumChessman中连续两个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// DeleConCheThree函数定义开始 //
// 删除continuumChessman中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheThree(ThreeChessman three)
{
ContinuumChessman temp=continuumChessmanCom;
if(temp.CountThree==0)
{
std::cout<<"There is no continuumThree data in continuumChessmanCom/n";
return true;
}
while(temp.three!=NULL)
{
if(temp.three->next->THREE[0].x==three->THREE[0].x&&temp.three->next->THREE[0].y==three->THREE[0].y&&
temp.three->next->THREE[1].x==three->THREE[1].x&&temp.three->next->THREE[1].y==three->THREE[1].y&&
temp.three->next->THREE[2].x==three->THREE[2].x&&temp.three->next->THREE[2].y==three->THREE[2].y)
{
ThreeChessman TThree=temp.three->next;
temp.three->next=temp.three->next->next;
free(TThree);//释放temp.three->next所指的内存空间
continuumChessmanCom.CountThree--;
return true;
}
temp.three=temp.three->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheThree函数定义结束 //
// 删除continuumChessman中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
// DeleConCheThree函数定义开始 //
// 删除continuumChessman中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
bool Computer::DeleConCheThree(ThreeChessman three)
{
ContinuumChessman temp=continuumChessmanCom;
if(temp.CountThree==0)
{
std::cout<<"There is no continuumThree data in continuumChessmanCom/n";
return true;
}
while(temp.three!=NULL)
{
if(temp.three->next->THREE[0].x==three->THREE[0].x&&temp.three->next->THREE[0].y==three->THREE[0].y&&
temp.three->next->THREE[1].x==three->THREE[1].x&&temp.three->next->THREE[1].y==three->THREE[1].y&&
temp.three->next->THREE[2].x==three->THREE[2].x&&temp.three->next->THREE[2].y==three->THREE[2].y)
{
ThreeChessman TThree=temp.three->next;
temp.three->next=temp.three->next->next;
free(TThree);//释放temp.three->next所指的内存空间
continuumChessmanCom.CountThree--;
return true;
}
temp.three=temp.three->next;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// DeleConCheThree函数定义结束 //
// 删除continuumChessman中连续三个棋子的一个节点 //
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// AddToContinuumChessman函数定义开始 //
// 添加一个点到ContinuumChessman数据成员中 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddToContinuumChessman(int x,int y)
{
ContinuumChessman temp;
// AddToContinuumChessman函数定义开始 //
// 添加一个点到ContinuumChessman数据成员中 //
////////////////////////////////////////////////////////////////////////////
bool Computer::AddToContinuumChessman(int x,int y)
{
ContinuumChessman temp;
temp=continuumChessmanCom;
// if(temp.CountTwo==0&&temp.CountThree==0&&temp.CountFour==0)//如果没有连续的点,判断可不可以与其他的分散点组成连续的点
// {
/////////////////没有连续的点-开始////////////////////////////////////////////
for(int i=0;i<ComCount;i++)
{
if(x-1==ComExistChessman[i].x&&y==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=ComExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
// if(temp.CountTwo==0&&temp.CountThree==0&&temp.CountFour==0)//如果没有连续的点,判断可不可以与其他的分散点组成连续的点
// {
/////////////////没有连续的点-开始////////////////////////////////////////////
for(int i=0;i<ComCount;i++)
{
if(x-1==ComExistChessman[i].x&&y==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=ComExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
for(int i=0;i<ComCount;i++)
{
if(x+1==ComExistChessman[i].x&&y==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
{
if(x+1==ComExistChessman[i].x&&y==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
for(int i=0;i<ComCount;i++)
{
if(x==ComExistChessman[i].x&&y-1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=ComExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
{
if(x==ComExistChessman[i].x&&y-1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=ComExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
for(int i=0;i<ComCount;i++)
{
if(x==ComExistChessman[i].x&&y+1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
{
if(x==ComExistChessman[i].x&&y+1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
for(int i=0;i<ComCount;i++)
{
if(x-1==ComExistChessman[i].x&&y-1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=ComExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
{
if(x-1==ComExistChessman[i].x&&y-1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0]=ComExistChessman[i];
tempTwo->TWO[1].x=x;
tempTwo->TWO[1].y=y;
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
for(int i=0;i<ComCount;i++)
{
if(x+1==ComExistChessman[i].x&&y+1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
{
if(x+1==ComExistChessman[i].x&&y+1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
for(int i=0;i<ComCount;i++)
{
if(x+1==ComExistChessman[i].x&&y-1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
{
if(x+1==ComExistChessman[i].x&&y-1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
for(int i=0;i<ComCount;i++)
{
if(x-1==ComExistChessman[i].x&&y+1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
/////////////////没有连续的点-结束////////////////////////////////////////////
//}
// else//有连续的点
// {
///////////////两个连续的棋子-开始////////////////////////
temp=continuumChessmanCom;
TwoChessman DeleTwo[NUM*NUM];
int DeleCountTwo=0;
if(temp.two->TWO[0].x==2*NUM&&temp.two->TWO[0].y==2*NUM)//跳过头节点
temp.two=temp.two->next;
while(temp.two!=NULL)
{
if((temp.two->TWO[1].x-temp.two->TWO[0].x)==(temp.two->TWO[0].x-x)&&
(temp.two->TWO[1].y-temp.two->TWO[0].y)==(temp.two->TWO[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.three->next!=NULL)temp.three=temp.three->next;
ThreeChessman tempThree_0=(ThreeChessman)malloc(sizeof(struct three));
tempThree_0->THREE[0].x=x;
tempThree_0->THREE[0].y=y;
tempThree_0->THREE[1]=temp.two->TWO[0];
tempThree_0->THREE[2]=temp.two->TWO[1];
tempThree_0->next=NULL;
temp.three->next=tempThree_0;
continuumChessmanCom.CountThree++;
//////////////加入到删除列表////////////////
DeleTwo[DeleCountTwo]=temp.two;
DeleCountTwo++;
//////////////加入到删除列表////////////////
{
if(x-1==ComExistChessman[i].x&&y+1==ComExistChessman[i].y)
{
while(temp.two->next!=NULL) temp.two=temp.two->next;
TwoChessman tempTwo=(TwoChessman)malloc(sizeof(struct two));
tempTwo->TWO[0].x=x;
tempTwo->TWO[0].y=y;
tempTwo->TWO[1]=ComExistChessman[i];
tempTwo->next=NULL;
temp.two->next=tempTwo;
continuumChessmanCom.CountTwo++;
}
}
/////////////////没有连续的点-结束////////////////////////////////////////////
//}
// else//有连续的点
// {
///////////////两个连续的棋子-开始////////////////////////
temp=continuumChessmanCom;
TwoChessman DeleTwo[NUM*NUM];
int DeleCountTwo=0;
if(temp.two->TWO[0].x==2*NUM&&temp.two->TWO[0].y==2*NUM)//跳过头节点
temp.two=temp.two->next;
while(temp.two!=NULL)
{
if((temp.two->TWO[1].x-temp.two->TWO[0].x)==(temp.two->TWO[0].x-x)&&
(temp.two->TWO[1].y-temp.two->TWO[0].y)==(temp.two->TWO[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.three->next!=NULL)temp.three=temp.three->next;
ThreeChessman tempThree_0=(ThreeChessman)malloc(sizeof(struct three));
tempThree_0->THREE[0].x=x;
tempThree_0->THREE[0].y=y;
tempThree_0->THREE[1]=temp.two->TWO[0];
tempThree_0->THREE[2]=temp.two->TWO[1];
tempThree_0->next=NULL;
temp.three->next=tempThree_0;
continuumChessmanCom.CountThree++;
//////////////加入到删除列表////////////////
DeleTwo[DeleCountTwo]=temp.two;
DeleCountTwo++;
//////////////加入到删除列表////////////////
// DeleConCheTwo(temp.two); //删除temp.two这个链表节点
// goto LABLE1;
// continuumChessmanCom.CountTwo--;
}
if((temp.two->TWO[0].x-temp.two->TWO[1].x)==(temp.two->TWO[1].x-x)&&
(temp.two->TWO[0].y-temp.two->TWO[1].y)==(temp.two->TWO[1].y-y))//新的点加在temp.two->TWO[1]的后面
{
while(temp.three->next!=NULL)temp.three=temp.three->next;
ThreeChessman tempThree_1=(ThreeChessman)malloc(sizeof(struct three));
tempThree_1->THREE[0]=temp.two->TWO[0];
tempThree_1->THREE[1]=temp.two->TWO[1];
tempThree_1->THREE[2].x=x;
tempThree_1->THREE[2].y=y;
tempThree_1->next=NULL;
temp.three->next=tempThree_1;
continuumChessmanCom.CountThree++;
//////////////加入到删除列表////////////////
DeleTwo[DeleCountTwo]=temp.two;
DeleCountTwo++;
//////////////加入到删除列表////////////////
// DeleConCheTwo(temp.two); //删除temp.two这个链表节点
// continuumChessmanCom.CountTwo--;
}
temp.two=temp.two->next;
}//while
while(DeleCountTwo!=0)
{
DeleConCheTwo(DeleTwo[DeleCountTwo-1]);
DeleCountTwo--;
}
///////////////两个连续的棋子-结束////////////////////////
//LABLE1:
///////////////三个连续的棋子-开始////////////////////////
temp=continuumChessmanCom;
ThreeChessman DeleThree[NUM*NUM];
int DeleCountThree=0;
if(temp.three->THREE[0].x==2*NUM&&temp.three->THREE[0].y==2*NUM)
temp.three=temp.three->next;
while(temp.three!=NULL)
{
if((temp.three->THREE[2].x-temp.three->THREE[1].x)==(temp.three->THREE[0].x-x)&&
(temp.three->THREE[2].y-temp.three->THREE[1].y)==(temp.three->THREE[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0].x=x;
tempFour_0->FOUR[0].y=y;
tempFour_0->FOUR[1]=temp.three->THREE[0];
tempFour_0->FOUR[2]=temp.three->THREE[1];
tempFour_0->FOUR[3]=temp.three->THREE[2];
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanCom.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
// continuumChessmanCom.CountTwo--;
}
temp.two=temp.two->next;
}//while
while(DeleCountTwo!=0)
{
DeleConCheTwo(DeleTwo[DeleCountTwo-1]);
DeleCountTwo--;
}
///////////////两个连续的棋子-结束////////////////////////
//LABLE1:
///////////////三个连续的棋子-开始////////////////////////
temp=continuumChessmanCom;
ThreeChessman DeleThree[NUM*NUM];
int DeleCountThree=0;
if(temp.three->THREE[0].x==2*NUM&&temp.three->THREE[0].y==2*NUM)
temp.three=temp.three->next;
while(temp.three!=NULL)
{
if((temp.three->THREE[2].x-temp.three->THREE[1].x)==(temp.three->THREE[0].x-x)&&
(temp.three->THREE[2].y-temp.three->THREE[1].y)==(temp.three->THREE[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0].x=x;
tempFour_0->FOUR[0].y=y;
tempFour_0->FOUR[1]=temp.three->THREE[0];
tempFour_0->FOUR[2]=temp.three->THREE[1];
tempFour_0->FOUR[3]=temp.three->THREE[2];
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanCom.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
// DeleConCheThree(temp.three); //删除temp.three这个链表节点
// goto LABLE2;
// continuumChessmanCom.CountThree--;
}
if((temp.three->THREE[0].x-temp.three->THREE[1].x)==(temp.three->THREE[2].x-x)&&
(temp.three->THREE[0].y-temp.three->THREE[1].y)==(temp.three->THREE[2].y-y))//新的点加在temp.two->TWO[2]的后面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0]=temp.three->THREE[0];
tempFour_0->FOUR[1]=temp.three->THREE[1];
tempFour_0->FOUR[2]=temp.three->THREE[2];
tempFour_0->FOUR[3].x=x;
tempFour_0->FOUR[3].y=y;
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanCom.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
// DeleConCheThree(temp.three); //删除temp.three这个链表节点
// continuumChessmanCom.CountThree--;
}
temp.three=temp.three->next;
}//while
while(DeleCountThree!=0)
{
DeleConCheThree(DeleThree[DeleCountThree-1]);
DeleCountThree--;
}
///////////////三个连续的棋子-结束////////////////////////
//LABLE2:
///////////////四个连续的棋子-开始////////////////////////
temp=continuumChessmanCom;
if(temp.four->FOUR[0].x==2*NUM&&temp.four->FOUR[0].y==2*NUM)
temp.four=temp.four->next;
while(temp.four!=NULL)
{
if((temp.four->FOUR[3].x-temp.four->FOUR[2].x)==(temp.four->FOUR[0].x-x)&&
(temp.four->FOUR[3].y-temp.four->FOUR[2].y)==(temp.four->FOUR[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
Result=1;
std::cout<<"The Computer has win!/n";
//结束程序的函数
}
if((temp.four->FOUR[0].x-temp.four->FOUR[1].x)==(temp.four->FOUR[3].x-x)&&
(temp.four->FOUR[0].y-temp.four->FOUR[1].y)==(temp.four->FOUR[3].y-y))//新的点加在temp.two->TWO[2]的后面
{
Result=1;
std::cout<<"The Computer has win!/n";
//结束程序的函数
}
temp.four=temp.four->next;
}
///////////////四个连续的棋子-结束////////////////////////
//}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddToContinuumChessman函数定义结束 //
// 添加一个点到ContinuumChessman数据成员中 //
////////////////////////////////////////////////////////////////////////////
// goto LABLE2;
// continuumChessmanCom.CountThree--;
}
if((temp.three->THREE[0].x-temp.three->THREE[1].x)==(temp.three->THREE[2].x-x)&&
(temp.three->THREE[0].y-temp.three->THREE[1].y)==(temp.three->THREE[2].y-y))//新的点加在temp.two->TWO[2]的后面
{
while(temp.four->next!=NULL)temp.four=temp.four->next;
FourChessman tempFour_0=(FourChessman)malloc(sizeof(struct four));
tempFour_0->FOUR[0]=temp.three->THREE[0];
tempFour_0->FOUR[1]=temp.three->THREE[1];
tempFour_0->FOUR[2]=temp.three->THREE[2];
tempFour_0->FOUR[3].x=x;
tempFour_0->FOUR[3].y=y;
tempFour_0->next=NULL;
temp.four->next=tempFour_0;
continuumChessmanCom.CountFour++;
//////////////加入到删除列表////////////////
DeleThree[DeleCountThree]=temp.three;
DeleCountThree++;
//////////////加入到删除列表////////////////
// DeleConCheThree(temp.three); //删除temp.three这个链表节点
// continuumChessmanCom.CountThree--;
}
temp.three=temp.three->next;
}//while
while(DeleCountThree!=0)
{
DeleConCheThree(DeleThree[DeleCountThree-1]);
DeleCountThree--;
}
///////////////三个连续的棋子-结束////////////////////////
//LABLE2:
///////////////四个连续的棋子-开始////////////////////////
temp=continuumChessmanCom;
if(temp.four->FOUR[0].x==2*NUM&&temp.four->FOUR[0].y==2*NUM)
temp.four=temp.four->next;
while(temp.four!=NULL)
{
if((temp.four->FOUR[3].x-temp.four->FOUR[2].x)==(temp.four->FOUR[0].x-x)&&
(temp.four->FOUR[3].y-temp.four->FOUR[2].y)==(temp.four->FOUR[0].y-y))//新的点加在temp.two->TWO[0]的前面
{
Result=1;
std::cout<<"The Computer has win!/n";
//结束程序的函数
}
if((temp.four->FOUR[0].x-temp.four->FOUR[1].x)==(temp.four->FOUR[3].x-x)&&
(temp.four->FOUR[0].y-temp.four->FOUR[1].y)==(temp.four->FOUR[3].y-y))//新的点加在temp.two->TWO[2]的后面
{
Result=1;
std::cout<<"The Computer has win!/n";
//结束程序的函数
}
temp.four=temp.four->next;
}
///////////////四个连续的棋子-结束////////////////////////
//}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// AddToContinuumChessman函数定义结束 //
// 添加一个点到ContinuumChessman数据成员中 //
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// JudgeCoordinate函数定义开始 //
// 判断一个坐标是否已经被占用 //
///////////////////////////////////////////////////////////////////////////
bool Computer::JudgeCoordinate(int x,int y)
{
int temp=0;
for(int i=0;i<ComCount;i++)
{
if(x==ComExistChessman[i].x&&y==ComExistChessman[i].y)
temp++;
}
for(int j=0;j<OppCount;j++)
{
if(x==OppExistChessman[j].x&&y==OppExistChessman[j].y)
temp++;
}
if(temp==0&&x<NUM&&x>=0&&y<NUM&&y>=0)
return true;
else
return false;
}//如果该点不存在着返回真
////////////////////////////////////////////////////////////////////////////
// JudgeCoordinate函数定义结束 //
// 判断一个坐标是否已经被占用 //
///////////////////////////////////////////////////////////////////////////
// JudgeCoordinate函数定义开始 //
// 判断一个坐标是否已经被占用 //
///////////////////////////////////////////////////////////////////////////
bool Computer::JudgeCoordinate(int x,int y)
{
int temp=0;
for(int i=0;i<ComCount;i++)
{
if(x==ComExistChessman[i].x&&y==ComExistChessman[i].y)
temp++;
}
for(int j=0;j<OppCount;j++)
{
if(x==OppExistChessman[j].x&&y==OppExistChessman[j].y)
temp++;
}
if(temp==0&&x<NUM&&x>=0&&y<NUM&&y>=0)
return true;
else
return false;
}//如果该点不存在着返回真
////////////////////////////////////////////////////////////////////////////
// JudgeCoordinate函数定义结束 //
// 判断一个坐标是否已经被占用 //
///////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// MAX开始 //
// 函数返回4各数的最大值, //
// 并计算出有几个值并列为最大值 //
//////////////////////////////////////////////////////////////
int Computer::Max(int a,int b,int c,int d,int &count)
{
count=-1;
int temp=a;
if(temp<b)temp=b;
if(temp<c)temp=c;
if(temp<d)temp=d;
if(a==temp)count++;
if(b==temp)count++;
if(c==temp)count++;
if(d==temp)count++;
if(a==0&&b==0&&c==0&&d==0)count=0;
return temp;
}
//////////////////////////////////////////////////////////////
// MAX结束 //
// 函数返回4各数的最大值, //
// 并计算出有几个值并列为最大值 //
//////////////////////////////////////////////////////////////
// MAX开始 //
// 函数返回4各数的最大值, //
// 并计算出有几个值并列为最大值 //
//////////////////////////////////////////////////////////////
int Computer::Max(int a,int b,int c,int d,int &count)
{
count=-1;
int temp=a;
if(temp<b)temp=b;
if(temp<c)temp=c;
if(temp<d)temp=d;
if(a==temp)count++;
if(b==temp)count++;
if(c==temp)count++;
if(d==temp)count++;
if(a==0&&b==0&&c==0&&d==0)count=0;
return temp;
}
//////////////////////////////////////////////////////////////
// MAX结束 //
// 函数返回4各数的最大值, //
// 并计算出有几个值并列为最大值 //
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// bool ContinuumNum开始 //
// 计算一个点在各个方向上各有几个点相连 //
//////////////////////////////////////////////////////////////
bool Computer::ContinuumNum(int x,int y,int &left,int &right,
int &top,int &bottom,int &leftT,int &leftB,int &rightT,int &rightB)
{
int tempX,tempY;
left=0;
right=0;
top=0;
bottom=0;
leftT=0;
leftB=0;
rightT=0;
rightB=0;
// bool ContinuumNum开始 //
// 计算一个点在各个方向上各有几个点相连 //
//////////////////////////////////////////////////////////////
bool Computer::ContinuumNum(int x,int y,int &left,int &right,
int &top,int &bottom,int &leftT,int &leftB,int &rightT,int &rightB)
{
int tempX,tempY;
left=0;
right=0;
top=0;
bottom=0;
leftT=0;
leftB=0;
rightT=0;
rightB=0;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(--tempX,tempY))left++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(++tempX,tempY))right++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(tempX,--tempY))top++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(tempX,++tempY))bottom++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(--tempX,--tempY))leftT++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(++tempX,++tempY))rightB++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(--tempX,++tempY))leftB++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(++tempX,--tempY))rightT++;
return true;
}
////////////////////////////////////////////////////////////////
// bool ContinuumNum结束 //
// 计算一个点在各个方向上各有几个点相连 //
///////////////////////////////////////////////////////////////
tempY=y;
while(!JudgeComCoordinate(--tempX,tempY))left++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(++tempX,tempY))right++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(tempX,--tempY))top++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(tempX,++tempY))bottom++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(--tempX,--tempY))leftT++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(++tempX,++tempY))rightB++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(--tempX,++tempY))leftB++;
tempX=x;
tempY=y;
while(!JudgeComCoordinate(++tempX,--tempY))rightT++;
return true;
}
////////////////////////////////////////////////////////////////
// bool ContinuumNum结束 //
// 计算一个点在各个方向上各有几个点相连 //
///////////////////////////////////////////////////////////////
/////////////////////////////////////////////
// JudgeComNext函数定义开始 //
// 判断一个坐标是否已 //
// 经被加入到ComNext里面 //
///////////////////////////////////////////
bool Computer::JudgeComNext(int x,int y)
{
NextPri temp=ComNext;
for(int i=0;i<MAXPRI-1;i++)
{
while(temp.PRI[i]!=NULL)
{
if(temp.PRI[i]->point.x==x&&temp.PRI[i]->point.y==y)
return false;
temp.PRI[i]=temp.PRI[i]->next;
}
}
return true;
}
////////////////////////////////////////////
// JudgeComNext函数定义结束 //
// 判断一个坐标是否已 //
// 经被加入到ComNext里面 //
///////////////////////////////////////////
// JudgeComNext函数定义开始 //
// 判断一个坐标是否已 //
// 经被加入到ComNext里面 //
///////////////////////////////////////////
bool Computer::JudgeComNext(int x,int y)
{
NextPri temp=ComNext;
for(int i=0;i<MAXPRI-1;i++)
{
while(temp.PRI[i]!=NULL)
{
if(temp.PRI[i]->point.x==x&&temp.PRI[i]->point.y==y)
return false;
temp.PRI[i]=temp.PRI[i]->next;
}
}
return true;
}
////////////////////////////////////////////
// JudgeComNext函数定义结束 //
// 判断一个坐标是否已 //
// 经被加入到ComNext里面 //
///////////////////////////////////////////
///////////////////////////////////////////
// AddToComNext函数定义开始 //
// 添加新的棋子到ComNext成员 //
//////////////////////////////////////////
bool Computer::AddToComNext(int x,int y,int pri)
{
NextPri temp=ComNext;
while(temp.PRI[pri]->next!=NULL)
temp.PRI[pri]=temp.PRI[pri]->next;
LPoint AddPoint=(LPoint)malloc(sizeof(struct po));
AddPoint->point.x=x;
AddPoint->point.y=y;
AddPoint->next=NULL;
temp.PRI[pri]->next=AddPoint;
return true;
}
/////////////////////////////////////////////
// AddToComNext函数定义结束 //
// 添加新的棋子到ComNext成员 //
////////////////////////////////////////////
// AddToComNext函数定义开始 //
// 添加新的棋子到ComNext成员 //
//////////////////////////////////////////
bool Computer::AddToComNext(int x,int y,int pri)
{
NextPri temp=ComNext;
while(temp.PRI[pri]->next!=NULL)
temp.PRI[pri]=temp.PRI[pri]->next;
LPoint AddPoint=(LPoint)malloc(sizeof(struct po));
AddPoint->point.x=x;
AddPoint->point.y=y;
AddPoint->next=NULL;
temp.PRI[pri]->next=AddPoint;
return true;
}
/////////////////////////////////////////////
// AddToComNext函数定义结束 //
// 添加新的棋子到ComNext成员 //
////////////////////////////////////////////
void main()
{
Computer com;
/*
for(int i=0;i<4;i++)
{
com.AddNewChessmanOpp();
// com.AttackNextPri0();
// com.AttackNextPri1();
// com.AddNewChessman();
}
com.AddDefenNewCh();
*/
while(1)
{
com.AddNewChessmanOpp();
com.AddDefenNewCh();
com.AttackNextPri0();
com.AttackNextPri1();
com.AddNewChessman();
if(com.GetResult()==1)break;
}
}
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋核心算法研究
- 五子棋的核心算法
- 五子棋核心算法研究
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋核心算法
- 五子棋的核心算法
- 五子棋核心算法
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋的核心算法
- 五子棋的核心算法【转载】
- Java多线程运行时,尽可能调用单例对象、工具类和静态方法,这样可以减少内存的占用量
- Consuming Unmanaged C++ Class Libraries from .NET Clients
- MF研究:TinyCLR运行时原理
- [网摘]---有关int,Int32的疑惑解答
- PB编译一个OS时,出现如下错误
- 五子棋核心算法
- redhat和服务器相关软件站点一览
- 关于覆盖与隐藏
- 谷歌浏览器的源码分析(29)
- vs2005 C#与mySql连接解决中文乱码问题
- 大整数除法
- 自我约束:提高工作/学习效率的有效措施
- Panel内容清空
- Ubuntu下设置常见网络服务指南