#includevoid main()
{
int t,n,row,num,q=0,b,i,winner=0,j;
char a[3][3]={'1','2','3','4','5','6','7','8','9'};
printf("******************************************************\n");
printf("******************欢迎进入一担挑游戏******************\n");
printf("******************************************************\n");
printf("\n");
printf("进入游戏请按1,结束游戏请按0\n");
scanf("%d",&t);
while(t)
{
for(i=0;i<9&&winner==0;i++)
{
b=q%2+1;
printf(" %c | %c | %c\n",a[0][0],a[0][1],a[0][2]);
printf("---+---+---\n");
printf(" %c | %c | %c\n",a[1][0],a[1][1],a[1][2]);
printf("---+---+---\n");
printf(" %c | %c | %c\n",a[2][0],a[2][1],a[2][2]);
printf("玩家%d请选择\n",b);
q++;
scanf("%d",&n);
while(n<1||n>9)
{
printf("选择错误!无该位置.请重新选择\n");
scanf("%d",&n);
}
row=n/3;
num=n%3-1;
while(a[row][num]=='o'||a[row][num]=='x')
{
printf("选择错误!该位置已经被选择过.请重新选择\n");
scanf("%d",&n);
row=n/3;
num=n%3-1;
}
while(n<1||n>9)
{
printf("选择错误!无该位置.请重新选择\n");
scanf("%d",&n);
}
row=n/3;
num=n%3-1;
if(b==1)a[row][num]='o'; /*判断是否已经有玩家胜出*/
else a[row][num]='x';
if((a[0][0]==a[1][1]&&a[1][1]==a[2][2]&&a[0][0]=='o')||(a[0][2]==a[1][1]&&a[1][1]==a[2][0]&&a[0][2]=='o'))
winner=1;
else if((a[0][0]==a[1][1]&&a[1][1]==a[2][2]&&a[0][0]=='x')||(a[0][2]==a[1][1]&&a[1][1]==a[2][0]&&a[0][2]=='x'))
winner=2;
for(j=0;j<3;j++)
{
if((a[j][0]==a[j][1]&&a[j][1]==a[j][2]&&a[j][0]=='o')||(a[0][j]==a[1][j]&&a[1][j]==a[2][j]&a[0][j]=='o'))
winner=1;
else if((a[j][0]==a[j][1]&&a[j][1]==a[j][2]&&a[j][0]=='x')||(a[0][j]==a[1][j]&&a[1][j]==a[2][j]&a[0][j]=='x'))
winner=2;
}
}
if(winner!=0)printf("player%d胜利!\n",winner);
else printf("平局!\n");
printf("继续游戏请按1,结束游戏请按0\n");
scanf("%d",&t);
}
}