ok. i removed char winner =get_a_winner(tic_tac_toe); all together and left this char choice =get_user_character(); as is and removed the char from char winner =get_a_winner(tic_tac_toe);......it seems to work fine...I should have noticed that i was delaring winner twice.
I have a function written for a computer play. The computer would take the next open space and play a O.
Code:
int main()
{
int j =0;
char winner;
int O;
clear_board(tic_tac_toe);
print_board( tic_tac_toe);
char choice=get_user_character();
do
{
int i =user_move(tic_tac_toe);
tic_tac_toe[i-1]= choice;
print_board(tic_tac_toe);
winner =get_a_winner(tic_tac_toe);
int computer_move=get_computer_move(tic_tac_toe);
tic_tac_toe[computer_move] = 'O';
}while(winner != 'X' && winner != 'O');
printf("end of game\n");
}
int get_computer_move(char *tic_tac_toe)
{
int computer_move;
for (computer_move=0; computer_move<9; computer_move++)
if(tic_tac_toe[computer_move] = ' ')
return (computer_move);
}
Shouldn't the for loop cycle thru the array unitl ' ' and then teturn computer_move which in the function will put an 'O' in that spot?
output
Code:
| |
----+---+----
| |
----+---+----
| |
Play with X or play with O
X
Enter what box number that you
would like to place you move in>
4
| |
----+---+----
X | |
----+---+----
| |
Enter what box number that you
would like to place you move in>
6
make another move
O | |
----+---+----
X | | X
----+---+----
| |
Enter what box number that you
would like to place you move in>
It doesn't put an 'O" on the board intil I entered the 6. then it said make another move as if the spot was not empty???? confusing
Code:
char user_move(char *tic_tac_toe)
{
int k;
int i;
printf("Enter what box number that you\n");
printf("would like to place you move in>\n");
scanf("%d", &i);
if (i < 0 || i>9)
printf("invalid move\n");
else if (*tic_tac_toe != ' ')
printf("make another move\n");
return (i);
}
Is it not cycling thur the array correctly?