五子棋[原创]
// 五子棋
// 日期:2000.7.21
// 作者:shiter
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#include "graphics.h"
#include "bioskey.h"
#include "mousea.h"
int oldi,oldj,f=1;
again()
{
int x,y;
setlinestyle(0,0,3);
setfillstyle(1,7);
bar(100,150,400,300);
setcolor(15);
line(100,150,400,150);
line(100,150,100,300);
setcolor(4);
line(100,300,400,300);
line(400,150,400,300);
settextstyle(1,0,2);
outtextxy(170,170,"Play again?");
outtextxy(170,230,"OK");
outtextxy(300,230,"NO");
initmouse();
showmouse();
while(1)
{
getmousexy(&x,&y);
if(x>120&&x<240&&y>210&&y<270)
{
setcolor(15);
line(130,210,230,210);
line(130,210,130,270);
setcolor(0);
line(130,270,230,270);
line(230,210,230,270);
if(getpressinfo(0)==1)
{
hidemouse();
main();
}
continue;
}
if(x>260&&x<380&&y>210&&y<270)
{
setcolor(15);
line(270,210,370,210);
line(270,210,270,270);
setcolor(0);
line(270,270,370,270);
line(370,210,370,270);
if(getpressinfo(0)==1)
{
hidemouse();
closegraph();
}
continue;
}
if(!(x>120&&x<240&&y>210&&y<270&&x>260&&x<380&&y>210&&y<270))
{
setcolor(7);
line(130,210,230,210);
line(130,210,130,270);
line(130,270,230,270);
line(230,210,230,270);
line(270,210,370,210);
line(270,210,270,270);
line(270,270,370,270);
line(370,210,370,270);
if(getpressinfo(0)==1);
continue;
}
}
}
win1(int i)
{
setcolor(3);
settextstyle(1,0,4);
outtextxy(100,10,"Press any key!");
settextstyle(1,0,6);
randomize();
if(i==1)
{
while(!bioskey(1))
{
setcolor(random(15)+1);
outtextxy(100,400,"PLAY_1 IS WINNER");
delay(50);
}
again();
}
if(i==2)
{
while(!bioskey(1))
{
setcolor(random(15)+1);
outtextxy(100,400,"PLAY_2 IS WINNER");
delay(50);
}
again();
}
}
panduan(int a[16][16],int x,int y,int iflag)
{
if(a[x][y]==iflag)
if( (a[x+1][y]==iflag&&a[x+2][y]==iflag&&a[x+3][y]==iflag&&a[x+4][y]==iflag)
||(a[x-1][y]==iflag&&a[x+1][y]==iflag&&a[x+2][y]==iflag&&a[x+3][y]==iflag)
||(a[x-2][y]==iflag&&a[x-1][y]==iflag&&a[x+1][y]==iflag&&a[x+2][y]==iflag)
||(a[x-3][y]==iflag&&a[x-2][y]==iflag&&a[x-1][y]==iflag&&a[x+1][y]==iflag)
||(a[x-4][y]==iflag&&a[x-3][y]==iflag&&a[x-2][y]==iflag&&a[x-1][y]==iflag))
win1(iflag);
if( (a[x+1][y+1]==iflag&&a[x+2][y+2]==iflag&&a[x+3][y+3]==iflag&&a[x+4][y+4]==iflag)
||(a[x-1][y-1]==iflag&&a[x+1][y+1]==iflag&&a[x+2][y+2]==iflag&&a[x+3][y+3]==iflag)
||(a[x-2][y-2]==iflag&&a[x-1][y-1]==iflag&&a[x+1][y+1]==iflag&&a[x+2][y+2]==iflag)
||(a[x-3][y-3]==iflag&&a[x-2][y-2]==iflag&&a[x-1][y-1]==iflag&&a[x+1][y+1]==iflag)
||(a[x-4][y-4]==iflag&&a[x-3][y-3]==iflag&&a[x-2][y-2]==iflag&&a[x-1][y-1]==iflag))
win1(iflag);
if( (a[x][y+1]==iflag&&a[x][y+2]==iflag&&a[x][y+3]==iflag&&a[x][y+4]==iflag)
||(a[x][y-1]==iflag&&a[x][y+1]==iflag&&a[x][y+2]==iflag&&a[x][y+3]==iflag)
||(a[x][y-2]==iflag&&a[x][y-1]==iflag&&a[x][y+1]==iflag&&a[x][y+2]==iflag)
||(a[x][y-3]==iflag&&a[x][y-2]==iflag&&a[x][y-1]==iflag&&a[x][y+1]==iflag)
||(a[x][y-4]==iflag&&a[x][y-3]==iflag&&a[x][y-2]==iflag&&a[x][y-1]==iflag))
win1(iflag);
if( (a[x+1][y-1]==iflag&&a[x+2][y-2]==iflag&&a[x+3][y-3]==iflag&&a[x+4][y-4]==iflag)
||(a[x-1][y+1]==iflag&&a[x+1][y-1]==iflag&&a[x+2][y-2]==iflag&&a[x+3][y-3]==iflag)
||(a[x-2][y+2]==iflag&&a[x-1][y+1]==iflag&&a[x+1][y-1]==iflag&&a[x+2][y-2]==iflag)
||(a[x-3][y+3]==iflag&&a[x-2][y+2]==iflag&&a[x-1][y+1]==iflag&&a[x+1][y-1]==iflag)
||(a[x-4][y+4]==iflag&&a[x-3][y+3]==iflag&&a[x-2][y+2]==iflag&&a[x-1][y+1]==iflag))
win1(iflag);
}
putchess(int a[16][16])
{
int k,l,x=0,y=0;
f++;
for(k=0;k<16;k++)
for(l=0;l<16;l++)
{
if(a[k][l]==1)
{
x=k*20;
y=l*20;
setlinestyle(0,0,1);
setcolor(14);
qizi(x+50,y+50,14);
// a[k][l]==1;
oldi=k;
oldj=l;
// printf("%d %d",&k,&l);
panduan(a,k,l,1);
}
if(a[k][l]==4)
{
x=k*20;
y=l*20;
setlinestyle(0,0,1);
setcolor(4);
qizi(x+50,y+50,4);
a[k][l]=2;
panduan(a,k,l,2);
}
}
}
qizi(int x,int y,int i)
{
circle(x,y,6);
setfillstyle(1,i-1);
floodfill(x,y,i);
}
judg4_1(int a[16][16],int newi,int newj,int num1,int num2)
{
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2)
{
if(a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi-4][newj]==0)
{
a[newi-4][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-1][newj]==num2 && a[newi-2][newj]==num2 && a[newi+1][newj]==num2)
{
if(a[newi-3][newj]==0)
{
a[newi-3][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj]==0)
{
a[newi+2][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-1][newj]==num2 && a[newi+1][newj]==num2 && a[newi+2][newj]==num2)
{
if(a[newi-2][newj]==0)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj]==0)
{
a[newi+3][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi+1][newj]==num2 && a[newi+2][newj]==num2 && a[newi+3][newj]==num2)
{
if(a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj]==0)
{
a[newi+4][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi-4][newj]==num2&&a[newi-3][newj]==num2&&a[newi-1][newj]==num2&&a[newi][newj]==num2)
{
if(a[newi-2][newj]==0)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi-3][newj]==num2&&a[newi-2][newj]==num2&&a[newi+1][newj]==num2&&a[newi][newj]==num2)
{
if(a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi-1][newj]==num2&&a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2)
{
if(a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+3][newj]==num2&&a[newi+4][newj]==num2) //8
{
if(a[newi+2][newj]==0)
{
a[newi+2][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2&&a[newi-4][newj]==num2)
{
if(a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi+1][newj]==num2&&a[newi+2][newj]==num2)
{
if(a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2&&a[newi+4][newj]==num2)
{
if(a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2&&a[newi+2][newj]==num2)
{
if(a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
}
//heng lian 4
if(a[newi][newj]==num2 && a[newi-1][newj-1]==num2 && a[newi-2][newj-2]==num2 && a[newi-3][newj-3]==num2)
{
if(a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi-4][newj-4]==0)
{
a[newi-4][newj-4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-1][newj-1]==num2 && a[newi-2][newj-2]==num2 && a[newi+1][newj+1]==num2)
{
if(a[newi-3][newj-3]==0)
{
a[newi-3][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj+2]==0)
{
a[newi+2][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-1][newj-1]==num2 && a[newi+1][newj+1]==num2 && a[newi+2][newj+2]==num2)
{
if(a[newi-2][newj-2]==0)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj+3]==0)
{
a[newi+3][newj+3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi+1][newj+1]==num2 && a[newi+2][newj+1]==num2 && a[newi+3][newj+3]==num2)
{
if(a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj+4]==0)
{
a[newi+4][newj+4]=num1;
putchess(a);
return 5;
}
}
if(a[newi-4][newj-4]==num2&&a[newi-3][newj-3]==num2&&a[newi-1][newj-1]==num2&&a[newi][newj]==num2)
{
if(a[newi-2][newj-2]==0)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi-3][newj-3]==num2&&a[newi-2][newj-2]==num2&&a[newi+1][newj+1]==num2&&a[newi][newj]==num2)
{
if(a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi-1][newj-1]==num2&&a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2)
{
if(a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+3][newj+3]==num2&&a[newi+4][newj+4]==num2)
{
if(a[newi+2][newj+2]==0)
{
a[newi+2][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2&&a[newi-3][newj-3]==num2&&a[newi-4][newj-4]==num2)
{
if(a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2&&a[newi+1][newj+1]==num2&&a[newi+2][newj+2]==num2)
{
if(a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2&&a[newi+4][newj+4]==num2)
{
if(a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-2][newj-2]==num2&&a[newi+2][newj+2]==num2)
{
if(a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
}
//you xie lian 4
if(a[newi][newj]==num2 && a[newi][newj-1]==num2 && a[newi][newj-2]==num2 && a[newi][newj-3]==num2)
{
if(a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj-4]==0)
{
a[newi][newj-4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi][newj-1]==num2 && a[newi][newj-2]==num2 && a[newi][newj+1]==num2)
{
if(a[newi][newj-3]==0)
{
a[newi][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+2]==0)
{
a[newi][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi][newj-1]==num2 && a[newi][newj+1]==num2 && a[newi][newj+2]==num2)
{
if(a[newi][newj-2]==0)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+3]==0)
{
a[newi][newj+3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi][newj+1]==num2 && a[newi][newj+2]==num2 && a[newi][newj+3]==num2)
{
if(a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+4]==0)
{
a[newi][newj+4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj-4]==num2&&a[newi][newj-3]==num2&&a[newi][newj-1]==num2&&a[newi][newj]==num2)
{
if(a[newi][newj-2]==0)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj-3]==num2&&a[newi][newj-2]==num2&&a[newi][newj+1]==num2&&a[newi][newj]==num2)
{
if(a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj-1]==num2&&a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2)
{
if(a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+3]==num2&&a[newi][newj+4]==num2)
{
if(a[newi][newj+2]==0)
{
a[newi][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-2]==num2&&a[newi][newj-3]==num2&&a[newi][newj-4]==num2)
{
if(a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-2]==num2&&a[newi][newj+1]==num2&&a[newi][newj+2]==num2)
{
if(a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2&&a[newi][newj+4]==num2)
{
if(a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-2]==num2&&a[newi][newj+2]==num2)
{
if(a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
}
//shu lian 4
if(a[newi][newj]==num2 && a[newi-1][newj+1]==num2 && a[newi-2][newj+2]==num2 && a[newi-3][newj+3]==num2)//1
{
if(a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi-4][newj+4]==0)
{
a[newi-4][newj+4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-1][newj+1]==num2 && a[newi-2][newj+2]==num2 && a[newi+1][newj-1]==num2)//2
{
if(a[newi-3][newj+3]==0)
{
a[newi-3][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj-2]==0)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-1][newj+1]==num2 && a[newi+1][newj-1]==num2 && a[newi+2][newj-2]==num2)//3
{
if(a[newi-2][newj+2]==0)
{
a[newi-2][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj-3]==0)
{
a[newi+3][newj-3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi+1][newj-1]==num2 && a[newi+2][newj-1]==num2 && a[newi+3][newj-3]==num2)//4
{
if(a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj-4]==0)
{
a[newi+4][newj-4]=num1;
putchess(a);
return 5;
}
}
if(a[newi-4][newj+4]==num2&&a[newi-3][newj+3]==num2&&a[newi-1][newj+1]==num2&&a[newi][newj]==num2) //5
{
if(a[newi-2][newj+2]==0)
{
a[newi-2][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi-3][newj+3]==num2&&a[newi-2][newj+2]==num2&&a[newi+1][newj-1]==num2&&a[newi][newj]==num2) //6
{
if(a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi-1][newj+1]==num2&&a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2)//7
{
if(a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+3][newj-3]==num2&&a[newi+4][newj-4]==num2)//8
{
if(a[newi+2][newj-2]==0)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2&&a[newi+4][newj-4]==num2) //9
{
if(a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi-1][newj+1]==num2&&a[newi-2][newj+2]==num2) //10
{
if(a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2&&a[newi-3][newj+3]==num2&&a[newi-4][newj+4]==2) //11
{
if(a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+2][newj-2]==num2&&a[newi-2][newj+2]==num2) //12
{
if(a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
//zuo xie lian 4
// Yi Shang Lian 4
}
judg3_1(int a[16][16],int newi,int newj,int num1,int num2)
{
if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2 && a[newi-4][newj]==0&&a[newi-1][newj]==0&&a[newi+1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-3][newj]==num2 && a[newi-4][newj]==0&&a[newi-2][newj]==0&&a[newi+1][newj]==0)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2 && a[newi-3][newj]==0&&a[newi+1][newj]==0)
{
a[newi-3][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2 && a[newi-2][newj]==num2 && a[newi+1][newj]==num2 && a[newi-3][newj]==0&&a[newi-1][newj]==0&&a[newi+2][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+1][newj]==num2 && a[newi-2][newj]==0&&a[newi+2][newj]==0)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+2][newj]==num2 && a[newi-2][newj]==0&&a[newi+1][newj]==0&&a[newi+3][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+2][newj]==num2 && a[newi-1][newj]==0&&a[newi+3][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+3][newj]==num2 && a[newi-1][newj]==0&&a[newi+2][newj]==0&&a[newi+4][newj]==0)
{
a[newi+2][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2&& a[newi-1][newj]==0&&a[newi+1][newj]==0&&a[newi+4][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
//heng lian 3
if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2&&a[newi-3][newj-3]==num2 && a[newi-4][newj-4]==0&&a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-3][newj-3]==num2 && a[newi-4][newj-4]==0&&a[newi-2][newj-2]==0&&a[newi+1][newj+1]==0)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-2][newj-2]==num2 && a[newi-3][newj-3]==0&&a[newi+1][newj+1]==0)
{
a[newi-3][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2 && a[newi-2][newj-2]==num2 && a[newi+1][newj+1]==num2 && a[newi-3][newj-3]==0&&a[newi-1][newj-1]==0&&a[newi+2][newj+2]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+1][newj+1]==num2 && a[newi-2][newj-2]==0&&a[newi+2][newj+2]==0)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+2][newj+2]==num2 && a[newi-2][newj-2]==0&&a[newi+1][newj+1]==0&&a[newi+3][newj+3]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+2][newj+2]==num2 && a[newi-1][newj-1]==0&&a[newi+3][newj+3]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+3][newj+3]==num2 && a[newi-1][newj-1]==0&&a[newi+2][newj+2]==0&&a[newi+4][newj+4]==0)
{
a[newi+2][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2&& a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0&&a[newi+4][newj+4]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
//you xie lian 3
if(a[newi][newj]==num2&&a[newi][newj-2]==num2&&a[newi][newj-3]==num2 && a[newi][newj-4]==0&&a[newi][newj-1]==0&&a[newi][newj+1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-3]==num2 && a[newi][newj-4]==0&&a[newi][newj-2]==0&&a[newi][newj+1]==0)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-2]==num2 && a[newi][newj-3]==0&&a[newi][newj+1]==0)
{
a[newi][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2 && a[newi][newj-2]==num2 && a[newi][newj+1]==num2 && a[newi][newj-3]==0&&a[newi][newj-1]==0&&a[newi][newj+2]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+1]==num2 && a[newi][newj-2]==0&&a[newi][newj+2]==0)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+2]==num2 && a[newi][newj-2]==0&&a[newi][newj+1]==0&&a[newi][newj+3]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+2]==num2 && a[newi][newj-1]==0&&a[newi][newj+3]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+3]==num2 && a[newi][newj-1]==0&&a[newi][newj+2]==0&&a[newi][newj+4]==0)
{
a[newi][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2&& a[newi][newj-1]==0&&a[newi][newj+1]==0&&a[newi][newj+4]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
//shu lian 3
if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2 && a[newi+4][newj-4]==0&&a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+3][newj-3]==num2 && a[newi+4][newj-4]==0&&a[newi+2][newj-2]==0&&a[newi-1][newj+1]==0)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+2][newj-2]==num2 && a[newi+3][newj-3]==0&&a[newi-1][newj+1]==0)
{
a[newi+3][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2 && a[newi+2][newj-2]==num2 && a[newi-1][newj+1]==num2 && a[newi+3][newj-3]==0&&a[newi+1][newj-1]==0&&a[newi-2][newj+2]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi-1][newj+1]==num2 && a[newi+2][newj-2]==0&&a[newi-2][newj+2]==0)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi-2][newj+2]==num2 && a[newi+2][newj-2]==0&&a[newi-1][newj+1]==0&&a[newi-3][newj+3]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-2][newj+2]==num2 && a[newi+1][newj-1]==0&&a[newi-3][newj+3]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-3][newj+3]==num2 && a[newi+1][newj-1]==0&&a[newi-2][newj+2]==0&&a[newi-4][newj+4]==0)
{
a[newi-2][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2&&a[newi-3][newj+3]==num2&& a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0&&a[newi-4][newj+4]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
//zuo xie lian 3
// Yi Shang Lian 3 Bidu
}
judg3_2(int a[16][16],int newi,int newj,int num1,int num2)
{
if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2 &&a[newi-1][newj]==0)
{
if(a[newi-4][newj]==num1&&a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj]==num1&&a[newi-4][newj]==0)
{
a[newi-4][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-3][newj]==num2 &&a[newi-2][newj]==0)
{
if(a[newi-4][newj]==num1&&a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj]==num1&&a[newi-4][newj]==0)
{
a[newi-4][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2)
{
if(a[newi-3][newj]==num1&&a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj]==num1&&a[newi-3][newj]==0)
{
a[newi-3][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-2][newj]==num2 && a[newi+1][newj]==num2 &&a[newi-1][newj] == 0)
{
if(a[newi-3][newj]==num1&&a[newi+2][newj]==0)
{
a[newi+2][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj]==num1&&a[newi-3][newj]==0)
{
a[newi-3][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+1][newj]==num2)
{
if(a[newi-2][newj]==num1&&a[newi+2][newj]==0)
{
a[newi+2][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj]==num1&&a[newi-2][newj]==0)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+2][newj]==num2 &&a[newi+1][newj] == 0)
{
if(a[newi-2][newj]==num1&&a[newi+3][newj]==0)
{
a[newi+3][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj]==num1&&a[newi-2][newj]==0)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+2][newj]==num2)
{
if(a[newi-1][newj]==num1&&a[newi+3][newj]==0)
{
a[newi+3][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj]==num1&&a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+3][newj]==num2 &&a[newi+2][newj]==0)
{
if(a[newi-1][newj]==num1&&a[newi+4][newj]==0)
{
a[newi+4][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj]==num1&&a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2 &&a[newi+1][newj]==0)
{
if(a[newi-1][newj]==num1&&a[newi+4][newj]==0)
{
a[newi+4][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj]==num1&&a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
//heng lian 3
if(a[newi][newj]==num2&&a[newi-3][newj-3]==num2&&a[newi-2][newj-2]==num2 &&a[newi-1][newj-1]==0)
{
if(a[newi-4][newj-4]==num1&&a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj+1]==num1&&a[newi-4][newj-4]==0)
{
a[newi-4][newj-4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-3][newj-3]==num2 &&a[newi-2][newj-2]==0)
{
if(a[newi-4][newj-4]==num1&&a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj+1]==num1&&a[newi-4][newj-4]==0)
{
a[newi-4][newj-4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-2][newj-2]==num2)
{
if(a[newi-3][newj-3]==num1&&a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj+1]==num1&&a[newi-3][newj-3]==0)
{
a[newi-3][newj-3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-2][newj-2]==num2 && a[newi+1][newj+1]==num2&&a[newi-1][newj-1] == 0)
{
if(a[newi-3][newj-3]==num1&&a[newi+2][newj+2]==0)
{
a[newi+2][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj+2]==num1&&a[newi-3][newj-3]==0)
{
a[newi-3][newj-3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+1][newj+1]==num2)
{
if(a[newi-2][newj-2]==num1&&a[newi+2][newj+2]==0)
{
a[newi+2][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj+2]==num1&&a[newi-2][newj-2]==0)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+2][newj+2]==num2&&a[newi+1][newj+1]==0)
{
if(a[newi-2][newj-2]==num1&&a[newi+3][newj+3]==0)
{
a[newi+3][newj+3]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj+3]==num1&&a[newi-2][newj-2]==0)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+2][newj+2]==num2)
{
if(a[newi-1][newj-1]==num1&&a[newi+3][newj+3]==0)
{
a[newi+3][newj+3]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj+3]==num1&&a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+3][newj+3]==num2&&a[newi+2][newj+2]==0)
{
if(a[newi-1][newj-1]==num1&&a[newi+4][newj+4]==0)
{
a[newi+4][newj+4]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj+4]==num1&&a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2&&a[newi+1][newj+1]==0)
{
if(a[newi-1][newj-1]==num1&&a[newi+4][newj+4]==0)
{
a[newi+4][newj+4]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj+4]==num1&&a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
//you xie lian 3
if(a[newi][newj]==num2&&a[newi][newj-3]==num2&&a[newi][newj-2]==num2&&a[newi][newj-1]==0)
{
if(a[newi][newj-4]==num1&&a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+1]==num1&&a[newi][newj-4]==0)
{
a[newi][newj-4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-3]==num2&&a[newi][newj-2]==0)
{
if(a[newi][newj-4]==num1&&a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+1]==num1&&a[newi][newj-4]==0)
{
a[newi][newj-4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-2]==num2)
{
if(a[newi][newj-3]==num1&&a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+1]==num1&&a[newi][newj-3]==0)
{
a[newi][newj-3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi][newj-2]==num2 && a[newi][newj+1]==num2&&a[newi][newj-1] == 0)
{
if(a[newi][newj-3]==num1&&a[newi][newj+2]==0)
{
a[newi][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+2]==num1&&a[newi][newj-3]==0)
{
a[newi][newj-3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+1]==num2)
{
if(a[newi][newj-2]==num1&&a[newi][newj+2]==0)
{
a[newi][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+2]==num1&&a[newi][newj-2]==0)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+2]==num2&&a[newi][newj+1]==0)
{
if(a[newi][newj-2]==num1&&a[newi][newj+3]==0)
{
a[newi][newj+3]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+3]==num1&&a[newi][newj-2]==0)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+2]==num2)
{
if(a[newi][newj-1]==num1&&a[newi][newj+3]==0)
{
a[newi][newj+3]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+3]==num1&&a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+3]==num2&&a[newi][newj+2]==0)
{
if(a[newi][newj-1]==num1&&a[newi][newj+4]==0)
{
a[newi][newj+4]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+4]==num1&&a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2&&a[newi][newj+1]==0)
{
if(a[newi][newj-1]==num1&&a[newi][newj+4]==0)
{
a[newi][newj+4]=num1;
putchess(a);
return 5;
}
if(a[newi][newj+4]==num1&&a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
//shu lian 3
if(a[newi][newj]==num2&&a[newi-3][newj+3]==num2&&a[newi-2][newj+2]==num2&&a[newi-1][newj+1]==0)
{
if(a[newi-4][newj+4]==num1&&a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj-1]==num1&&a[newi-4][newj+4]==0)
{
a[newi-4][newj+4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-3][newj+3]==num2&&a[newi-2][newj+2]==0)
{
if(a[newi-4][newj+4]==num1&&a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj-1]==num1&&a[newi-4][newj+4]==0)
{
a[newi-4][newj+4]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-2][newj+2]==num2)
{
if(a[newi-3][newj+3]==num1&&a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi+1][newj-1]==num1&&a[newi-3][newj+3]==0)
{
a[newi-3][newj+3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2 && a[newi-2][newj+2]==num2 && a[newi+1][newj-1]==num2&&a[newi-1][newj+1] == 0)
{
if(a[newi-3][newj+3]==num1&&a[newi+2][newj-2]==0)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj-2]==num1&&a[newi-3][newj+3]==0)
{
a[newi-3][newj+3]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi+1][newj-1]==num2)
{
if(a[newi-2][newj+2]==num1&&a[newi+2][newj-2]==0)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj-2]==num1&&a[newi-2][newj+2]==0)
{
a[newi-2][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi+2][newj-2]==num2&&a[newi+1][newj-1]==0)
{
if(a[newi-2][newj+2]==num1&&a[newi+3][newj-3]==0)
{
a[newi+3][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj-3]==num1&&a[newi-2][newj+2]==0)
{
a[newi-2][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+2][newj-2]==num2)
{
if(a[newi-1][newj+1]==num1&&a[newi+3][newj-3]==0)
{
a[newi+3][newj-3]=num1;
putchess(a);
return 5;
}
if(a[newi+3][newj-3]==num1&&a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+3][newj-3]==num2&&a[newi+2][newj-2]==0)
{
if(a[newi-1][newj+1]==num1&&a[newi+4][newj-4]==0)
{
a[newi+4][newj-4]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj-4]==num1&&a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2&&a[newi+1][newj-1]==0)
{
if(a[newi-1][newj+1]==num1&&a[newi+4][newj-4]==0)
{
a[newi+4][newj-4]=num1;
putchess(a);
return 5;
}
if(a[newi+4][newj-4]==num1&&a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
//zuo xie lian 3
/* Yi Shang Lian 3 */
}
judg2_1(int a[16][16],int newi,int newj,int num1,int num2)
{
if(a[newi][newj]==num2&&a[newi-1][newj]==num2 &&a[newi-2][newj]==0&&a[newi+1][newj]==0)
{
if(random(1)==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj]==num2 &&a[newi-1][newj]==0&&a[newi+2][newj]==0)
{
if(random(1)==0)
{
a[newi+2][newj]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj]==num2 &&a[newi-3][newj]==0&&a[newi-1][newj]==0&&a[newi+1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+2][newj]==num2 &&a[newi-1][newj]==0&&a[newi+1][newj]==0&&a[newi+3][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
//hen 2
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2 &&a[newi-2][newj-2]==0&&a[newi+1][newj+1]==0)
{
if(random(1)==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2 &&a[newi-1][newj-1]==0&&a[newi+2][newj+2]==0)
{
if(random(1)==0)
{
a[newi+2][newj+2]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2 &&a[newi-3][newj-3]==0&&a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2 &&a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0&&a[newi+3][newj+3]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
//you xie 2
if(a[newi][newj]==num2&&a[newi][newj-1]==num2 &&a[newi][newj-2]==0&&a[newi][newj+1]==0)
{
if(random(1)==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj+1]==num2 &&a[newi][newj-1]==0&&a[newi][newj+2]==0)
{
if(random(1)==0)
{
a[newi][newj+2]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-2]==num2 &&a[newi][newj-3]==0&&a[newi][newj-1]==0&&a[newi][newj+1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj+2]==num2 &&a[newi][newj-1]==0&&a[newi][newj+1]==0&&a[newi][newj+3]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
//shu 2
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2 &&a[newi+2][newj-2]==0&&a[newi-1][newj+1]==0)
{
if(random(1)==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2 &&a[newi+1][newj-1]==0&&a[newi-2][newj+2]==0)
{
if(random(1)==0)
{
a[newi-2][newj+2]=num1;
putchess(a);
return 5;
}
if(random(1)==1)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2 &&a[newi+3][newj-3]==0&&a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2 &&a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0&&a[newi-3][newj+3]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
//zuo xie 2
}
judg2_2(int a[16][16],int newi,int newj,int num1,int num2)
{
if(a[newi][newj]==num2&&a[newi-1][newj]==num2)
{
if(a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi-2][newj]==0)
{
a[newi-2][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj]==num2)
{
if(a[newi+2][newj]==0)
{
a[newi+2][newj]=num1;
putchess(a);
return 5;
}
if(a[newi+2][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj]==num2)
if(a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+2][newj]==num2)
if(a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2)
{
if(a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi-2][newj-2]==0)
{
a[newi-2][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2)
{
if(a[newi+2][newj+2]==0)
{
a[newi+2][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2)
if(a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2)
if(a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj-1]==num2)
{
if(a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj-2]==0)
{
a[newi][newj-2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj+1]==num2)
{
if(a[newi][newj+2]==0)
{
a[newi][newj+2]=num1;
putchess(a);
return 5;
}
if(a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi][newj-2]==num2)
if(a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi][newj+2]==num2)
if(a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2)
{
if(a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi-2][newj+2]==0)
{
a[newi-2][newj+2]=num1;
putchess(a);
return 5;
}
}
if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2)
{
if(a[newi+2][newj-2]==0)
{
a[newi+2][newj-2]=num1;
putchess(a);
return 5;
}
if(a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2)
if(a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2)
if(a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
}
judg1_1(int a[16][16],int newi,int newj,int num1,int num2)
{
if(a[newi][newj]==num2)
{
if(random(7)==0&&a[newi][newj-1]==0)
{
a[newi][newj-1]=num1;
putchess(a);
return 5;
}
if(random(7)==1&&a[newi][newj+1]==0)
{
a[newi][newj+1]=num1;
putchess(a);
return 5;
}
if(random(7)==2&&a[newi-1][newj]==0)
{
a[newi-1][newj]=num1;
putchess(a);
return 5;
}
if(random(7)==3&&a[newi+1][newj]==0)
{
a[newi+1][newj]=num1;
putchess(a);
return 5;
}
if(random(7)==4&&a[newi-1][newj-1]==0)
{
a[newi-1][newj-1]=num1;
putchess(a);
return 5;
}
if(random(7)==5&&a[newi+1][newj+1]==0)
{
a[newi+1][newj+1]=num1;
putchess(a);
return 5;
}
if(random(7)==6&&a[newi+1][newj-1]==0)
{
a[newi+1][newj-1]=num1;
putchess(a);
return 5;
}
if(random(7)==7&&a[newi-1][newj+1]==0)
{
a[newi-1][newj+1]=num1;
putchess(a);
return 5;
}
}
}
int comp_4_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg4_1(a,i,j,1,1)==5)
return 6;
}
int user_4_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg4_1(a,i,j,1,2)==5)
return 6;
}
int comp_3_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg3_1(a,i,j,1,1)==5)
return 6;
}
int user_3_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg3_1(a,i,j,1,2)==5)
return 6;
}
int comp_3_2put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg3_2(a,i,j,1,1)==5)
return 6;
}
int user_3_2put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg3_2(a,i,j,1,2)==5)
return 6;
}
int comp_2_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg2_1(a,i,j,1,1)==5)
return 6;
}
int user_2_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg2_1(a,i,j,1,2)==5)
return 6;
}
int comp_2_2put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg2_2(a,i,j,1,1)==5)
return 6;
}
int user_2_2put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg2_2(a,i,j,1,2)==5)
return 6;
}
int comp_1_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg1_1(a,i,j,1,1)==5)
return 6;
}
int user_1_1put(int a[16][16])
{
int i,j;
for(i=4;i<=11;i++)
for(j=4;j<=11;j++)
if(judg1_1(a,i,j,1,2)==5)
return 6;
}
chesstable()
{
int i,j;
setlinestyle(0,0,0);
setcolor(2);
for(i=0;i<=15;i++)
for(j=0;j<=15;j++)
rectangle(50+i*20,50+j*20,i*20+70,j*20+70);
}
main(void)
{
int i = 0,j = 0, k, l, m, n, x = 0, y = 0;
int weii, weij;
int a[16][16], b[16][16];
int gd=0, gm;
for(k = 0; k < 16; k++)
for(l = 0; l < 16; l++)
a[k][l]=0;
initgraph(&gd, &gm, "f://shiter//tc//");
setbkcolor(0);
chesstable();
gotoxy(55, 4); printf("PLAY_1 ");
gotoxy(60, 5); printf("E -- 上 ");
gotoxy(60, 7); printf("D -- 下 ");
gotoxy(60, 9); printf("S -- 左 ");
gotoxy(60, 11); printf("F -- 右 ");
gotoxy(60, 13); printf("SPACE --确定 ");
gotoxy(55, 15); printf("PLAY_2 ");
gotoxy(60, 16); printf("UP -- 上 ");
gotoxy(60, 18); printf("DOWN -- 下 ");
gotoxy(60, 20); printf("LEFT -- 左 ");
gotoxy(60, 22); printf("RIGHT -- 右 ");
gotoxy(60, 24); printf("DEL -- 确定");
while(1)
{
// setlinestyle(0, 0, 3);
// line(x + 50 - 8, y + 58, x + 58, y + 58);
if(f%2==0)
{
if(comp_4_1put(a)==6)
continue;
if(user_4_1put(a)==6)
continue;
if(comp_3_1put(a)==6)
continue;
if(user_3_1put(a)==6)
continue;
if(comp_3_2put(a)==6)
continue;
if(comp_2_1put(a)==6)
continue;
if(user_3_2put(a)==6)
continue;
if(comp_1_1put(a)==6)
continue;
if(user_2_1put(a)==6)
continue;
if(user_1_1put(a)==6)
continue;
f++;
}
else
{
while(bioskey(1)!=0)
{
i=x/20;
j=y/20;
switch(bioskey(0))
{
case KEY_UP: setlinestyle(0,0,3);
setcolor(0);
line(x+42,y+58,x+58,y+58);
setcolor(2);
setlinestyle(0,0,0);
line(x+50,y+57,x+50,y+59);
y-=20;
if(y<0)
y=0;
setlinestyle(0,0,3);
line(x+42,y+58,x+58,y+58);
break;
case KEY_DOWN: setlinestyle(0,0,3);
setcolor(0);
line(x+42,y+58,x+58,y+58);
setcolor(2);
setlinestyle(0,0,0);
line(x+50,y+57,x+50,y+59);
y+=20;
if(y>300)
y=300;
setlinestyle(0,0,3);
line(x+42,y+58,x+58,y+58);
break;
case KEY_LEFT: setlinestyle(0,0,3);
setcolor(0);
line(x+42,y+58,x+58,y+58);
setcolor(2);
setlinestyle(0,0,0);
line(x+50,y+57,x+50,y+59);
x-=20;
if(x<0)
x=0;
setlinestyle(0,0,3);
line(x+42,y+58,x+58,y+58);
break;
case KEY_RIGHT: setlinestyle(0,0,3);
setcolor(0);
line(x+42,y+58,x+58,y+58);
setcolor(2);
setlinestyle(0,0,0);
line(x+50,y+57,x+50,y+59);
x+=20;
if(x>320)
x=320;
setlinestyle(0,0,3);
line(x+42,y+58,x+58,y+58);
break;
case KEY_SPACE:if(a[i][j]==0)
{
a[i][j]=4;
setlinestyle(0,0,3);
setcolor(0);
line(x+42,y+58,x+58,y+58);
putchess(a);
continue;
}
continue;
case KEY_ESC: again();
line(x+42,y+58,x+58,y+58);
}
}
}
}
getch();
}
不复杂,看看就懂了。贴上来那两个吧!
mousea.h
# include <dos.h>
# include <graphics.h>
# define TRUE 1
# define FALSE 0
int mouse_installed = FALSE;
/*=========================================================================*/
功能 入口参数 出口参数
初始化mouse ax = 0x0000h ax = mouse状态(-1=已安装,0=未安装)
bx = mouse按扭数目
/*=========================================================================*/
int InitMouse()
{
union REGS r;
r.x.ax = 0;
int86(0x33,&r,&r);
if(r.x.ax == 0xffff)
mouse_installed = TRUE;
else
mouse_installed = FALSE;
return(r.x.bx);
}
/*======================================================================*/
显示鼠标 ax=0x0001h
/*======================================================================*/
int ShowMouse()
{
union REGS r;
if(mouse_installed == FALSE)return(-1);
r.x.ax = 0x0001;
int86(0x33,&r,&r);
return(0);
}
/*======================================================================*/
隐藏鼠标 ax=0x0002h
/*======================================================================*/
int HideMouse()
{
union REGS r;
if(mouse_installed == FALSE) return(-1);
r.x.ax = 0x0002;
int86(0x33,&r,&r);
return(0);
}
/*======================================================================*/
读取鼠标位置 ax=0x0003h cx=x
dx=y
/*======================================================================*/
int GetMouseXY(int *x,int *y)
{
union REGS r;
if(mouse_installed == FALSE)return(-1);
r.x.ax = 0x0003;
int86(0x33,&r,&r);
*x = r.x.cx;
*y = r.x.dx;
return(0);
}
/*======================================================================*/
设置鼠标位置 ax=0x0004h
cx=x
dx=y
/*======================================================================*/
int SetMouseXY(int x,int y)
{
union REGS r;
if(mouse_installed == FALSE)return(-1);
r.x.ax = 0x0004;
r.x.cx = x;
r.x.dx = y;
int86(0x33,&r,&r);
return(0);
}
/*======================================================================*/
读取按下信息 ax = 0x0005h ax = 读取按下信息
bx = 按键序号
/*======================================================================*/
int GetPressInfo(int button)
{
union REGS r;
if(mouse_installed == FALSE)return(-1);
r.x.ax = 0x0005;
r.x.bx = button;
int86(0x33,&r,&r);
return(r.x.bx);
}
/*======================================================================*/
读取放开信息 ax = 0x0006h ax = 读取放开信息
bx = 按键序号
/*======================================================================*/
int GetReleaseInfo(int button)
{
union REGS r;
if(mouse_installed == FALSE)return(-1);
r.x.ax = 0x0006;
r.x.bx = button;
int86(0x33,&r,&r);
return(r.x.bx);
}
/*======================================================================*/
设置mouse
的x方向范围 ax = 0x0007h
cx = x(min)
dx = x(max)
/*======================================================================*/
int SetXRange(int min,int max)
{
union REGS r;
if(mouse_installed == FALSE)return(-1);
r.x.ax = 0x0007;
r.x.cx = min;
r.x.dx = max;
int86(0x33,&r,&r);
return(0);
}
/*======================================================================*/
设置mouse
的y方向范围 ax = 0x0008h
cx = y(min)
dx = y(max)
/*======================================================================*/
int SetYRange(int min,int max)
{
union REGS r;
if(mouse_installed == FALSE)return(-1);
r.x.ax = 0x0008;
r.x.cx = min;
r.x.dx = max;
int86(0x33,&r,&r);
return(0);
}
bioskey.h
/*========================================================*/
BIOSKEY define file bioskey.h
Created by Shiter 2000.7.10
/*========================================================*/
# define KEY_` 0x2960
# define KEY_1 0x0231
# define KEY_2 0x0332
# define KEY_3 0x0433
# define KEY_4 0x0534
# define KEY_5 0x0635
# define KEY_6 0x0736
# define KEY_7 0x0837
# define KEY_8 0x0938
# define KEY_9 0x0A39
# define KEY_0 0x0B30
# define KEY_BACKSPACE 0x0E08
# define KEY_TAB 0x0F09
# define KEY_q 0x1071
# define KEY_w 0x1177
# define KEY_e 0x1265
# define KEY_r 0x1372
# define KEY_t 0x1474
# define KEY_y 0x1579
# define KEY_u 0x1675
# define KEY_i 0x1769
# define KEY_o 0x186F
# define KEY_p 0x1970
# define KEY_a 0x1E61
# define KEY_s 0x1F73
# define KEY_d 0x2064
# define KEY_f 0x2166
# define KEY_g 0x2267
# define KEY_h 0x2368
# define KEY_j 0x246A
# define KEY_k 0x256B
# define KEY_l 0x266C
# define KEY_ENTER 0x1C0D
# define KEY_z 0x2C7A
# define KEY_x 0x2D78
# define KEY_c 0x2E63
# define KEY_v 0x2F76
# define KEY_b 0x3062
# define KEY_n 0x316E
# define KEY_m 0x326D
# define KEY_SPACE 0x3920
# define KEY_INSERT 0x5200
# define KEY_HOME 0x4700
# define KEY_PAGEUP 0x4900
# define KEY_DELETE 0x5300
# define KEY_END 0x4F00
# define KEY_PAGEDN 0x5100
# define KEY_LEFT 0x4B00
# define KEY_RIGHT 0x4D00
# define KEY_UP 0x4800
# define KEY_DOWN 0x5000
# define KEY_f1 0x3B00
# define KEY_f2 0x3C00
# define KEY_f3 0x3D00
# define KEY_f4 0x3E00
# define KEY_f5 0x3F00
# define KEY_f6 0x4000
# define KEY_f7 0x4100
# define KEY_f8 0x4200
# define KEY_f9 0x4300
# define KEY_f10 0x4400
# define KEY_ESC 0x011B
# define KEY_A 0x1E41
# define KEY_B 0x3042
# define KEY_C 0x2E43
# define KEY_D 0x2044
# define KEY_E 0x1245
# define KEY_F 0x2146
# define KEY_G 0x2247
# define KEY_H 0x2348
# define KEY_I 0x1749
# define KEY_J 0x244A
# define KEY_K 0x254B
# define KEY_L 0x264C
# define KEY_M 0x324D
# define KEY_N 0x314E
# define KEY_O 0x184F
# define KEY_P 0x1950
# define KEY_Q 0x1051
# define KEY_R 0x1352
# define KEY_S 0x1F53
# define KEY_T 0x1454
# define KEY_U 0x1655
# define KEY_V 0x2F56
# define KEY_W 0x1157
# define KEY_X 0x2D58
# define KEY_Y 0x1559
# define KEY_Z 0x2C5A