I have created a tic tac toe program that works in that it allows a player to select a move in a 2d array by selecting the cords, then the computer makes a move.
The program works, but the computer's move is sequential rather then random and will always select the next available space in the array. Now that I have the game working, I want to improve the program into three levels of difficulty:
Easy = Randomly generated move by computer Medium = Randomly generated move by computer that checks to block player and complete line Hard = Selection of optimal move every time through recursion
How I can get the computer to randomly select a set of cords in my array?
(My current basic for loop for computers move)
static void Computermove(char[,] gamegrid, char fin)
{
Console.WriteLine("\nComputer's turn");
Console.ReadKey();
int x = 0;
int y = 0;
for (x = 0; x < 2; x++)
{
for (y = 0; y < 2; y++)
if (gamegrid[x, y] == ' ') break;
if (gamegrid[x, y] == ' ') break;
}
if (x * y == 9)
{
fin = 'X';
}
else
gamegrid[x, y] = 'O';
} // End Computermove