def _diamond_displace(DS_array, i, j, half_step, roughness):
    """
    defines the midpoint displacement for the diamond step
    :param DS_array:
    :param i:
    :param j:
    :param half_step:
    :param roughness:
    :return:
    """
    ul = DS_array[i - half_step, j - half_step]
    ur = DS_array[i - half_step, j + half_step]
    ll = DS_array[i + half_step, j - half_step]
    lr = DS_array[i + half_step, j + half_step]

    ave = (ul + ur + ll + lr) / 4.0

    rand_val = random.uniform(0, 1)

    return (roughness * rand_val) + (1.0 - roughness) * ave

    defines the midpoint displacement for the diamond step
    :param DS_array:
    :param i:
    :param j:
    :param half_step:
    :param roughness:
    :return:
    
metadrive/third_party/diamond_square/diamond_square.py