private boolean castlingPossible(final boolean kingside) {
        // First check whether castling is generally allowed in this position.
        boolean result = this.getPos().isCastlingAvailable(kingside,
                this.getColor());
        if (result) {
            // Castling to the specified side is generally allowed, we are good
            // to go on checking.

            // Prepare the file index limit (left or right corner)
            int fileBorder = kingside ? ChessRules.MAX_FILE
                    : ChessRules.MIN_FILE;
            // Decide whether we have to go left (-1) or right (+1)
            int step = kingside ? 1 : -1;
            /*
             * Make sure no piece is blocking the castling and no field between
             * the rook and the king is controlled.
             */
            /*
             * IMPROVE Castling in Fischer Random Chess: there can be the
             * situation where the rook is actually on the wrong side of the
             * king with castling being a legal move. In this case we have to
             * check the fields between the king and his target coordinate as
             * well as the range between the king and the rook. The calculation
             * is not correct in this case at the moment as we would check the
             * whole range from the king to the border because the index moves
             * away from the rook position.
             */
            for (int i = this.getCoord().getFile(); i != this.getPos()
                    .getCastlingRookFile(true, this.getColor())
                    && i != fileBorder; i += step) {
                // Get target coordinate and piece at coordinate
                final ChessCoord tarCoord = Coords.coord(i, this.getCoord()
                        .getRank());
                final Piece tarPiece = this.getPos().getPieceAt(tarCoord);
                // Make sure our target coordinate is not blocked or
                // controlled
                if (this.getPos().isControlled(tarCoord) || (tarPiece != null)) {
                    // It is blocked, so we cannot castle. Break the loop and
                    // return.
                    result = false;
                    break;
                }
            }
        }
        return result;
    }