def adjust_displacement(n_trials, n_accept, max_displacement):
    """Adjusts the maximum value allowed for a displacement move.
    
    This function adjusts the maximum displacement to obtain a suitable acceptance \
    of trial moves. That is, when the acceptance is too high, the maximum \
    displacement is increased and when the acceptance is too low, the \
    maximum displacement is decreased.
    
    Parameters
    ----------
    n_trials : integer
        Number of trials that have been performed when the funtction is called.
    n_accept: integer
        Number of current accepted trials when the function is called.
    max_displacement: float
        Maximum displacement allowed for any step in the simulation.
    
    Returns
    -------
    n_trials: int
        Number of trials. Updated to zero if maximum displacement is updated.
    n_accept: int
        Number of trials. Updated to zero if maximum displacement is updated.
    max_displacemnt: float
        Maximum displacement allowed for any step in the simulation. 
    """
    acc_rate = float(n_accept)/float(n_trials)
    if (acc_rate < 0.38):
        max_displacement *= 0.8
    
    elif (acc_rate > 0.42):
        max_displacement *= 1.2

    n_trials = 0
    n_accept = 0
    return max_displacement, n_trials, n_accept