private JavaList <object> GetComputerMinimaxMovements(CheckersBoardGameEngine boardGameEngine)
        {
            JavaList <object> bestMove = null;
            int maxValue = int.MinValue;

            var sucessors = boardGameEngine.FindAllLegalMovesForCurrentPlayer();

            while (IsValidMove(sucessors))
            {
                var move      = (JavaList <object>)sucessors.pop_front();
                var nextBoard = boardGameEngine.Clone();

                nextBoard.ApplyMove(move);
                var value = PlayerMinMove(nextBoard, 1, maxValue, int.MaxValue);

                if (value > maxValue)
                {
                    Debug.WriteLine("Max value : " + value + " at depth : 0");
                    maxValue = value;
                    bestMove = move;
                }
            }

            Debug.WriteLine("Move value selected : " + maxValue + " at depth : 0");

            return(bestMove);
        }
        private int PlayerMaxMove(CheckersBoardGameEngine boardGameEngine, int minimaxTreeDepth, int alphaCutOff, int betaCutOff)
        {
            if (TreeCutOffTest(boardGameEngine, minimaxTreeDepth))
            {
                return(GetCurrentPlayerStrength(boardGameEngine));
            }

            Debug.WriteLine("Max node at depth : " + minimaxTreeDepth + " with alpha : " + alphaCutOff +
                            " beta : " + betaCutOff);

            var sucessors = boardGameEngine.FindAllLegalMovesForCurrentPlayer();

            while (IsValidMove(sucessors))
            {
                var move      = (JavaList <object>)sucessors.pop_front();
                var nextBoard = boardGameEngine.Clone();
                nextBoard.ApplyMove(move);
                var value = PlayerMinMove(nextBoard, minimaxTreeDepth + 1, alphaCutOff, betaCutOff);

                if (value > alphaCutOff)
                {
                    alphaCutOff = value;
                    Debug.WriteLine("Max value : " + value + " at depth : " + minimaxTreeDepth);
                }

                if (alphaCutOff > betaCutOff)
                {
                    Debug.WriteLine("Max value with prunning : " + betaCutOff + " at depth : " + minimaxTreeDepth);
                    Debug.WriteLine(sucessors.Count + " sucessors left");
                    return(betaCutOff);
                }
            }

            Debug.WriteLine("Max value selected : " + alphaCutOff + " at depth : " + minimaxTreeDepth);
            return(alphaCutOff);
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            var pos = GetBoardPiecePos(e.X, e.Y);

            if (pos != -1)
            {
                try
                {
                    int piece = _boardGameEngine.GetPieceAtPosition(pos);

                    if (piece != CheckersBoardGameEngine.EmptyPiece &&
                        (((piece == CheckersBoardGameEngine.WhitePiece || piece == CheckersBoardGameEngine.WhiteKingPiece) &&
                          _boardGameEngine.GetCurrentPlayer() == CheckersBoardGameEngine.WhitePiece) ||
                         ((piece == CheckersBoardGameEngine.BlackPiece || piece == CheckersBoardGameEngine.BlackKing) &&
                          _boardGameEngine.GetCurrentPlayer() == CheckersBoardGameEngine.BlackPiece)))
                    {
                        if (_selectedPositions.IsEmpty())
                        {
                            _selectedPositions.push_back(pos);
                        }
                        else
                        {
                            var temp = (int)_selectedPositions.peek_tail();
                            if (temp == pos)
                            {
                                _selectedPositions.pop_back();
                            }
                            else
                            {
                                MessageBox.Show("WAT ARE U TRYIN' TO DO?");
                            }
                        }
                        Invalidate();
                        Update();
                    }
                    else
                    {
                        var isValidMove = false;
                        if (!_selectedPositions.IsEmpty())
                        {
                            CheckersBoardGameEngine tempBoardGameEngine;
                            if (_boardStack.Count == 0)
                            {
                                tempBoardGameEngine = _boardGameEngine.Clone();
                                _boardStack.Push(tempBoardGameEngine);
                            }
                            else
                            {
                                tempBoardGameEngine = (CheckersBoardGameEngine)_boardStack.Peek();
                            }
                            var from = (int)_selectedPositions.peek_tail();
                            if (tempBoardGameEngine.IsValidMove(from, pos))
                            {
                                tempBoardGameEngine = tempBoardGameEngine.Clone();
                                var isAttacking = tempBoardGameEngine.CanCurrentPlayerAttack();
                                tempBoardGameEngine.ApplyMove(from, pos);
                                if (isAttacking && tempBoardGameEngine.CanAttackPosition(pos))
                                {
                                    _selectedPositions.push_back(pos);
                                    _boardStack.Push(tempBoardGameEngine);
                                }
                                else
                                {
                                    _selectedPositions.push_back(pos);
                                    ApplyPlayerMove(_selectedPositions, _boardGameEngine);
                                    _boardStack = new Stack();
                                }
                                isValidMove = true;
                            }
                            else if (from == pos)
                            {
                                _selectedPositions.pop_back();
                                _boardStack.Pop();
                                isValidMove = true;
                            }
                        }
                        if (!isValidMove)
                        {
                            MessageBox.Show("CAN'T DO THAT BRAH");
                        }
                        else
                        {
                            Invalidate();
                            Update();
                        }
                    }
                }
                catch (InvalidBoardCoordinateException bad)
                {
                    Debug.WriteLine(bad.StackTrace);
                    Application.Exit();
                }
            }