void button_click_human(object sender, EventArgs e) { Button button = sender as Button; if (human_Players) //2 player button clicks { if (button.Text != "") { return; } button.Text = X_O_display_button.Text; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (buttons[i, j].Text != "") { evaluation_Board[i, j] = buttons[i, j].Text; } } } switchPlayer(); if (gameover == true) { gameover = false; } return; } //human clicks versus AI if (X_O_display_button.Text == human) { if (button.Text == "") { button.Text = human; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (buttons[i, j].Text == human && evaluation_Board[i, j] == "") { evaluation_Board[i, j] = human; } } } switchPlayer(); if (ai_Player && X_O_display_button.Text == ai) { Minimax ai_minimax = new Minimax(); int[] ai_move = ai_minimax.Ai_bestMove(evaluation_Board, buttons, X_O_display_button.Text); evaluation_Board[ai_move[0], ai_move[1]] = ai; buttons[ai_move[0], ai_move[1]].Text = ai; switchPlayer(); } } } }
private void Ai_RandomMove() { int random_Num1 = random_Move.Next(0, 3); //random first move after activation or reset int random_Num2 = random_Move.Next(0, 3); foreach (var button in buttons) { if (button.Text != "") { Minimax ai_Minimax = new Minimax(); int[] ai_move = ai_Minimax.Ai_bestMove(evaluation_Board, buttons, X_O_display_button.Text); evaluation_Board[ai_move[0], ai_move[1]] = ai; buttons[ai_move[0], ai_move[1]].Text = ai; switchPlayer(); return; } } buttons[random_Num1, random_Num2].Text = ai; evaluation_Board[random_Num1, random_Num2] = ai; switchPlayer(); }