public Move NextMove()
        {
            Move   a      = new Move(1, 1);
            int    max    = int.MinValue;
            int    alpha  = int.MinValue;
            int    beta   = int.MaxValue;
            Random random = new Random();

            List <Move> moveList = game.GetPossibleMoves(maxMoveSearch, game.isXMove ? 1 : 2);

            for (int i = 0; i < moveList.Count; i++)
            {
                int row = moveList[i].row;
                int col = moveList[i].column;
                game.NextMove(row, col);
                int value = GetScore(row, col, false, alpha, beta) + random.Next(-1, 2);
                game.RemoveMove(row, col);
                if (value > max)
                {
                    max      = value;
                    a.row    = row;
                    a.column = col;
                }
                alpha = Math.Max(alpha, max);
            }
            return(a);
        }
        private void Undo(object sender, RoutedEventArgs e)
        {
            if (undoMoves.Count <= 1)
            {
                return;
            }
            mainGrid.IsEnabled = true;
            Move move = undoMoves.Pop();

            gameLogic.RemoveMove(move.row, move.column);
            buttonBoard[move.row, move.column].Background = Brushes.White;
            buttonBoard[move.row, move.column].Content    = "";
            redoMoves.Push(move);

            move = undoMoves.Pop();
            gameLogic.RemoveMove(move.row, move.column);
            buttonBoard[move.row, move.column].Background = Brushes.White;
            redoMoves.Push(move);
            buttonBoard[move.row, move.column].Content = "";

            if (undoMoves.Count > 0)
            {
                buttonBoard[undoMoves.Peek().row, undoMoves.Peek().column].Background = Brushes.Yellow;
            }
            if (undoMoves.Count <= 1)
            {
                UndoButton.IsEnabled = false;
            }
            RedoButton.IsEnabled = true;
        }
        private void Redo(object sender, RoutedEventArgs e)
        {
            Move move = redoMoves.Pop();

            ApplyMove(move.row, move.column);
            if (redoMoves.Count > 0)
            {
                move = redoMoves.Pop();
                ApplyMove(move.row, move.column);
            }
            buttonBoard[move.row, move.column].Background = Brushes.Yellow;
            if (redoMoves.Count == 0)
            {
                RedoButton.IsEnabled = false;
            }
            UndoButton.IsEnabled = true;
        }
        private void ComputerNextMove()
        {
            Dispatcher.Invoke((Action)(() =>
            {
                MainMenu.IsEnabled = false;
                mainGrid.IsEnabled = false;
            }));
            Move move = computer.NextMove();

            Dispatcher.Invoke((Action)(() =>
            {
                mainGrid.IsEnabled = true;
                ApplyMove(move.row, move.column);
                if (gameLogic.CheckWin(move.row, move.column))
                {
                    MessageBox.Show(Application.Current.MainWindow, "Computer won", "End Game");
                    mainGrid.IsEnabled = false;
                }
                MainMenu.IsEnabled = true;
            }));
        }