I have a tic tac toe program. The board is stored in a two dimensional character array board[3][3]. Here is a function that is supposed to check if the player specified in the player argument wins. It doesn't work. Ideas?
Code:
bool is_threeinrow(char player, char board[3][3])
{
bool done = 0;
for (int x = 0; x < 3; x++)
{
if (board[x][0] == board[x][1] == board[x][2] == player)
{
return 1;
done = 1;
}
}
for (int y = 0; y < 3; y++)
{
if (board[0][y] == board[1][y] == board[2][y] == player)
{
return 1;
done = 1;
}
}
if (board[0][0] == board[1][1] == board[2][2] == player)
{
return 1;
done = 1;
}
if (board[0][2] == board[1][1] == board[2][0] == player)
{
return 1;
done = 1;
}
if (done == 0)
{
return 0;
}
}