Here is what I have. Everything is working very well except for one detail.
When the last move is made by the user, the computer is initialized to 1 again, and tries to search another random moves, but another random move does not exist, so the program is frozen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
if (computer == 1) //computer = 1, means it's computer's turn
{
bool found = false;
while (found == false )
{
i = rand() % 3;
j = rand() % 3;
if(board[i][j] !='X' && board[i][j] != '0')
{
board[i][j] = '0';
found = true;
computer--; // computer = 0, means it's the player's turn
}
}
}