Beispiel #1
0
    def _get_sensor_at(self, actors, radians, length, reach):
        """
		Compute the strength of an Actor sensor at some location away from the
		Agent at radians with distance out length and max sensing reach. Return
		tuple (sense, closest actor)
		"""
        # Compute sensor location
        length += self.radius
        sensor_x = self.x + math.cos(self.radians + radians) * length
        sensor_y = self.y + math.sin(self.radians + radians) * length
        pos = (sensor_x, sensor_y)
        # Compute sensor value
        sense = 0
        reach_sqr = reach**2
        closest = None
        closest_dist = 0
        for actor in actors:
            if actor is self:
                continue
            dist_sqr = util.dist_sqr(pos, actor.get_pos())
            if dist_sqr > reach_sqr:
                continue
            dist = math.sqrt(dist_sqr)
            if closest is None or dist < closest_dist:
                closest = actor
                closest_dist = dist
            ratio = (reach - dist) / float(reach)
            sense += ratio
        return (sense, closest)
	def _get_sensor_at(self, actors, radians, length, reach):
		"""
		Compute the strength of an Actor sensor at some location away from the
		Agent at radians with distance out length and max sensing reach. Return
		tuple (sense, closest actor)
		"""
		# Compute sensor location
		length += self.radius
		sensor_x = self.x + math.cos(self.radians + radians) * length
		sensor_y = self.y + math.sin(self.radians + radians) * length
		pos = (sensor_x, sensor_y)
		# Compute sensor value
		sense = 0
		reach_sqr = reach ** 2
		closest = None
		closest_dist = 0
		for actor in actors:
			if actor is self:
				continue
			dist_sqr = util.dist_sqr(pos, actor.get_pos())
			if dist_sqr > reach_sqr:
				continue
			dist = math.sqrt(dist_sqr)
			if closest is None or dist < closest_dist:
				closest = actor
				closest_dist = dist
			ratio = (reach - dist) / float(reach)
			sense += ratio
		return (sense, closest)
Beispiel #3
0
    def _update_attack(self, world_agents):
        """
		Allow Agents to attack other Agents and store the result of the
		interaction
		"""
        # If we've interacted with an Agent this tick then don't do so again
        if self.interact_agent is not None:
            return
        attack_dist_sqr = (self.radius * 2)**2
        for other in world_agents:
            # Can we interact with this Agent?
            if other is self or other.interact_agent is not None:
                continue
            dist_sqr = util.dist_sqr(self.get_pos(), other.get_pos())
            if dist_sqr > attack_dist_sqr:
                continue
            # Execute interaction between self and other
            self.interact_agent = other
            other.interact_agent = self
            if other is not self.prev_interact_agent:
                self.interact_attacked = self._will_attack()
                other.interact_attacked = other._will_attack()
            break
        if self.interact_agent is None:
            self.interact_attacked = False
	def _update_attack(self, world_agents):
		"""
		Allow Agents to attack other Agents and store the result of the
		interaction
		"""
		# If we've interacted with an Agent this tick then don't do so again
		if self.interact_agent is not None:
			return
		attack_dist_sqr = (self.radius * 2) ** 2
		for other in world_agents:
			# Can we interact with this Agent?
			if other is self or other.interact_agent is not None:
				continue
			dist_sqr = util.dist_sqr(self.get_pos(), other.get_pos())
			if dist_sqr > attack_dist_sqr:
				continue
			# Execute interaction between self and other
			self.interact_agent = other
			other.interact_agent = self
			if other is not self.prev_interact_agent:
				self.interact_attacked = self._will_attack()
				other.interact_attacked = other._will_attack()
			break
		if self.interact_agent is None:
			self.interact_attacked = False