コード例 #1
0
 def update(self, model):
     attack = []
     for x in set(model.simultons):
         if isinstance(x, Hunter) and Mobile_Simulton.distance(self, x.get_location()) <= 100:
             attack.append((x, Mobile_Simulton.distance(self, x.get_location())))
     if attack != []:
         hunt_the_hunter = min(attack, key = lambda x: x[1])
         angle = (hunt_the_hunter[0].get_location()[1] - self.get_location()[1], hunt_the_hunter[0].get_location()[0] - self.get_location()[0])
         self.set_angle(atan2(*(angle)))
     self.move()
     return self.kill(model)
コード例 #2
0
 def update(self, model):
     attack = []
     for x in set(model.simultons):
         if isinstance(x, Prey) and Mobile_Simulton.distance(
                 self, x.get_location()) <= Hunter.distance:
             attack.append(
                 (x, Mobile_Simulton.distance(self, x.get_location())))
     if attack != []:
         prey = min(attack, key=lambda x: x[1])
         angle = (prey[0].get_location()[1] - self.get_location()[1],
                  prey[0].get_location()[0] - self.get_location()[0])
         self.set_angle(atan2(*(angle)))
     self.move()
     return Pulsator.update(self, model)
コード例 #3
0
 def update(self, model):
     self.move()
     self.wall_bounce()
     closest = None
     near = model.find(lambda s: isinstance(s, Prey) and Mobile_Simulton.
                       distance(self, s.get_location()) <= Hunter.distance)
     if len(near) != 0:
         closest_distance = min(
             [Mobile_Simulton.distance(self, (n._x, n._y)) for n in near])
         for simulton in near:
             if Mobile_Simulton.distance(
                     self, (simulton._x, simulton._y)) == closest_distance:
                 closest = simulton
         self._angle = atan2(closest._y - self._y, closest._x - self._x)
     Pulsator.update(self, model)
コード例 #4
0
 def update(self, model):
     self.move()
     result = dict()
     for item in model.find(lambda x: isinstance(x, Prey)):
         if Mobile_Simulton.distance(self,
                                     (item._x, item._y)) < Hunter.distance:
             result[Mobile_Simulton.distance(self,
                                             item.get_location())] = item
     if result != dict():
         m = min(result)
         min_location = result[m].get_location()
         hunter_location = self.get_location()
         new_x_angle = min_location[0] - hunter_location[0]
         new_y_angle = min_location[1] - hunter_location[1]
         Mobile_Simulton.set_angle(self, atan2(new_y_angle, new_x_angle))
     Pulsator.update(self, model)