private static void ComputerMove()
{
Random rand = new Random();
int positionIndex = rand.Next(0, freePositions.Count);
Position position = freePositions[positionIndex];
int row = position.X;
int col = position.Y;
if (game[row, col] == '*')
{
game[row, col] = computerCharacter;
freePositions.Remove(position);
Button btn = new Button();
Page page = new Page();
if (HttpContext.Current != null)
{
page = (Page)HttpContext.Current.Handler;
btn = (Button)page.FindControl("Btn" + row + col);
btn.Text = computerCharacter.ToString();
}
if (Win(computerCharacter))
{
Label lbWinner = (Label)page.FindControl("Winner");
lbWinner.Text = "You win!";
lbWinner.Visible = true;
computerScores++;
UpdateScores(page);
return;
}
}
else
{
ComputerMove();
}
}