Exemple #1
0
    def hide(self, hunter_position, delta):

        to_hunter = self.position - hunter_position
        if to_hunter.length() > self.panic_radius:
            return self.weighted_sum(delta)

        best_hiding_spot = None
        best_hiding_distance = None

        for object_position in self.world.objects:

            hiding_spot = self.get_hiding_spot(
                hunter_position, Vector2D(object_position.x,
                                          object_position.y))
            hiding_distance = self.position.distance_sq(hiding_spot)
            if not best_hiding_spot or hiding_distance < best_hiding_distance:
                best_hiding_spot = hiding_spot
                best_hiding_distance = hiding_distance

            egi.red_pen()
            egi.cross(hiding_spot, 10)

        if best_hiding_spot:
            return self.arrive(best_hiding_spot)

        return self.flee(hunter_position)
Exemple #2
0
    def render(self):
        egi.set_pen_color(name=self.color)
        points = self.world.transform_points(self.vehicle_shape, self.position,
                                             self.heading, self.side,
                                             Vector2D(self.scale, self.scale))
        egi.closed_shape(points)

        #egi.red_pen()
        #egi.circle(self.position, self.panic_radius)

        if self.mode == 'Wander1':  # Disabled for now

            local_position = Vector2D(self.wander_distance, 0)
            world_position = self.world.transform_point(
                local_position, self.position, self.heading, self.side)
            egi.green_pen()
            egi.circle(world_position, self.wander_radius)

            local_position += self.wander_target
            world_position = self.world.transform_point(
                local_position, self.position, self.heading, self.side)
            egi.red_pen()
            egi.circle(world_position, 5)

        elif self.mode == 'Follow path':
            self.path.render()
Exemple #3
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        # draw the ship
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)
        # draw it!
        egi.closed_shape(pts)

        # draw the border
        egi.blue_pen()
        egi.closed_shape(self.walls, False)
        egi.red_pen()
        egi.line_with_arrow(self.pos, self.pos + self.vel * 0.5, 5)    #feeler1

        # add some handy debug drawing info lines - force and velocity
        if self.show_info:
            s = 0.5 # <-- scaling factor
            # force
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.force * s, 5)
            # velocity
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change
            egi.white_pen()
            egi.line_with_arrow(self.pos+self.vel * s, self.pos+ (self.force+self.vel) * s, 5)
            egi.line_with_arrow(self.pos, self.pos+ (self.force+self.vel) * s, 5)
Exemple #4
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        # draw the ship
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)
        # draw it!
        egi.closed_shape(pts)

        # draw the border
        egi.blue_pen()
        egi.closed_shape(self.walls, False)
        egi.red_pen()
        egi.line_with_arrow(self.pos, self.pos + self.vel * 0.5, 5)  #feeler1

        # add some handy debug drawing info lines - force and velocity
        if self.show_info:
            s = 0.5  # <-- scaling factor
            # force
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.force * s, 5)
            # velocity
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change
            egi.white_pen()
            egi.line_with_arrow(self.pos + self.vel * s,
                                self.pos + (self.force + self.vel) * s, 5)
            egi.line_with_arrow(self.pos,
                                self.pos + (self.force + self.vel) * s, 5)
Exemple #5
0
    def render(self):
        if self.hunter is not None:
            self.hunter.render()
        for agent in self.agents:
            agent.render()
        for hide in self.hideObjects:
            hide.render()
        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.showinfo:
            # added additional info to info text in regards to emergant group behaviour ##2018-04-16
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
            infotext = ': '.join(('Cohesion Modifier', str(self.cohesion)))
            egi.white_pen()
            egi.text_at_pos(0, 12, infotext)
            infotext = ': '.join(('Seperation Modifier', str(self.seperation)))
            egi.white_pen()
            egi.text_at_pos(0, 24, infotext)
            infotext = ': '.join(('Alignment Modifier', str(self.alignment)))
            egi.white_pen()
            egi.text_at_pos(0, 36, infotext)
            infotext = ': '.join(('Radius', str(self.radius)))
            egi.white_pen()
            egi.text_at_pos(0, 48, infotext)
    def render(self, color=None):
        # graphics,
        ''' Draw the triangle agent with color'''
        # self.graphics = Graphics()
        # draw the path if it exists and the mode is follow.
        if self.mode == 'follow_path':
            self.path.render()
            pass
        # draw the ship.
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)
        # draw it!
        egi.closed_shape(pts)

        # add some handy debug drawing info lines - force and velocity.
        if self.show_info:
            s = 0.5  # <-- scaling factor.
            # force.
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.force * s, 5)
            # velocity.
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change.
            egi.white_pen()
            egi.line_with_arrow(self.pos + self.vel * s,
                                self.pos + (self.force + self.vel) * s, 5)
            egi.line_with_arrow(self.pos,
                                self.pos + (self.force + self.vel) * s, 5)
Exemple #7
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)

        if (self.mode == 'hunt'):
            wnd_pos = Vector2D(self.wander_dist, 0)
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            egi.green_pen()
            egi.circle(wld_pos, self.wander_radius)
            egi.red_pen()
            wnd_pos = (self.wander_target + Vector2D(self.wander_dist, 0))
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            egi.circle(wld_pos, 3)
        # draw it!
        egi.closed_shape(pts)

        if self.show_info:
            s = 0.5  # <-- scaling factor
            # force
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.force * s, 5)
            # velocity
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change
            egi.white_pen()
            egi.line_with_arrow(self.pos + self.vel * s,
                                self.pos + (self.force + self.vel) * s, 5)
            egi.line_with_arrow(self.pos,
                                self.pos + (self.force + self.vel) * s, 5)
Exemple #8
0
    def render(self):
        for agent in self.agents:
            agent.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        for obstacle in self.obstacle:
            obstacle.render()

        if self.show_info:
            infotext = ': '.join(('Radius', str(self.radius)))
            egi.white_pen()
            egi.text_at_pos(0, 487, infotext)
            infotext = ': '.join(('Cohesion', str(self.cohesion)))
            egi.white_pen()
            egi.text_at_pos(0, 448, infotext)
            infotext = ': '.join(('Seperation', str(self.separation)))
            egi.white_pen()
            egi.text_at_pos(0, 461, infotext)
            infotext = ': '.join(('Alignment', str(self.alignment)))
            egi.white_pen()
            egi.text_at_pos(0, 474, infotext)
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
Exemple #9
0
	def hide(self, hunters, obstacles, closest=True):

		hidingPlaces = []

		for hunter in hunters:
			for obstacle in obstacles:
				dir = hunter.pos.distanceTo(obstacle.pos).get_normalised()
				length = hunter.pos.distance(obstacle.pos) + obstacle.boundingRadius + self.boundingRadius
				
				# Calculate the position of the hiding spot
				place = hunter.pos + dir * length

				# If this spot isn't inside any other obstacles, then add it to the list
				if(not True in [ob.containsPoint(place) for ob in obstacles]):
					hidingPlaces.append(place)

		self.hidingPlaces = hidingPlaces # store for debugging purposes

		# Find the 'best' hiding place from our list
		self.bestPlace = self.bestHidingPlaceFromHunter(hidingPlaces=hidingPlaces, hunter=hunters[0], closest=closest)

		# print 'bestPlace', self.bestPlace

		# seek = self.seek(self.bestPlace)
		arrive = self.arrive(self.bestPlace, 'fast')

		if(self.chosenOne and self.world.drawHidingSpots):
			for place in self.hidingPlaces or []:
				egi.red_pen()
				if(place == self.bestPlace): egi.green_pen()
				egi.cross(place, 10)

		return arrive
Exemple #10
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)

        # draw wander info
        if self.mode == 'wander':
            # calculate the center of the wander circle in front of the agent
            wnd_pos = Vector2D(self.wander_dist, 0)
            wnd_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            # draw wander circle
            egi.green_pen()
            egi.circle(wnd_pos, self.wander_radius)
            # draw the wander target (little cirlce on the big circle)
            egi.red_pen()
            wnd_pos = (self.wander_target + Vector2D(self.wander_dist, 0))
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            egi.circle(wld_pos, 3)

        if self.mode == 'follow_path':
            self.path.render()

        # draw it!
        egi.closed_shape(pts)
Exemple #11
0
	def render(self):

		self.super.render()

		# Draw our sight radius
		if(self.chosenOne and self.world.drawHidingSpots):
			egi.red_pen()
			egi.circle(self.sightCircle['pos'], self.sightCircle['radius'])
Exemple #12
0
    def render(self):

        self.super.render()

        # Draw our sight radius
        if (self.chosenOne and self.world.drawHidingSpots):
            egi.red_pen()
            egi.circle(self.sightCircle['pos'], self.sightCircle['radius'])
Exemple #13
0
	def hidingSteer(self, delta, closest=True):

		hiding = self.hide(hunters=self.world.hunters, obstacles=self.world.obstacles, closest=closest)

		if(self.chosenOne and self.world.drawDebug):
			egi.red_pen()
			egi.line_by_pos(self.pos, self.pos + hiding * 5)

		return hiding
Exemple #14
0
	def wallSteer(self, delta):

		wallForce = self.wallAvoidance(self.world.tank.getWalls('vertical')) * 2

		if(self.chosenOne and self.world.drawDebug):
			egi.red_pen()
			egi.line_by_pos(self.pos, self.pos + wallForce * 5)

		return wallForce
Exemple #15
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        # draw the path if it exists and the mode is follow
        if self.mode == 'follow_path':
            self.path.render()

        # draw the ship
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)
        # draw it!
        egi.closed_shape(pts)

        # draw wander info?
        if self.mode == 'wander':
            ## ...
            pass

        #draw neighbour radius
        cntr_pos = Vector2D()
        cntrwld_pos = self.world.transform_point(cntr_pos, self.pos,
                                                 self.heading, self.side)

        egi.white_pen()
        egi.circle(cntrwld_pos, self.neighbour_radius)

        # add some handy debug drawing info lines - force and velocity
        if self.show_info:
            s = 0.5  # <-- scaling factor
            # force
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.force * s, 5)
            # velocity
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change
            egi.white_pen()
            egi.line_with_arrow(self.pos + self.vel * s,
                                self.pos + (self.force + self.vel) * s, 5)
            egi.line_with_arrow(self.pos,
                                self.pos + (self.force + self.vel) * s, 5)

        if (self.mode == 'wander'):
            #calculate center of the wander circle in front of agent
            wnd_pos = Vector2D(self.wander_dist, 0)
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            #draw the wander circle
            egi.green_pen()
            egi.circle(wld_pos, self.wander_radius)
            #draw the wander target (little circle on big circle)
            egi.red_pen()
            wnd_pos = (self.wander_target + Vector2D(self.wander_dist, 0))
            wnd_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            egi.circle(wld_pos, 3)
Exemple #16
0
 def draw(self):
     if self.mode == "Agent":
         if self.fsm:
             self.fsm.update()
             self.fsm.draw()
         egi.blue_pen()
     else:
         egi.red_pen()
     egi.set_stroke(4)
     egi.circle(Point2D(self.my_x, self.my_y), 10)
Exemple #17
0
    def wallSteer(self, delta):

        wallForce = self.wallAvoidance(
            self.world.tank.getWalls('vertical')) * 2

        if (self.chosenOne and self.world.drawDebug):
            egi.red_pen()
            egi.line_by_pos(self.pos, self.pos + wallForce * 5)

        return wallForce
Exemple #18
0
    def render(self):
        for projectile in self.projectiles:
            projectile.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target.pos, self.target.size)

        if self.attacker:
            self.attacker.render()
Exemple #19
0
    def render(self, color=None):
        egi.blue_pen()
        egi.cross(self.predictedtarget, 5)
        ''' Draw the triangle agent with color'''
        # draw the path if it exists and the mode is follow
        if self.mode == 'follow_path':
            ## ...
            self.path.render()
            pass

        if self.is_hit:
            self.visible = False

        # draw the ship
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)

        # draw it!
        egi.closed_shape(pts)

        self.is_hit = False

        # draw wander info?
        if self.mode == 'wander':
            wnd_pos = Vector2D(self.wander_dist, 0)
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            # draw the wander circle
            egi.green_pen()
            egi.circle(wld_pos, self.wander_radius)
            # draw the wander target (little circle on the big circle)
            egi.red_pen()
            wnd_pos = (self.wander_target + Vector2D(self.wander_dist, 0))
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            egi.circle(wld_pos, 3)
            ## ...
            pass

        # add some handy debug drawing info lines - force and velocity
        if self.show_info:
            s = 0.5  # <-- scaling factor
            # force
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.force * s, 5)
            # velocity
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change
            egi.white_pen()
            egi.line_with_arrow(self.pos + self.vel * s,
                                self.pos + (self.force + self.vel) * s, 5)
            egi.line_with_arrow(self.pos,
                                self.pos + (self.force + self.vel) * s, 5)
Exemple #20
0
	def pursuit(self, target): 

		

		projected = self.projectedPosition(target)

		if(self.world.drawDebug and self.chosenOne):
			egi.red_pen()
			egi.cross(projected, 10)

		return self.seek(projected)
Exemple #21
0
    def hidingSteer(self, delta, closest=True):

        hiding = self.hide(hunters=self.world.hunters,
                           obstacles=self.world.obstacles,
                           closest=closest)

        if (self.chosenOne and self.world.drawDebug):
            egi.red_pen()
            egi.line_by_pos(self.pos, self.pos + hiding * 5)

        return hiding
Exemple #22
0
    def render(self):
        for agent in self.agents:
            agent.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.showinfo:
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
Exemple #23
0
    def render(self, color = None):
        if self.show_info:
            s = 0.5 # <-- scaling factor
            # force
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.acceleration * s, 5)
            # velocity
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change
            egi.white_pen()
            egi.line_with_arrow(self.pos+self.vel * s, self.pos+ (self.acceleration+self.vel) * s, 5)
            egi.line_with_arrow(self.pos, self.pos+ (self.acceleration+self.vel) * s, 5)

        return super().render(color)
Exemple #24
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        # draw the path if it exists and the mode is follow
        if self.mode == 'follow_path':
            ## ...
            self.path.render()
            pass
        if self.ishit:
            egi.red_pen()
        else:
            egi.blue_pen()
        # draw the ship

        egi.circle(self.pos, 20, True)

        self.ishit = False
Exemple #25
0
    def render(self):
        self.hunter.render()
        self.cannon.render()

        for projectile in self.projectiles:
            projectile.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.showinfo:
            infotext = ', '.join(
                set(projectile.mode for projectile in self.projectiles))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
Exemple #26
0
    def render(self):
        for agent in self.agents:
            agent.render()

        self.hunter.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.showinfo:
            controltext = 'Cohesion [Q/W]\nSeparation [T\Y]\nAlignment [K/L]\nNeighbourhood Radius [N/M]'
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 15, controltext)
            egi.text_at_pos(0, 0, infotext)
Exemple #27
0
    def render(self):
        for agent in self.agents:
            agent.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.show_info:
            infotext = \
                'Mode: ' + self.agents[0].mode + \
                ', Local group radius: ' + str(round(self.agents[0].local_group_radius, 2)) + \
                ', Separation: ' + str(round(self.agents[0].separation_multiplier, 2)) + \
                ', Cohesion: '   + str(round(self.agents[0].cohesion_multiplier, 2)) + \
                ', Alignment: '  + str(round(self.agents[0].alignment_multiplier, 2))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
Exemple #28
0
    def render(self):
        for agent in self.agents:
            agent.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.show_info:
            text = 'Mode: ' + self.agents[0].mode + \
            '\nWander: ' + str(round(self.agents[0].wanderAmount, 2)) + \
            '\nSeparation: ' + str(round(self.agents[0].separationAmount, 2)) + \
            '\nCohesion: ' + str(round(self.agents[0].cohesionAmount, 2)) + \
            '\nAlignment ' + str(round(self.agents[0].alignmentAmount, 2))

            egi.white_pen()
            egi.text_at_pos(10, 420, text)
Exemple #29
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        # draw the path if it exists and the mode is follow
        if self.mode == 'follow_path':
            ## ...
            self.path.render()

        # draw the ship
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,
                                          self.heading, self.side, self.scale)
        # draw it!
        egi.closed_shape(pts)

        # draw wander info?
        if self.mode == 'wander':
            ## ...
            wnd_pos = Vector2D(self.wander_dist, 0)
            wld_pos = self.world.transform_point(wnd_pos, self.pos, self.heading, self.side)

            egi.green_pen()
            egi.circle(wld_pos, self.wander_radius)

            egi.red_pen()
            wnd_pos = (self.wander_target + Vector2D(self.wander_dist, 0))
            wld_pos = self.world.transform_point(wnd_pos, self.pos, self.heading, self.side)
            egi.circle(wld_pos, 3)

        if self.mode == 'hide':
            egi.green_pen()
            egi.cross(self.besthidingspot, 5)

        # add some handy debug drawing info lines - force and velocity
        if self.show_info:
            s = 0.5 # <-- scaling factor
            # force
            egi.red_pen()
            egi.line_with_arrow(self.pos, self.pos + self.force * s, 5)
            # velocity
            egi.grey_pen()
            egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5)
            # net (desired) change
            egi.white_pen()
            egi.line_with_arrow(self.pos+self.vel * s, self.pos+ (self.force+self.vel) * s, 5)
            egi.line_with_arrow(self.pos, self.pos+ (self.force+self.vel) * s, 5)
Exemple #30
0
    def render(self):
        for agent in self.agents:
            agent.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.hunter:
            agent.render('GREEN')

        if self.show_info:
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            infotext += ', '
            infotext += ' , '.join(
                set(agent.attribute for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
Exemple #31
0
	def survivalSteer(self, delta):
		avoidHunters, hunterDist = self.avoidHuntersSteer(delta)
		# avoidHunters *
		hideForce =  self.hidingSteer(delta) / (hunterDist / 20000) / (avoidHunters.length() / 100)

		steer = avoidHunters + hideForce 

		if(self.chosenOne and self.world.drawHidingSpots):
			egi.green_pen()
			egi.line_by_pos(self.pos, self.pos + avoidHunters * 5)
			# print 'avoidHunters', avoidHunters
			egi.red_pen()
			egi.line_by_pos(self.pos, self.pos + hideForce * 5)
			# print 'hideForce', hideForce
			egi.orange_pen()
			# egi.line_by_pos(self.pos, self.pos + steer * 5)
			

		return steer
Exemple #32
0
    def render(self):
        for agent in self.agents:
            agent.render()

        for hunter in self.hunters:
            hunter.render()

        for obstacle in self.obstacles:
            obstacle.render()


        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)

        if self.show_info:
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
Exemple #33
0
    def survivalSteer(self, delta):
        avoidHunters, hunterDist = self.avoidHuntersSteer(delta)
        # avoidHunters *
        hideForce = self.hidingSteer(delta) / (hunterDist / 20000) / (
            avoidHunters.length() / 100)

        steer = avoidHunters + hideForce

        if (self.chosenOne and self.world.drawHidingSpots):
            egi.green_pen()
            egi.line_by_pos(self.pos, self.pos + avoidHunters * 5)
            # print 'avoidHunters', avoidHunters
            egi.red_pen()
            egi.line_by_pos(self.pos, self.pos + hideForce * 5)
            # print 'hideForce', hideForce
            egi.orange_pen()
            # egi.line_by_pos(self.pos, self.pos + steer * 5)

        return steer
    def update(self, delta):
        ''' update vehicle position and orientation '''
        # calculate and set self.force to be applied
        # force = self.calculate()
        # <-- delta needed for wander (delta)
        ## limit force? <-- for wander
        force = self.calculate(delta)
        force.truncate(self.max_force)
        # <-- new force limiting code
        # determine the new accelteration
        self.accel = force / self.mass
        # not needed if mass = 1.0
        # new velocity
        self.vel += self.accel * delta
        # check for limits of new velocity
        self.vel.truncate(self.max_speed)
        # update position
        self.pos += self.vel * delta
        # update heading is non-zero velocity (moving)
        if self.vel.length_sq() > 0.00000001:
            self.heading = self.vel.get_normalised()
            self.side = self.heading.perp()
        # treat world as continuous space - wrap new position if needed
        self.world.wrap_around(self.pos)

        ### added wander to render function. ###
        # draw wander info?
        if self.mode == 'wander':
            # calculate the center of the wander circle in front of the agent
            wnd_pos = Vector2D(self.wander_dist, 0)
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            # draw the wander circle
            egi.green_pen()
            egi.circle(wld_pos, self.wander_radius)
            # draw the wander target (little circle on the big circle)
            egi.red_pen()
            wnd_pos = (self.wander_target + Vector2D(self.wander_dist, 0))
            wld_pos = self.world.transform_point(wnd_pos, self.pos,
                                                 self.heading, self.side)
            egi.circle(wld_pos, 3)
            pass
Exemple #35
0
	def render(self,color=None):

		self.calculateRenderPosition()
		
		if(color is None):
			color = self.color

		''' Draw the triangle agent with color'''
		self.drawBody(color)

		
		if(not self.world.drawDebug or not self.chosenOne):
			return
		
		# Debug stuff to draw for all agents
		

		# if not self.chosenOne:
		# 	return
		# Debug stuff to only draw for one agent

		egi.circle(self.pos, self.boundingRadius)

		egi.orange_pen()
		egi.circle(self.pos, self.boundingRadius)

		egi.grey_pen()
		wnd_pos = Vector2D(0, 0)
		
		

		# Draw wander info
		# calculate the center of the wander circle
		wnd_pos = Vector2D(self.wanderDistance, 0)
		wld_pos = self.world.transform_point(wnd_pos, self.renderPosition, self.heading, self.side) # draw the wander circle
		egi.green_pen()
		egi.circle(wld_pos, self.wanderRadius)
		# draw the wander target (little circle on the big circle)
		egi.red_pen()
		wnd_pos = (self.wander_target + Vector2D(self.wanderDistance,0))
		wld_pos = self.world.transform_point(wnd_pos, self.renderPosition, self.heading, self.side)
		egi.circle(wld_pos, 3)
Exemple #36
0
	def flock(self, delta):

		
		alignment = self.alignmentForce()
		separation = self.separationForce()
		cohesion = self.cohesionForce()

		if(self.chosenOne and self.world.drawComponentForces):
			s = 0.1
			egi.green_pen()
			egi.line_with_arrow(self.pos, self.pos + alignment * s, 10)
			egi.blue_pen()
			egi.line_with_arrow(self.pos, self.pos + separation * s, 10)
			egi.red_pen()
			egi.line_with_arrow(self.pos, self.pos + cohesion * s, 10)
			egi.grey_pen()
			egi.line_with_arrow(self.pos, self.pos + self.force * s, 10)
			egi.circle(self.pos, self.neighbourDistance)

		return alignment + separation + cohesion
Exemple #37
0
    def render(self):
        for agent in self.agents:
            agent.render()

        if self.target:
            egi.red_pen()
            for obstacle in self.obstacles:
                egi.circle(obstacle.pos, obstacle.radius, filled=True)

        if self.show_info:
            massText = "Mass(q,w): " + str(agent.mass)
            maxTurnText = "Max Turn Force(a,s): " + str(agent.max_force)
            maxSpeedText = "Max Speed(z,x): " + str(agent.max_speed)
            agent = self.agents[0]
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
            egi.text_at_pos(150, 0, massText)
            egi.text_at_pos(150, 13, maxTurnText)
            egi.text_at_pos(150, 26, maxSpeedText)
Exemple #38
0
    def render(self):
        for agent in self.agents:
            if agent is not self.hunter:
                agent.render()
            else:
                agent.render("GREEN")


        for obs in self.obstacles:
            obs.render()

        if self.target:
            egi.red_pen()
            egi.cross(self.target, 10)


        if self.show_info:
            infotext = ', '.join(set(agent.mode for agent in self.agents))
            infotext += ', '
            infotext += ' , '.join(set(agent.attribute for agent in self.agents))
            egi.white_pen()
            egi.text_at_pos(0, 0, infotext)
Exemple #39
0
    def render(self, color=None):
        ''' Draw the triangle agent with color'''
        # draw the ship
        egi.set_pen_color(name=self.color)
        pts = self.world.transform_points(self.vehicle_shape, self.pos,self.heading, self.side, self.scale)
        # draw it!
        egi.closed_shape(pts)

        #draw some patrol target
        egi.red_pen()
        for target in self.world.targets:
            egi.cross(target, 10)

        ''' Draw bullets '''
        egi.grey_pen()
        if self.mode == 'fire':
            self.shoot_enemy()

        if self.mode == 'reload':
            self.color = 'YELLOW'
            self.reload_gun()
            if self.ammo == 10:
                self.mode = 'soldier'
                self.color = 'GREEN'
Exemple #40
0
 def render(self):
     egi.red_pen()
     egi.circle(self.pos, self.radius)
Exemple #41
0
	def obstacleAvoidance(self, objects):
		# calc a "Detection Box" length proportional to current speed
		boxLength = self.minBoxLength + (self.speed() / self.maxSpeed) * self.minBoxLength
		boxWidth = self.boundingRadius * 2

		# Draw the collision box
		if(self.chosenOne and self.world.drawDebug):
			box = Rect({
				'left': 0, 
				'right': boxLength, 
				'top': boxWidth/2, 
				'bottom': -boxWidth/2
			})
			boxPoints = box.getPoints()
			print 'render points...', Util.strPoints(boxPoints)

			pts = self.pointsInWorldSpace(boxPoints, self.pos)
			print 'render points...', Util.strPoints(pts)
			egi.red_pen()
			egi.closed_shape(pts)
			simple = [
				Vector2D(0, 10),
				Vector2D(10, 10),
				Vector2D(10, -10),
				Vector2D(0, -10)]
			egi.closed_shape(self.pointsInWorldSpace(simple, self.pos))
		
		# note (tag) the objects in range
		tagList = self.tagObjectsInViewRange(objects, boxLength, boxWidth)
		closestDistance = BIG_FLOAT # float('inf') 
		closestObj = None
		closestPos = None

		# Loop through the TagList and find the intersection points ... 
		# keep track of the closest object found ...
		# Calculate the steering force (if required) ...

		for obj in tagList:
			localPos = PointToLocalSpace(obj.pos, self.heading, self.side, self.pos) 
			if localPos.x >= 0:
				ExpandedRadius = obj.boundingRadius + self.boundingRadius 
				if abs(localPos.y) < ExpandedRadius:
					# line/circle intersection test, x = cX +/- sqrt(r**2 - cY**2) for y=0
					cX = localPos.x
					cY = localPos.y
					# only calc the sqrt part once (avoid repetition) 
					sqrtPart = math.sqrt(ExpandedRadius**2 - cY**2) 
					ip = cX - sqrtPart
					if ip <= 0.0: 
						ip = cX + sqrtPart
						# Keep track of the closest found so far
						if ip < closestDistance:
							closestDistance = ip 
							closestObj = obj 
							closestPos = obj.pos

		# now find the steering force
		steeringForce = Vector2D() 
		if closestObj:
			# the closer, the stronger the force needed
			multi = 1.0 + (boxLength - closestPos.x) / boxLength

			# lateral force as needed
			steeringForce.y = (closestObj.boundingRadius - closestPos.y) * multi

			# breaking force proportional to closest object
			breakingWeight = 0.2
			steeringForce.x = (closestObj.boundingRadius - closestPos.x) * breakingWeight
		
		# convert force back to world space
		return VectorToWorldSpace(steeringForce,self.heading, self.side)
Exemple #42
0
 def render(self):
 	egi.red_pen()
 	egi.circle(self.pos, 20)
Exemple #43
0
	def render(self, color=None):
		egi.red_pen()
		egi.circle(self.pos, 30)