i think i may have taken the long way with this code, but all i need for it to do now is repeat asking the player to enter another symbol...instead of it saying "Tie game" after the first move
Code:
#include<stdio.h>
void enter_symbol(char tic_tac_toe[][3], int player);
void print_board(char tic_tac_toe[][3]);
int has_won(char tic_tac_toe[][3]);
int
main(void)
{
char tic_tac_toe[3][3] =
{{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
int player;
enter_symbol(tic_tac_toe, player);
print_board(tic_tac_toe);
has_won(tic_tac_toe);
return(0);
}
void enter_symbol(char tic_tac_toe[][3], int player)
{
int row, col;
while(1){
printf("Where would u like to enter symbol\n", player);
scanf("%d", &row);
scanf("%d", &col);
if (tic_tac_toe[row][col]==' ')
{
if (player == 1)
tic_tac_toe[row][col]=='x';
else
tic_tac_toe[row][col]='o';
break;
}
else
printf("Position already taken\n");
}
}
void print_board(char tic_tac_toe[][3])
{
printf("\n %c|%c|%c\n -----\n", tic_tac_toe[0][0], tic_tac_toe[0][1], tic_tac_toe[0][2]);
printf(" %c|%c|%c\n -----\n", tic_tac_toe[1][0], tic_tac_toe[1][1], tic_tac_toe[1][2]);
printf(" %c|%c|%c\n", tic_tac_toe[2][0], tic_tac_toe[2][1], tic_tac_toe[2][2]);
}
int has_won(char tic_tac_toe[][3]){
if (tic_tac_toe[0][0] == tic_tac_toe[0][1] &&
tic_tac_toe[0][1] == tic_tac_toe[0][2] &&
tic_tac_toe[0][2] == 'x'){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[0][0] == tic_tac_toe[0][1] &&
tic_tac_toe[0][1] == tic_tac_toe[0][2] &&
tic_tac_toe[0][2] == 'o'){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[1][0] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[1][2] &&
tic_tac_toe[1][2] == 'x'){
printf("%c has won!\n", tic_tac_toe[1][0]);
return (1);
}
else if (tic_tac_toe[1][0] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[1][2] &&
tic_tac_toe[1][2] == 'o'){
printf("%c has won!\n", tic_tac_toe[1][0]);
return (1);
}
else if (tic_tac_toe[2][0] == tic_tac_toe[2][1] &&
tic_tac_toe[2][1] == tic_tac_toe[2][2] &&
tic_tac_toe[2][2] == 'x'){
printf("%c has won!\n", tic_tac_toe[2][0]);
return (1);
}
else if (tic_tac_toe[2][0] == tic_tac_toe[2][1] &&
tic_tac_toe[2][1] == tic_tac_toe[2][2] &&
tic_tac_toe[2][2] == 'o'){
printf("%c has won!\n", tic_tac_toe[2][0]);
return (1);
}
else if (tic_tac_toe[0][0] == tic_tac_toe[1][0] &&
tic_tac_toe[1][0] == tic_tac_toe[2][0] &&
tic_tac_toe[2][0] == 'x'){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[0][0] == tic_tac_toe[1][0] &&
tic_tac_toe[1][0] == tic_tac_toe[2][0] &&
tic_tac_toe[2][0] == 'o'){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[0][1] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][1] &&
tic_tac_toe[2][1] == 'x'){
printf("%c has won!\n", tic_tac_toe[0][1]);
return (1);
}
else if (tic_tac_toe[0][1] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][1] &&
tic_tac_toe[2][1] == 'o'){
printf("%c has won!\n", tic_tac_toe[0][1]);
return (1);
}
else if (tic_tac_toe[0][2] == tic_tac_toe[1][2] &&
tic_tac_toe[1][2] == tic_tac_toe[2][2] &&
tic_tac_toe[2][2] == 'x'){
printf("%c has won!\n", tic_tac_toe[0][2]);
return (1);
}
else if (tic_tac_toe[0][2] == tic_tac_toe[1][2] &&
tic_tac_toe[1][2] == tic_tac_toe[2][2] &&
tic_tac_toe[2][2] == 'o'){
printf("%c has won!\n", tic_tac_toe[0][2]);
return (1);
}
else if (tic_tac_toe[0][0] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][2] &&
tic_tac_toe[2][2] == 'x'){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[0][0] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][2] &&
tic_tac_toe[2][2] == 'o'){
printf("%c has won!\n", tic_tac_toe[0][0]);
return (1);
}
else if (tic_tac_toe[0][2] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][0] &&
tic_tac_toe[2][0] == 'x'){
printf("%c has won!\n", tic_tac_toe[0][2]);
return (1);
}
else if (tic_tac_toe[0][2] == tic_tac_toe[1][1] &&
tic_tac_toe[1][1] == tic_tac_toe[2][0] &&
tic_tac_toe[2][0] == 'o'){
printf("%c has won!\n", tic_tac_toe[0][2]);
return (1);
}
else
printf("Tie Game\n");
return(0);
}