Beispiel #1
0
    def draw_paths(self):
        if self.path:
            # copied from the box_world

            egi.set_stroke(2)
            # Show open edges
            route = self.path.route
            egi.set_pen_color(name='GREEN')
            for i in self.path.open:
                egi.circle(self.world.boxes[i]._vc, 10)
            # show the partial paths considered
            egi.set_pen_color(name='ORANGE')
            egi.set_stroke(2)
            for i, j in route.items():
                egi.line_by_pos(self.world.boxes[i]._vc,
                                self.world.boxes[j]._vc)
            egi.set_stroke(1)

            # show the final path delivered
            egi.set_pen_color(name='RED')
            egi.set_stroke(2)
            path = self.path.path
            for i in range(1, len(path)):
                egi.line_by_pos(self.world.boxes[path[i - 1]]._vc,
                                self.world.boxes[path[i]]._vc)
            egi.set_stroke(1)
Beispiel #2
0
    def render(self, color=None):

        # draw the ship
        egi.set_pen_color(name=self.color)

        egi.cross(self.pos,10)
        egi.circle(self.pos,10)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
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()
    def draw(self):
        # draw filled box
        egi.set_pen_color(self.color)
        egi.closed_shape(self._pts, filled=True)

        # draw box border
        if cfg['BOXLINES_ON']:
            egi.set_pen_color((.7, .7, .7, 1))
            egi.closed_shape(self._pts, filled=False)

        if self.kind == 'I':
            egi.set_stroke(1)
            egi.set_pen_color(name="RED")
            egi.line(self._pts[0].x + 10, self._pts[0].y - 5,
                     self._pts[0].x + 10, self._pts[0].y - 16)
            egi.line(self._pts[0].x + 5, self._pts[0].y - 11,
                     self._pts[0].x + 16, self._pts[0].y - 11)

        if self.kind == 'P':
            obj_pts = (
                Point2D(self._pts[0].x + 5, self._pts[0].y - 5),  # top left
                Point2D(self._pts[0].x + 15, self._pts[0].y - 4),  # top right
                Point2D(self._pts[0].x + 15,
                        self._pts[0].y - 15),  # bottom right
                Point2D(self._pts[0].x + 5, self._pts[0].y - 15)  # bottom left
            )
            egi.set_stroke(1)
            egi.set_pen_color(name="RED")
            egi.closed_shape(obj_pts, filled=False)

        # centre circle
        if cfg['CENTER_ON']:
            egi.set_pen_color((.3, .3, 1, 1))
            egi.circle(self._vc, 5)
        # box position (simple column,row) (or x,y actually)
        if self.node:
            if cfg['LABELS_ON']:
                if not self.idx_label:
                    info = "%d" % self.idx
                    self.idx_label = pyglet.text.Label(info,
                                                       color=(0, 0, 0, 255),
                                                       anchor_x="center",
                                                       anchor_y="top")
                    info = "(%d,%d)" % (self.pos[0], self.pos[1])
                    self.pos_label = pyglet.text.Label(info,
                                                       color=(0, 0, 0, 255),
                                                       anchor_x="center",
                                                       anchor_y="bottom")
                    self._reposition_labels()
                self.idx_label.draw()
                #self.pos_label.draw()
        if self.marker:
            if not self.marker_label or self.marker_label.text != self.marker:
                self.marker_label = pyglet.text.Label(self.marker,
                                                      color=(255, 0, 0, 255),
                                                      bold=True,
                                                      anchor_x="center",
                                                      anchor_y="center")
                self._reposition_labels()
            self.marker_label.draw()
Beispiel #7
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'])
Beispiel #8
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'])
Beispiel #9
0
	def separationForce(self):

		avg = Vector2D()
		count = 0

		# Radius within which to steer away
		DESIRED_SEPARATION = 60
		if(self.world.drawDebug and self.chosenOne):
			egi.circle(self.pos, DESIRED_SEPARATION)

		for agent in self.neighbours:
			d = self.pos.distance(agent.pos)
			if d > 0 and d < DESIRED_SEPARATION:
				# Normalized, weighted by distance vector pointing away from the neighbour

				direction = (self.pos - agent.pos).normalise()
				# print 'direction', direction
				amount = direction / d
				
				avg += amount
				count += 1


		if(count > 0):
			avg /= float(count)

		

		avg *= 20000

		avg.truncate(self.maxForce)
		

		return avg




		steeringForce = Vector2D() 

		if(len(self.neighbours) == 0):
			return steeringForce

		

		for agent in self.neighbours:	      
			# toNeighbour = agent.pos.distanceTo(self.pos)
			toNeighbour = self.pos - agent.pos
			# scale based on inverse distance to neighbour 
			steeringForce += toNeighbour.normalise() / (toNeighbour.length() + 0.01) # prevent divide by zero

		

		# steeringForce = self.seek(-steeringForce)

		

		return steeringForce * self.separationInfluence
Beispiel #10
0
    def drawEye(self, color=None):

        if (self.dead):
            egi.set_pen_color(self.color)
            egi.cross(self.renderPosition + self.side * self.body,
                      self.body * 5)
        else:
            egi.set_pen_color(rgba('fff', 0.5))
            egi.circle(self.renderPosition + self.side * self.body, self.body)
Beispiel #11
0
	def drawEye(self, color=None):
		

		if(self.dead):
			egi.set_pen_color(self.color)
			egi.cross(self.renderPosition + self.side * self.body, self.body * 5)
		else:	
			egi.set_pen_color(rgba('fff', 0.5))
			egi.circle(self.renderPosition + self.side * self.body, self.body)
Beispiel #12
0
	def drawEye(self, color=None):
		
		eyePosition = self.renderPosition + self.side * self.body * -8 - self.heading * 20

		eyeRadius = self.body * 0.8
		if(self.awake):
			egi.circle(eyePosition, eyeRadius)
		else:
			egi.line_by_pos(eyePosition, eyePosition + self.heading * eyeRadius * 2)
Beispiel #13
0
    def drawEye(self, color=None):

        eyePosition = self.renderPosition + self.side * self.body * -8 - self.heading * 20

        eyeRadius = self.body * 0.8
        if (self.awake):
            egi.circle(eyePosition, eyeRadius)
        else:
            egi.line_by_pos(eyePosition,
                            eyePosition + self.heading * eyeRadius * 2)
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
0
	def render(self):
		egi.set_pen_color(self.color)

		frequency = 5
		pulse = sin(self.world._clock * frequency)

		range = 0.2
		pulse = 1 + (pulse * range) 
		r = self.boundingRadius * pulse
		
		egi.circle(self.pos, r, filled=True)
Beispiel #17
0
    def render(self):
        egi.set_pen_color(self.color)

        frequency = 5
        pulse = sin(self.world._clock * frequency)

        range = 0.2
        pulse = 1 + (pulse * range)
        r = self.boundingRadius * pulse

        egi.circle(self.pos, r, filled=True)
Beispiel #18
0
 def render(self):
     ''' Draw the path, open or closed, using the current pen colour. '''
     # draw base line
     egi.blue_pen()
     if self.looped:
         egi.closed_shape(self._pts)
     else:
         egi.polyline(self._pts)
     # draw current waypoint
     egi.orange_pen()
     wp = self.current_pt()
     egi.circle(pos=wp, radius=5, slices=32)
Beispiel #19
0
    def draw(self):
        for box in self.boxes:
            box.draw()

        if cfg['EDGES_ON']:
            egi.set_pen_color(name='LIGHT_BLUE')
            for node, edges in self.graph.edgelist.items():
                # print node, edges
                for dest in edges:
                    egi.line_by_pos(self.boxes[node]._vc, self.boxes[dest]._vc)



        if self.path:

            if not self.agent:
                path_pts = []
                for i in range(0,len(self.path.path)):
                    path_pts.append(PointToVector2D(self.boxes[self.path.path[i]]._vc))

                self.agent = Agent()
                self.agent.path.set_pts(path_pts)

            self.agent.update()
            self.agent.render()

            # put a circle in the visited boxes?
            if cfg['BOXUSED_ON']:
                egi.set_pen_color(name="GREEN")
                for i in self.path.closed:
                    egi.circle(self.boxes[i]._vc, 10)

            if cfg['TREE_ON']:
                egi.set_stroke(3)
                # Show open edges
                route = self.path.route
                egi.set_pen_color(name='GREEN')
                for i in self.path.open:
                    egi.circle(self.boxes[i]._vc, 10)
                # show the partial paths considered
                egi.set_pen_color(name='ORANGE')
                for i,j in route.items():
                    egi.line_by_pos(self.boxes[i]._vc, self.boxes[j]._vc)
                egi.set_stroke(1)

            if cfg['PATH_ON']:
                # show the final path delivered
                egi.set_pen_color(name='RED')
                egi.set_stroke(2)
                path = self.path.path
                for i in range(1,len(path)):
                    egi.line_by_pos(self.boxes[path[i-1]]._vc, self.boxes[path[i]]._vc)
                egi.set_stroke(1)
Beispiel #20
0
 def render(self):
     ''' Draw the path, open or closed, using the current pen colour. '''
     # draw base line
     egi.blue_pen()
     if self.looped:
         egi.closed_shape(self._pts)
     else:
         egi.polyline(self._pts)
     # draw current waypoint
     egi.orange_pen()
     wp = self.current_pt()
     egi.circle(pos=wp, radius=5, slices=32)
Beispiel #21
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
Beispiel #22
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)
    def draw(self):
        for box in self.boxes:
            box.draw()

        if cfg['EDGES_ON']:
            egi.set_pen_color(name='LIGHT_BLUE')
            for node, edges in self.graph.edgelist.items():
                # print node, edges
                for dest in edges:
                    egi.line_by_pos(self.boxes[node]._vc, self.boxes[dest]._vc)

        if self.path:
            # put a circle in the visited boxes?
            if cfg['BOXUSED_ON']:
                egi.set_pen_color(name="GREEN")
                for i in self.path.closed:
                    egi.circle(self.boxes[i]._vc, 10)

            if cfg['TREE_ON']:
                egi.set_stroke(3)
                # Show open edges
                route = self.path.route
                egi.set_pen_color(name='GREEN')
                for i in self.path.open:
                    egi.circle(self.boxes[i]._vc, 10)
                # show the partial paths considered
                egi.set_pen_color(name='ORANGE')
                for i,j in route.items():
                    egi.line_by_pos(self.boxes[i]._vc, self.boxes[j]._vc)
                egi.set_stroke(1)

            if cfg['PATH_ON']:
                # show the final path delivered
                egi.set_pen_color(name='RED')
                egi.set_stroke(2)
                path = self.path.path
                for i in range(1,len(path)):
                    egi.line_by_pos(self.boxes[path[i-1]]._vc, self.boxes[path[i]]._vc)
                egi.set_stroke(1)

        if self.agent:
            self.agent.render()
    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
Beispiel #25
0
    def render(self):
        ''' Draw the path, open or closed, using the current pen colour. '''

        for index, wp in enumerate(self._way_pts):
            egi.blue_pen()
            filled = False
            if (index < self._cur_pt_idx):
                egi.green_pen()

            if (index == self._cur_pt_idx):
                egi.orange_pen()
                filled = True

            egi.circle(pos=wp, radius=5, filled=filled, slices=32)

        egi.blue_pen()
        if self.looped:
            egi.closed_shape(self._way_pts)
        else:
            egi.polyline(self._way_pts)
Beispiel #26
0
    def render(self):
        ''' Draw the path, open or closed, using the current pen colour. '''

        for index, wp in enumerate(self._way_pts):
            egi.blue_pen()
            filled = False
            if(index < self._cur_pt_idx):
                egi.green_pen()

            if(index == self._cur_pt_idx):
                egi.orange_pen()
                filled = True

            egi.circle(pos=wp, radius=5, filled=filled, slices=32)

        egi.blue_pen()
        if self.looped:
            egi.closed_shape(self._way_pts)
        else:
            egi.polyline(self._way_pts)
Beispiel #27
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
Beispiel #28
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)
Beispiel #29
0
    def render(self):
        for agent in self.agents:
            agent.render()

        egi.white_pen()
        for objectPosition in self.objects:
            egi.circle(objectPosition, 50)

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

        if self.show_info:
            infotext = \
                'Mode: ' + self.agents[1].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)
Beispiel #30
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 hiding spots
        egi.blue_pen()
        egi.circle(self.obstacles[0], 25)
        egi.circle(self.obstacles[1], 50)
        egi.circle(self.obstacles[2], 75)

        #draw detection box
        egi.blue_pen()
        length = 1.0 * (self.speed() / self.max_speed) * 3.0  #db length
        dbox = [
            Point2D(-1.0, 0.6),
            Point2D(length, 0.6),  #new
            Point2D(length, 0.0),  #new
            Point2D(length, -0.6),  #new
            Point2D(-1.0, -0.6)
        ]
        pts = self.world.transform_points(dbox, self.pos, self.heading,
                                          self.side, self.scale)
        egi.closed_shape(pts, False)
    def draw(self):
        for box in self.boxes:
            box.draw()

        if cfg['EDGES_ON']:
            egi.set_pen_color(name='LIGHT_BLUE')
            for node, edges in self.graph.edgelist.items():
                # print node, edges.
                for dest in edges:
                    egi.line_by_pos(self.boxes[node]._vc, self.boxes[dest]._vc)

        if self.path:
            # put a circle in the visited boxes?
            if cfg['BOXUSED_ON']:
                egi.set_pen_color(name="GREEN")
                for i in self.path.closed:
                    egi.circle(self.boxes[i]._vc, 10)

            if cfg['TREE_ON']:
                egi.set_stroke(3)
                # Show open edges.
                route = self.path.route
                egi.set_pen_color(name='GREEN')
                for i in self.path.open:
                    egi.circle(self.boxes[i]._vc, 10)
                # show the partial paths considered.
                egi.set_pen_color(name='ORANGE')
                for i, j in route.items():
                    egi.line_by_pos(self.boxes[i]._vc, self.boxes[j]._vc)
                egi.set_stroke(1)

            if cfg['PATH_ON']:
                # show the final path delivered
                egi.set_pen_color(name='RED')
                egi.set_stroke(2)
                path = self.path.path
                for i in range(1, len(path)):
                    egi.line_by_pos(self.boxes[path[i - 1]]._vc,
                                    self.boxes[path[i]]._vc)
                egi.set_stroke(1)
Beispiel #32
0
    def render(self):
        for agent in self.agents:
            if agent.mode == 'hunt':
                egi.blue_pen()
                for spot in agent.hiding_spots:
                    egi.cross(spot, 10)
            elif agent.mode == 'prey':
                egi.green_pen()
                egi.circle(agent.best_spot, 10)
            agent.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)
    def draw(self):
        # draw filled box
        egi.set_pen_color(self.color)
        egi.closed_shape(self._pts, filled=True)

        # draw box border
        if cfg['BOXLINES_ON']:
            egi.set_pen_color((.7, .7, .7, 1))
            egi.closed_shape(self._pts, filled=False)
        # centre circle
        if cfg['CENTER_ON']:
            egi.set_pen_color((.3, .3, 1, 1))
            egi.circle(self._vc, 5)
        # box position (simple column,row) (or x,y actually)
        if self.node:
            if cfg['LABELS_ON']:
                if not self.idx_label:
                    info = "%d" % self.idx
                    self.idx_label = pyglet.text.Label(info,
                                                       color=(0, 0, 0, 255),
                                                       anchor_x="center",
                                                       anchor_y="top")
                    info = "(%d,%d)" % (self.pos[0], self.pos[1])
                    self.pos_label = pyglet.text.Label(info,
                                                       color=(0, 0, 0, 255),
                                                       anchor_x="center",
                                                       anchor_y="bottom")
                    self._reposition_labels()
                self.idx_label.draw()
                #self.pos_label.draw()
        if self.marker:
            if not self.marker_label or self.marker_label.text != self.marker:
                self.marker_label = pyglet.text.Label(self.marker,
                                                      color=(255, 0, 0, 255),
                                                      bold=True,
                                                      anchor_x="center",
                                                      anchor_y="center")
                self._reposition_labels()
            self.marker_label.draw()
Beispiel #34
0
	def tagObjectsInViewRange(self, objects, boxLength, boxWidth):

		tagged = []

		# Check each object in the list
		for obj in objects:

			if(self.chosenOne): obj.tagged = False

			# Don't check outselves
			if(obj == self):
				continue

			localPos = VectorToLocalSpace(obj.pos, self.heading, self.side)
			radius = obj.boundingRadius + boxWidth * 0.5

			
			
			# If it's behind us, or its x is further away than the box
			if(localPos.x < 0 or localPos.x - radius > boxLength):
				continue
			
			# So we're within the box's x range
			# Time to check the y

			# If its highest point is below the box, or its lowest point is above the box
			if(localPos.y - radius < -boxWidth / 2 or localPos.y + radius < boxWidth/2):
				continue

			# We must have intersected the box, so tag ourselves
			tagged.append(obj)

			if(self.chosenOne and self.world.drawDebug): 
				obj.tagged = True
				egi.circle(obj.localPos, radius)


		return tagged
Beispiel #35
0
    def render(self, color=None):
        ''' Draw moving target '''
        #calculate target points
        self.movingTarget()
        #draw target using those points
        egi.blue_pen()
        dbox = [
            Point2D(self.x0, self.y0),
            Point2D(self.x1, self.y0),
            Point2D(self.x1, self.y1),
            Point2D(self.x0, self.y1)
        ]
        egi.closed_shape(dbox, False)
        #pos of target
        self.target_pos = Vector2D(self.x0 + self.target_mid.x, self.y1 + self.target_mid.y)

        ''' 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 bullets being fired
        egi.green_pen()
        if self.mode == 'rifle' or self.mode == 'rocket' or self.mode == 'handgun' or self.mode == 'grenade':
            if self.step_count == 0:
                egi.circle(self.bullet_pos, self.size)
                self.step_count += 1
            elif self.bullet_pos.y > self.target_pos.y:
                self.step_count = 0
                self.bullet_pos = Vector2D(250,250)
                self.mode = 'aim'
            else:
                self.bullet_pos += self.avg
                egi.circle(self.bullet_pos, self.size)
                self.step_count += 1
Beispiel #36
0
    def shoot_enemy(self):
        self.bullet_path(self.enemy)

        #soldier fires bullet
        if self.step_count == 0:
            self.bullet_pos = self.world.soldier.pos.copy()
        #update bullet pos
        elif self.step_count > 0:
            self.bullet_pos += self.avg
        egi.circle(self.bullet_pos, 5)
        self.step_count += 1

        #reduce stats for soldier and enemy target
        if self.bullet_pos == self.enemy.pos or self.bullet_pos.distance(self.enemy.pos) < 10:
            self.enemy_health()
            print('enemy health: ', self.enemy.health)
            #check if enemy is dead
            if self.enemy.health == 0:
                self.mode = 'soldier'
                self.world.hostiles.remove(self.enemy)
                self.world.agents.remove(self.enemy)
                self.enemy = Vector2D()
                self.step_count = 0
    def draw(self):
        # draw filled box
        egi.set_pen_color(self.color)
        egi.closed_shape(self._pts, filled=True)

        # draw box border
        if cfg['BOXLINES_ON']:
            egi.set_pen_color((.7,.7,.7,1))
            egi.closed_shape(self._pts, filled=False)
        # centre circle
        if cfg['CENTER_ON']:
            egi.set_pen_color((.3,.3,1,1))
            egi.circle(self._vc, 5)
        # box position (simple column,row) (or x,y actually)
        if self.node:
            if cfg['LABELS_ON']:
                if not self.idx_label:
                    info = "%d" % self.idx
                    self.idx_label = pyglet.text.Label(info, color=(0,0,0,255),
                                                       anchor_x="center",
                                                       anchor_y="top")
                    info = "(%d,%d)" % (self.pos[0], self.pos[1])
                    self.pos_label = pyglet.text.Label(info, color=(0,0,0,255),
                                                       anchor_x="center",
                                                       anchor_y="bottom")
                    self._reposition_labels()
                self.idx_label.draw()
                #self.pos_label.draw()
        if self.marker:
            if not self.marker_label or self.marker_label.text != self.marker:
                self.marker_label = pyglet.text.Label(self.marker,
                                                      color=(255,0,0,255),
                                                      bold=True,
                                                      anchor_x="center",
                                                      anchor_y="center")
                self._reposition_labels()
            self.marker_label.draw()
Beispiel #38
0
    def shoot_enemy(self):
        self.bullet_path(self.enemy)

        #soldier fires bullet
        if self.step_count == 0:
            self.bullet_pos = self.world.soldier.pos.copy()
        #update bullet pos
        elif self.step_count > 0:
            self.bullet_pos += self.avg
        egi.circle(self.bullet_pos, 5)
        self.step_count += 1

        #reduce stats for soldier and enemy target
        if self.bullet_pos == self.enemy.pos or self.bullet_pos.distance(
                self.enemy.pos) < 10:
            self.enemy_health()
            print('enemy health: ', self.enemy.health)
            #check if enemy is dead
            if self.enemy.health == 0:
                self.mode = 'soldier'
                self.world.hostiles.remove(self.enemy)
                self.world.agents.remove(self.enemy)
                self.enemy = Vector2D()
                self.step_count = 0
Beispiel #39
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 it!
        egi.closed_shape(pts)

        # draw wander info?
        ## ...
        # 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.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(self.pos, self.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)
Beispiel #40
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)
Beispiel #41
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)
Beispiel #42
0
	def bestHidingPlaceFromHunter(self, hidingPlaces, hunter, closest=True):

		

		closestPlaces = sorted(hidingPlaces, key=lambda p: p.distanceSq(self.pos))

		if(closest):
			return closestPlaces[0]
		
		# Get the closest places that are out of range of the hunter
		safePlaces = [place for place in closestPlaces if not hunter.canSeePosition(place)]

		if(self.chosenOne and self.world.drawHidingSpots):
			egi.blue_pen()
			[egi.circle(p, 10) for p in safePlaces]

		# If there actually are some safe places then choose the closest (they'll still be in order)
		if(len(safePlaces)):
			return safePlaces[0]

		# If all hiding places are close to the hunter, then just pick the furthest
		return max(hidingPlaces, key=lambda p: p.distanceSq(hunter.pos))
Beispiel #43
0
	def render(self, color=None):
		egi.red_pen()
		egi.circle(self.pos, 30)
Beispiel #44
0
 def render(self):
 	egi.red_pen()
 	egi.circle(self.pos, 20)
Beispiel #45
0
 def render(self):
     egi.green_pen()
     egi.set_stroke(2)
     egi.circle(self.pos, self.radius, True)
 def render(self):
     egi.aqua_pen()
     egi.circle(self.pos, self.radius)
Beispiel #47
0
 def render(self):
     egi.white_pen()
     egi.set_stroke(3)
     egi.circle(self.pos, self.radius)