def uav_update(time_counter: int, p: parameter.Parameter,
               uav_swarm: uav.Uav_Swarm, target_swarm: target.Target_Swarm):
    p.S_a_p = p.S_a
    p.S_r_p = p.S_r
    p.V = np.zeros([p.nx, p.ny], dtype=float)
    for i in range(p.nu):
        [pos_nox_x, pos_nox_y] = uav_swarm[i].pos_now
        p.detect_map[pos_nox_x, pos_nox_y] = 1
        p.V[pos_nox_x, pos_nox_y] = 1
        # 更新单无人机信息
        # uav_swarm[i] = uav_single_step(time_counter, p, uav_swarm[i], target_swarm)
        uav_swarm[i].pos_past = uav_swarm[i].pos_now
        uav_swarm[i].path[time_counter] = uav_swarm[i].pos_now
        # 改变位置
        uav_swarm[i].pos_now = uav_swarm[i].way_global[0]  # 更新当前位置
        # 更新概率图 arm, target_swarm)
        [pos_nox_x, pos_nox_y] = uav_swarm[i].pos_now
        t_map_num = p.t_map[pos_nox_x, pos_nox_y]
        if t_map_num != -1:  # 遇到目标
            target_swarm[t_map_num].found_flag = True
        for j in range(p.nt):
            target_swarm[j].p_map[pos_nox_x, pos_nox_y] = 0
    # 除法还未加入对全0的考虑,或许也可以不修改概率地图
    p.found_counter = 0
    for i in range(p.nt):
        p_map_sum = np.sum(target_swarm[i].p_map)
        if not target_swarm[i].found_flag and p_map_sum != 0:
            target_swarm[i].p_map = target_swarm[i].p_map / p_map_sum
        elif target_swarm[i].found_flag:
            p.found_counter += target_swarm[i].found_flag
def uav_swarm_step(time_counter: int, p: parameter.Parameter,
                   uav_swarm: uav.Uav_Swarm,
                   target_swarm: target.Target_Swarm):
    # 求下一步策略
    p.S_a_p = p.S_a
    p.S_a = cal_S_a(p)
    p.S_r_p = p.S_r
    p.S_r = cal_S_r(p)
    search_way_local(p, uav_swarm, target_swarm)
    for i in range(p.nu):
        search_way_global(time_counter, p, uav_swarm[i], uav_swarm,
                          target_swarm)
    optimal.interation(time_counter, uav_swarm, target_swarm, p)