Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
 def updatePos(self):
     self.pos = utils.v_add(self.pos, self.vel)
Ejemplo n.º 8
0
 def update_pos(self):
     self.pos = v_add(self.pos, self.vel)