Commit 11e326bf authored by Chris Dancy's avatar Chris Dancy
Browse files

Commiting some previously fixed issues

parent 6cb34e0b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ class Agent:
            return self.get_cell_on_left()
        elif key == 'right_cell':
            return self.get_cell_on_right()
        elif key == 'left90_cell':
            return self.get_cell_on_left90()
        elif key == 'right90_cell':
            return self.get_cell_on_right90()
        elif key == 'ahead_cell':
            return self.get_cell_ahead()
        raise AttributeError(key)
@@ -80,6 +84,12 @@ class Agent:
    def get_cell_on_right(self):
        return self.cell.neighbour[(self.dir + 1) % self.world.directions]

    def get_cell_on_left90(self):
        return self.cell.neighbour[(self.dir - 2) % self.world.directions]

    def get_cell_on_right90(self):
        return self.cell.neighbour[(self.dir + 2) % self.world.directions]

    def go_towards(self, target, y=None):
        if not isinstance(target, Cell):
            target = self.world.grid[int(y)][int(target)]
+128 −114
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ class VisionScanner(ccm.Model):
		self.scan_time = scan_time

	def start(self):
        while True:
		for obj in self._body._list_visible_objects():
			if hasattr(obj, 'cell'):
				if getattr(obj, 'x', None) != obj.cell.x:
@@ -121,8 +120,23 @@ class VisionScanner(ccm.Model):
				salience = 1

			self._visual.add(obj)
		# Modified by Chris Dancy
		# Any agents in the environment are now included in the list of items returned
		#  May want to remove ground object at same location in future
		try:
			for agent in self._body.world.agents:
				try:
					ox, oy = agent.x, agent.y
					x, y = self._body.x, self._body.y
					salience = self.salience(ox - x, oy - y)
				except AttributeError:
					salience = 1
		except AttributeError:
			pass

		yield self.scan_time


	def salience(self, dx, dy):
		dist = dx * dx + dy * dy
		s = 4 / (math.sqrt(dist) + 1)
+3 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ def get(obj,name,key):
      key1,key=key.split('.',1)
      try:
        a=a[key1]
      except AttributeError:
      except (AttributeError, TypeError):
        a=getattr(a,key1)
  try:
      x=a[key]
@@ -103,10 +103,12 @@ def parse(patterns,bound=None):
                            pass
                        text=text[m.end():]
                        if len(text)==0:
                            print("106")
                            raise PatternException("No value for slot '%s' in pattern '%s'"%(key,pattern))
                        namedSlots=True
                    else:
                        if namedSlots!=False:
                            print("111")
                            raise PatternException("Found unnamed slot '%s' after named slot in pattern '%s'"%(text,pattern))
                    if text=='?': continue
                    while len(text)>0:
+10 −0
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ class Agent:
            return self.get_cell_on_left()
        elif key == 'right_cell':
            return self.get_cell_on_right()
        elif key == 'left90_cell':
            return self.get_cell_on_left90()
        elif key == 'right90_cell':
            return self.get_cell_on_right90()
        elif key == 'ahead_cell':
            return self.get_cell_ahead()
        raise AttributeError(key)
@@ -80,6 +84,12 @@ class Agent:
    def get_cell_on_right(self):
        return self.cell.neighbour[(self.dir + 1) % self.world.directions]

    def get_cell_on_left90(self):
        return self.cell.neighbour[(self.dir - 2) % self.world.directions]

    def get_cell_on_right90(self):
        return self.cell.neighbour[(self.dir + 2) % self.world.directions]

    def go_towards(self, target, y=None):
        if not isinstance(target, Cell):
            target = self.world.grid[int(y)][int(target)]
+128 −114
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ class VisionScanner(ccm.Model):
		self.scan_time = scan_time

	def start(self):
        while True:
		for obj in self._body._list_visible_objects():
			if hasattr(obj, 'cell'):
				if getattr(obj, 'x', None) != obj.cell.x:
@@ -121,8 +120,23 @@ class VisionScanner(ccm.Model):
				salience = 1

			self._visual.add(obj)
		# Modified by Chris Dancy
		# Any agents in the environment are now included in the list of items returned
		#  May want to remove ground object at same location in future
		try:
			for agent in self._body.world.agents:
				try:
					ox, oy = agent.x, agent.y
					x, y = self._body.x, self._body.y
					salience = self.salience(ox - x, oy - y)
				except AttributeError:
					salience = 1
		except AttributeError:
			pass

		yield self.scan_time


	def salience(self, dx, dy):
		dist = dx * dx + dy * dy
		s = 4 / (math.sqrt(dist) + 1)
Loading