这个小游戏程序的运行结果出现了错误,望得修改建议
#include<stdio.h>void main()
{
int i=0;
int player=0;
int winner=0;
int choice=0;
int row=0;
int column=0;
int line=0;
char board[3][3]={
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
for(i=0;i<9;i++)
{
printf("\n\n");
printf("%c|%c|%c\n",board[0][0],board[0][1],board[0][2]);
printf("-+-+-\n");
printf("%c|%c|%c\n",board[1][0],board[1][1],board[1][2]);
printf("-+-+-\n");
printf("%c|%c|%c\n",board[2][0],board[2][1],board[2][2]);
printf("-+-+-\n");
player=i%2+1;
do
{
printf("\nplayer %d ,please enter the number of the square where you want place your %c\n",player,(player==1)?'x':'o');
scanf("%d",&choice);
row=--choice/3;
column=choice%3;
}while(choice<0||choice>9||board[row][column]>'9');
board[row][column]=(player==1)?'x':'o';
if((board[0][0]==board[1][1]&&board[0][0]==board[2][2])||(board[0][2]==board[1][1]&&board[0][2]==board[2][0]))
winner=player;
else
for(line=0;line<=2;line++)
if((board[0][line]==board[1][line])&&(board[0][line]==board[2][line])||(board[line][0]==board[line][0])&&(board[line][0]==board[line][2]))
winner=player;
}
printf("\n\n");
printf("%c|%c|%c\n",board[0][0],board[0][1],board[0][2]);
printf("-+-+-\n");
printf("%c|%c|%c\n",board[1][0],board[1][1],board[1][2]);
printf("-+-+-\n");
printf("%c|%c|%c\n",board[2][0],board[2][1],board[2][2]);
printf("-+-+-\n");
if(winner==0)
printf("\nHow boring!it is a draw!\n");
else
printf("congratulations!winner is player %d",winner);
system("pause");
}
这是一个很简单的游戏程序,运行的结果总是winner is player 1 谁能告诉我怎么修正这个程序才能正确运行呢?