#include
#define SIZE 10
#define row 10
#define clow 10
int b[row][clow]={{0}};
void print_board(void){
int i,j,t=0;
//char b[row][clow]={0};
printf(" 0 1 2 3 4 5 6 7 8 9 ");
printf("\n");
printf(" ");
for(i=0;i<2*SIZE+3;i++){
printf("-");
}
printf("\n");
for(i=0;i<SIZE;i++){
printf("%d",t);
t++;
printf("|");
for(j=0;j<SIZE;j++){
//if(*(char )(b)==0)
//printf(" +");
if ((char*)(b+i*SIZE+j)==1)
printf(" @");
else if (*(char*)(b+i*SIZE+j)==2)
printf(" o");
else printf(" +");
}
printf(" |\n");
}
printf(" ");
for (i=0;i<2*SIZE+3;i++){
printf("-");
}
printf("\n");
}
int test(int x,int y){
if(x=row)
return 0;
if(y=clow)
return 0;
if(b[row][clow]==0)
return 1;
return 0;
}
int putchess(int x,int y,int who){
if(test(x,y)){
b[row][clow]=who;
return 1;
}
else
return 2;
}
int check(int x,int y){
int i,j;
int nx = x, ny = y;
int count = 1;
int dir_x[] = {1,1,1,0};
int dir_y[] = {-1,0,1,1};
int who=b[x][y];
if (who == 0)
return 0;
for (i = 0; i < 4; i++)
{
count = 1;
nx = x;
ny = y;
for (j = 0; j < 4; j++)
{
nx += dir_x[i];
ny += dir_y[i];
if (b[nx][ny] == who)
count++;
else
break;
}
if (count == 5)
return 1;
}
return 0;
}
int find(void){
int i, j;
for (i = 0; i < row; i++)
{
for (j = 0; j < clow; j++)
{
if (check(i, j))
return 1;
}
}
return 0;
}
void clearboard(void)
{
int i, j;
for (i = 0; i < row; i++)
{
for (j = 0; j < clow; j++)
{
b[row][clow]= 0;
}
}
}
int main(int argc, char *argv[])
{
int x, y;
int step = 0;
int player = 0;
int choice;
//begin:
while (1)
{
print_board();
player = step % 2 + 1;
printf("player %d : ", player);
scanf("%d%d", &x, &y);
if (putchess(x, y, player))
{
if (find())
{
printf("<%d> Win!\n", player);
printf("1.Quit;2.Continue\n");
scanf("%d", &choice);
if (choice == 1)
break;
else
{
clearboard();
continue;
}
}
print_board();
step++;
}
else
printf("<%d %d> is occupied!\n", x, y);
}
return 0;
}