def compute_obstacle_dodge(myAgent): compute_vel = (0, 0) neighbors_cnt = 0 for obs in shared.obstacle_array: if obs.distance_from(myAgent) < OBSTACLE_DOGDGE_RADIUS: temp_vel = v_sub(myAgent.pos, obs.pos) temp_vel = convert_to_unit_vector(temp_vel) compute_vel = v_add(compute_vel, v_div(temp_vel, myAgent.distance_from(obs))) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel return v_div(compute_vel, neighbors_cnt)
def computeObscatleDodge(myAgent): compute_vel = (0, 0) neighbors_cnt = 0 for obs in obstacle_array: if obs.distanceFrom(myAgent) < OBSTACLE_DOGDGE_RADIUS: temp_vel = v_sub(myAgent.pos, obs.pos) temp_vel = utils.getUnitVector(temp_vel) compute_vel = v_add(compute_vel, v_div(temp_vel, myAgent.distanceFrom(obs))) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel return v_div(compute_vel, neighbors_cnt)
def compute_seperation(myAgent, t): compute_vel = (0, 0) neighbors_cnt = 0 for i in range(len(shared.agent_array)): agent = shared.agent_array[i] if agent != myAgent and myAgent.distance_from( agent) < SEPERATION_RADIUS and t == i % 2: temp_vel = v_sub(myAgent.pos, agent.pos) temp_vel = convert_to_unit_vector(temp_vel) compute_vel = v_add(compute_vel, v_div(temp_vel, myAgent.distance_from(agent))) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel return v_div(compute_vel, neighbors_cnt)
def computeSeperation(myAgent, t): compute_vel = (0, 0) neighbors_cnt = 0 for i in xrange(0, len(agent_array)): agent = agent_array[i] if agent != myAgent and myAgent.distanceFrom( agent) < SEPERATION_RADIUS and t == i % 2: temp_vel = v_sub(myAgent.pos, agent.pos) temp_vel = utils.getUnitVector(temp_vel) compute_vel = v_add(compute_vel, v_div(temp_vel, myAgent.distanceFrom(agent))) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel return v_div(compute_vel, neighbors_cnt)
def compute_cohesion(myAgent, t): compute_vel = (0, 0) neighbors_cnt = 0 for i in range(len(shared.agent_array)): agent = shared.agent_array[i] if agent != myAgent and myAgent.distance_from( agent) < COHESION_RADIUS and t == i % 2: compute_vel = v_sub(agent.pos, myAgent.pos) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel compute_vel = v_div(compute_vel, neighbors_cnt) return limit(compute_vel, 0.05)
def compute_alignment(myAgent, t): compute_vel = (0, 0) neighbors_cnt = 0 for i in range(len(shared.agent_array)): agent = shared.agent_array[i] if agent != myAgent and myAgent.distance_from( agent) < ALIGNMENT_RADIUS and t == i % 2: compute_vel = v_add(compute_vel, agent.vel) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel compute_vel = v_div(compute_vel, neighbors_cnt) return limit(compute_vel, 0.05)
def computeCohesion(myAgent, t): compute_vel = (0, 0) neighbors_cnt = 0 for i in xrange(0, len(agent_array)): agent = agent_array[i] if agent != myAgent and myAgent.distanceFrom( agent) < COHESION_RADIUS and t == i % 2: compute_vel = v_sub(agent.pos, myAgent.pos) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel compute_vel = v_div(compute_vel, neighbors_cnt) return utils.limit(compute_vel, 0.05)
def computeAlignment(myAgent, t): compute_vel = (0, 0) neighbors_cnt = 0 for i in xrange(0, len(agent_array)): agent = agent_array[i] if agent != myAgent and myAgent.distanceFrom( agent) < ALIGNMENT_RADIUS and t == i % 2: compute_vel = v_add(compute_vel, agent.vel) neighbors_cnt += 1 if neighbors_cnt == 0: return compute_vel compute_vel = v_div(compute_vel, neighbors_cnt) return utils.limit(compute_vel, 0.05)