private JavaList <object> AddNewGameMovement(PlayerMove playerMove, JavaList <object> moves)
        {
            if (playerMove == null)
            {
                return(moves);
            }

            JavaList <object> temp = new JavaList <object>();

            while (!moves.IsEmpty())
            {
                var current = (JavaList <object>)moves.pop_front();
                current.push_front(playerMove);
                temp.push_back(current);
            }

            return(temp);
        }
        private JavaList <object> FindAllLegalSimpleAttackMoves(int currentPiecePos, int currentPlayerColor, int enemyColor)
        {
            var x     = PosToCol(currentPiecePos);
            var y     = PosToBoardLine(currentPiecePos);
            var moves = new JavaList <object>();
            JavaList <object> tempMoves;
            int enemyPos, nextPos;

            var i = currentPlayerColor == WhitePiece ? -1 : 1;

            // Diagonals UPR e DNR
            if (x < 6 && y + i > 0 && y + i < 7)
            {
                enemyPos = ColLineToPos(x + 1, y + i);
                nextPos  = ColLineToPos(x + 2, y + 2 * i);

                if ((_pieces[enemyPos] & ~King) == enemyColor && _pieces[nextPos] == EmptyPiece)
                {
                    tempMoves = FindAllLegalSimpleAttackMoves(nextPos, currentPlayerColor, enemyColor);
                    moves.AppendToTail(AddNewGameMovement(new PlayerMove(currentPiecePos, nextPos), tempMoves));
                }
            }

            // Diagonals DNR e UPL
            if (x > 1 && y + i > 0 && y + i < 7)
            {
                enemyPos = ColLineToPos(x - 1, y + i);
                nextPos  = ColLineToPos(x - 2, y + 2 * i);

                if ((_pieces[enemyPos] & ~King) == enemyColor && _pieces[nextPos] == EmptyPiece)
                {
                    tempMoves = FindAllLegalSimpleAttackMoves(nextPos, currentPlayerColor, enemyColor);
                    moves.AppendToTail(AddNewGameMovement(new PlayerMove(currentPiecePos, nextPos), tempMoves));
                }
            }

            if (moves.IsEmpty())
            {
                moves.push_back(new JavaList <object>());
            }

            return(moves);
        }
 private bool Any(JavaList <object> moves)
 {
     return(!moves.IsEmpty() && !((JavaList <object>)moves.peek_head()).IsEmpty());
 }
        private JavaList <object> FindAllLegalKingDiagonalAttackMoves(JavaList <object> lastPos, int currentPos, int playerColor, int enemyColor, int incX, int incY)
        {
            var x     = PosToCol(currentPos);
            var y     = PosToBoardLine(currentPos);
            var moves = new JavaList <object>();


            var startPos = (int)lastPos.peek_head();

            var i = x + incX;
            var j = y + incY;

            // Find enemy
            while (i > 0 && i < 7 && j > 0 && j < 7 &&
                   (_pieces[ColLineToPos(i, j)] == EmptyPiece || ColLineToPos(i, j) == startPos))
            {
                i += incX;
                j += incY;
            }

            if (i > 0 && i < 7 && j > 0 && j < 7 && (_pieces[ColLineToPos(i, j)] & ~King) == enemyColor &&
                !lastPos.Contains(ColLineToPos(i, j)))
            {
                lastPos.push_back(ColLineToPos(i, j));

                i += incX;
                j += incY;

                var saveI = i;
                var saveJ = j;
                JavaList <object> tempMoves;
                while (i >= 0 && i <= 7 && j >= 0 && j <= 7 &&
                       (_pieces[ColLineToPos(i, j)] == EmptyPiece || ColLineToPos(i, j) == startPos))
                {
                    int dir;

                    if (incX == 1 && incY == 1)
                    {
                        dir = LastDirectionLeftAbove;
                    }
                    else if (incX == -1 && incY == -1)
                    {
                        dir = LastDirectionRightBelow;
                    }
                    else if (incX == -1 && incY == 1)
                    {
                        dir = LastDirectionRightAbove;
                    }
                    else
                    {
                        dir = LastDirectionLeftBelow;
                    }


                    var tempPos = lastPos.Clone();
                    tempMoves = FindAllLegalKingAttackMoves(tempPos, ColLineToPos(i, j), dir, playerColor, enemyColor);

                    if (Any(tempMoves))
                    {
                        moves.AppendToTail(AddNewGameMovement(new PlayerMove(currentPos, ColLineToPos(i, j)), tempMoves));
                    }

                    i += incX;
                    j += incY;
                }

                lastPos.pop_back();

                if (moves.IsEmpty())
                {
                    i = saveI;
                    j = saveJ;

                    while (i >= 0 && i <= 7 && j >= 0 && j <= 7 &&
                           (_pieces[ColLineToPos(i, j)] == EmptyPiece || ColLineToPos(i, j) == startPos))
                    {
                        tempMoves = new JavaList <object>();
                        tempMoves.push_back(new PlayerMove(currentPos, ColLineToPos(i, j)));
                        moves.push_back(tempMoves);

                        i += incX;
                        j += incY;
                    }
                }
            }

            return(moves);
        }