📄 game.c
字号:
{
count++;
i--;
j++;
}
}//while(i>=0&&j<11)
}//if(Infor[i][j]==0)
return 0;
}
int LeftUpCheck(const int x,const int y,int color)
{
int i=x,j=y,count=0,tempy=0;
int *gradeTar,*gradeNot,target,nottarget;
if(color==WHITE)
{
gradeTar=&GradeWhite;
gradeNot=&GradeBlack;
target=1;
nottarget=2;
}
else
{
gradeTar=&GradeBlack;
gradeNot=&GradeWhite;
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i--;
j--;
while((i>=0)&&(j>=0))
{
if(Infor[i][j]==0)//为底色
return 0;
if((Infor[i][j]==target)&&(count==0))//为白色且不能消去黑子
return 0;
if((Infor[i][j]==target)&&(count>0))//为白色且能消去黑子
{
tempy=j;
i=x-1;
for(j=y-1;j>tempy;j--)
{
DrowCirle(i,j,color);
Infor[i][j]=target;
i--;
(*gradeTar)++;
(*gradeNot)--;
}
return 1;
}
if(Infor[i][j]==nottarget)//为黑色
{
count++;
i--;
j--;
}
}//while((i>=0)&&(j>=0))
}//if(Infor[i][j]==0)
return 0;
}
int RightDownCheck(const int x,const int y,int color)
{
int i=x,j=y,count=0,tempy=0;
int *gradeTar,*gradeNot,target,nottarget;
if(color==WHITE)
{
gradeTar=&GradeWhite;
gradeNot=&GradeBlack;
target=1;
nottarget=2;
}
else
{
gradeTar=&GradeBlack;
gradeNot=&GradeWhite;
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i++;
j++;
while((i<M)&&(j<M))
{
if(Infor[i][j]==0)//为底色
return 0;
if((Infor[i][j]==target)&&(count==0))//为白色且不能消去黑子
return 0;
if((Infor[i][j]==target)&&(count>0))//为白色且能消去黑子
{
tempy=j;
i=x+1;
for(j=y+1;j<tempy;j++)
{
DrowCirle(i,j,color);
Infor[i][j]=target;
i++;
(*gradeTar)++;
(*gradeNot)--;
}
//(gradeNot)-=count;
return 1;
}
if(Infor[i][j]==nottarget)//为黑色
{
count++;
i++;
j++;
}
}//while((i<11)&&(j<11))
}//if(Infor[i][j]==0)
return 0;
}
int LeftDownCheck(const int x,const int y,int color)
{
int i=x,j=y,count=0,tempy=0;
int *gradeTar,*gradeNot,target,nottarget;
if(color==WHITE)
{
gradeTar=&GradeWhite;
gradeNot=&GradeBlack;
target=1;
nottarget=2;
}
else
{
gradeTar=&GradeBlack;
gradeNot=&GradeWhite;
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i++;
j--;
while((i<M)&&(j>=0))
{
if(Infor[i][j]==0)//为底色
return 0;
if((Infor[i][j]==target)&&(count==0))//为白色且不能消去黑子
return 0;
if((Infor[i][j]==target)&&(count>0))//为白色且能消去黑子
{
tempy=j;
i=x+1;
for(j=y-1;j>tempy;j--)
{
DrowCirle(i,j,color);
Infor[i][j]=target;
i++;
(*gradeTar)++;
(*gradeNot)--;
}
//(*gradeNot)-=count;
return 1;
}
if(Infor[i][j]==nottarget)//为黑色
{
count++;
i++;
j--;
}
}//while((i<11)&&(j>=0))
}//if(Infor[i][j]==0)
return 0;
}
//人直接放置或者机器检查完后放置
int Put(const int x,const int y,int color)
{
int flag1=0,flag2=0,flag3=0,flag4=0;
int flag5=0,flag6=0,flag7=0,flag8=0;
flag1=UpCheck(x,y,color);
flag2=DownCheck(x,y,color);
flag3=RightCheck(x,y,color);
flag4=LeftCheck(x,y,color);
flag5=RightUpCheck(x,y,color);
flag6=LeftUpCheck(x,y,color);
flag7=RightDownCheck(x,y,color);
flag8=LeftDownCheck(x,y,color);
if(flag1==1||flag2==1||flag3==1||flag4==1||flag5==1||flag6==1||flag7==1||flag8==1)
{
DrowCirle(x,y,color);
if(color==WHITE)
{
Infor[x][y]=1;
GradeWhite++;
}
else
{
Infor[x][y]=2;
GradeBlack++;
}
return 1;
}
else
{
return 0;
}
}
void ManStep(const int x,const int y)
{
DrowCirle(x,y,WHITE);
GradeWhite++;
Infor[x][y]=1;
}
int AllowUpCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i--;
while(i>=0)
{
if(Infor[i][j]==0)
return 0;
if((Infor[i][j]==target)&&(count==0))
return 0;
if((Infor[i][j]==target)&&(count!=0))
return count;
if(Infor[i][j]==nottarget)
{
i--;
count++;
}
}
}
return 0;
}
int AllowDownCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i++;
while(i<M)
{
if(Infor[i][j]==0)
return 0;
if(Infor[i][j]==target&&count==0)
return 0;
if(Infor[i][j]==target&&count!=0)
return count;
if(Infor[i][j]==nottarget)
{
i++;
count++;
}
}
}
return 0;
}
int AllowRightCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{j++;
while(j<M)
{
if(Infor[i][j]==0)
return 0;
if(Infor[i][j]==target&&count==0)
return 0;
if(Infor[i][j]==target&&count!=0)
return count;
if(Infor[i][j]==nottarget)
{
j++;
count++;
}
}
}
return 0;
}
int AllowLeftCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{j--;
while(j>=0)
{
if(Infor[i][j]==0)
return 0;
if(Infor[i][j]==target&&count==0)
return 0;
if(Infor[i][j]==target&&count!=0)
return count;
if(Infor[i][j]==nottarget)
{
j--;
count++;
}
}
}
return 0;
}
int AllowRigtUpCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i--;
j++;
while((i>=0)&&(j<M))
{
if(Infor[i][j]==0)
return 0;
if(Infor[i][j]==target&&count==0)
return 0;
if(Infor[i][j]==target&&count!=0)
return count;
if(Infor[i][j]==nottarget)
{
i--;
j++;
count++;
}
}
}
return 0;
}
int AllowLeftUpCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i--;
j--;
while((i>=0)&&(j>=0))
{
if(Infor[i][j]==0)
return 0;
if(Infor[i][j]==target&&count==0)
return 0;
if(Infor[i][j]==target&&count!=0)
return count;
if(Infor[i][j]==nottarget)
{
i--;
j--;
count++;
}
}
}
return 0;
}
int AllowRihtDownCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i++;
j++;
while((i<M)&&(j<M))
{
if(Infor[i][j]==0)
return 0;
if(Infor[i][j]==target&&count==0)
return 0;
if(Infor[i][j]==target&&count!=0)
return count;
if(Infor[i][j]==nottarget)
{
i++;
j++;
count++;
}
}
}
return 0;
}
int AllowLeftDownCheck(const int x,const int y,int color)
{
int count=0,i=x,j=y;
int target,nottarget;
if(color==WHITE)
{
target=1;
nottarget=2;
}
else
{
target=2;
nottarget=1;
}
if(Infor[i][j]==0)
{i++;
j--;
while((i<M)&&(j>=0))
{
if(Infor[i][j]==0)
return 0;
if(Infor[i][j]==target&&count==0)
return 0;
if(Infor[i][j]==target&&count!=0)
return count;
if(Infor[i][j]==nottarget)
{
i++;
j--;
count++;
}
}
}
return 0;
}
int AllowPut(int *x,int *y,int color)
{ int count=0,i=0,j=0,max=0,tempx=0,tempy=0,flag=0;
for(i=0;i<8;i++)
{
for(j=0;j<M;j++)
{
if(Infor[i][j]==0)
{
Address[i][j]=0;
}
else
{
Address[i][j]=200;
}
}
}
for(i=0;i<M;i++)
{
for(j=0;j<M;j++)
{
Address[i][j]=Allow(i,j,color);
}
}
for(i=0;i<M;i++)
{
for(j=0;j<M;j++)
{
if((Address[i][j]!=200)&&(Address[i][j]!=0))
{
if(Address[i][j]>max)
{
flag=1;
max=Address[i][j];
tempx=i;
tempy=j;
}
}
}
}//get the best address(tempx,tempy)
*x=tempx;
*y=tempy;
return flag;
}
int Allow(int x,int y,int color)
{
int count=0;
if(Infor[x][y]==0)
{
count+=AllowUpCheck(x,y,color);
count+=AllowDownCheck(x,y,color);
count+=AllowRightCheck(x,y,color);
count+=AllowLeftCheck(x,y,color);
count+=AllowRigtUpCheck(x,y,color);
count+=AllowLeftUpCheck(x,y,color);
count+=AllowRihtDownCheck(x,y,color);
count+=AllowLeftDownCheck(x,y,color);
}
return count;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -