import math


def ddpg_state_2_spike_value_state(state, spike_state_num,
                                   goal_dir_range=math.pi, linear_spd_range=0.5, angular_spd_range=2.0):
    """
    Transform DDPG state to Spike Value State for SNN
    :param state: single ddpg state
    :param spike_state_num: number of spike states
    :param goal_dir_range: range of goal dir
    :param linear_spd_range: range of linear spd
    :param angular_spd_range: range of angular spd
    :return: spike_state_value
    """
    spike_state_value = [0 for _ in range(spike_state_num)]
    if state[0] > 0:
        spike_state_value[0] = state[0] / goal_dir_range
        spike_state_value[1] = 0
    else:
        spike_state_value[0] = 0
        spike_state_value[1] = abs(state[0]) / goal_dir_range
    spike_state_value[2] = state[1]
    spike_state_value[3] = state[2] / linear_spd_range
    if state[3] > 0:
        spike_state_value[4] = state[3] / angular_spd_range
        spike_state_value[5] = 0
    else:
        spike_state_value[4] = 0
        spike_state_value[5] = abs(state[3]) / angular_spd_range
    spike_state_value[6:] = state[4:]
    return spike_state_value