def update(self,model): temp=model.find(lambda a:isinstance(a,Prey)) for i in temp: if self.distance(i.get_location())<=Hunter.eye: self.set_angle(atan2(i.get_location()[1]-self.get_location()[1],i.get_location()[0]-self.get_location()[0])) Pulsator.update(self,model) self.move()
def update(self): Pulsator.update(self) self.counter += 1 self._x = self.get_location()[0] self._y = self.get_location()[1] if self.counter == Special.Counter: self.set_location(self._x + (randrange(-75, 75)), self._y + (randrange(-75, 75))) self.counter = 0
def update(self, model): Pulsator.update(self, model) g = model.find(lambda x: isinstance(x, Prey)) for f in g: if self.distance(f.get_location()) <= self.dis: y = f.get_location()[1] - self.get_location()[1] x = f.get_location()[0] - self.get_location()[0] angle = atan2(y, x) self.set_angle(angle) self.move()
def update(self): Pulsator.update(self) in_hunt_radius = model.find(lambda x: isinstance(x, Prey) and x. distance(self.get_location()) <= 200) if len(in_hunt_radius) > 0: closest = sorted(in_hunt_radius, key=lambda x: x.distance(self.get_location()))[0] self.set_angle( atan2(closest.get_location()[1] - self.get_location()[1], closest.get_location()[0] - self.get_location()[0])) self.move()
def update(self, eaten): x, y = self.get_location() hunting_set = model.find( lambda x: self.distance(x) <= Hunter.hunting_range) if hunting_set != set(): closest = min(hunting_set, key=lambda k: k.distance((x, y))) x1, y1 = closest.get_location() angle = atan2(y1 - y, x1 - x) self.set_angle(angle) Pulsator.update(self, eaten) self.move()
def update(self, model): matched = model.find(lambda s: isinstance(s,Simulton ) and type(s) is not Special and self.min_distance>=self.distance(s.get_location())) Pulsator.update(self, model) if matched: matched_min = [i for i in sorted(matched, key = lambda i: self.distance(i.get_location()))] new_x, new_y = matched_min[0].get_location() x, y = self.get_location() self.set_angle(atan2( new_y -y, new_x -x)) print('myangle', self.get_angle()) self.move() return matched
def update(self, model): target_simu = model.find( lambda x: isinstance(x, Prey) and self.distance(x.get_location( )) <= Hunter.search_distance) for target in target_simu: position_target = target.get_location() position_hunter = self.get_location() self.set_angle( atan2(position_target[1] - position_hunter[1], position_target[0] - position_hunter[0])) Pulsator.update(self, model) self.move()
def update(self): closest = None Pulsator.update(self) s = model.find(lambda x: isinstance(x, Prey) and self.distance( (x._x, x._y)) < 200) minimum = 200 for p in s: if minimum > self.distance((p._x, p._y)): closest = p minimum = self.distance((p._x, p._y)) if closest != None: self._angle = atan2(closest._y - self._y, closest._x - self._x) self.move()
def update(self): Pulsator.update(self) a_set = model.find(lambda x: isinstance(x, Prey)) chase = None d = Hunter.dis for i in a_set: if self.distance(i.get_location()) <= d: d = self.distance(i.get_location()) chase = i.get_location() if chase != None: angle = atan2(chase[1] - self.get_location()[1], chase[0] - self.get_location()[0]) self.set_angle(angle) self.move()
def update(self, model): closestd = Hunter.vision closest = None for p in model.find(lambda c: isinstance(c, Prey) and self.distance( (c._x, c._y)) <= Hunter.vision): if self.distance(p.get_location()) < closestd: closestd = self.distance(p.get_location()) closest = p if closest != None: px, py = closest.get_location() sx, sy = self.get_location() self.set_angle(atan2(py - sy, px - sx)) Pulsator.update(self, model) self.move()
def update(self, model): p = lambda sim: (isinstance(sim, Prey) and self.distance( sim.get_location()) <= 200) hunt = model.find(p) s_hunt = sorted(hunt.copy(), key=lambda x: self.distance(x.get_location())) if len(s_hunt) > 0: closest = s_hunt[0] cx, cy = closest.get_location() dif_x = cx - self._x dif_y = cy - self._y new_angle = atan2(dif_y, dif_x) self.set_angle(new_angle) Pulsator.update(self, model) self.move()
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)
def update(self, model): Pulsator.update(self, model) nearbyPrey = model.find(lambda x: isinstance(x, Prey) and self. distance((x.get_location())) <= 200) toSort = [] for prey in nearbyPrey: toSort.append((prey, self.distance((prey.get_location())))) if toSort != []: prey_to_chase = min(toSort, key=lambda x: x[1]) xp, yp = Prey.get_location(prey_to_chase[0]) xh, yh = self.get_location() diff_y = yp - yh diff_x = xp - xh self.set_angle(atan2(diff_y, diff_x)) Mobile_Simulton.move(self)
def update(self): self.move() Pulsator.update(self) current = 201 chase = 0 for b in (list(model.find(Ball))+list(model.find(Floater))): coord = (b._x, b._y) leng = hypot(coord[0]-self._x, coord[1]-self._y) if leng<Hunter.constant: if leng<current: current=leng chase = b if chase != 0: self._angle = atan2(chase._y-self._y, chase._x-self._x)
def update(self, model): Pulsator.update(self, model) self.move() self.wall_bounce() prey_nearby = False nearest_distance = Hunter.view_distance for item in model.find(Prey): dist = self.distance(item.get_location()) if dist < Hunter.view_distance and dist < nearest_distance: nearest = item nearest_distance = dist prey_nearby = True if prey_nearby: self._angle = atan2(-(self._y - nearest._y), -(self._x - nearest._x))
def update(self): Pulsator.update(self) self.move() self.wall_bounce() def p(arg): return isinstance( arg, Prey) and self.distance(arg.get_location()) <= 200 eatable = model.find(p) if len(eatable) != 0: nearest = list(eatable)[0].get_location() for i in eatable: if self.distance(i.get_location()) < self.distance(nearest): nearest = i.get_location() self.set_angle(atan2(nearest[1] - self._y, nearest[0] - self._x))
def update(self): closest = None Pulsator.update(self) s = model.find(lambda x: isinstance (x,Prey) and self.distance((x._x, x._y) )< 200) minimum = 200 for p in s: if minimum > self.distance( (p._x, p._y)): closest = p minimum = self.distance( (p._x, p._y)) if closest != None: self._angle = atan2( closest._y - self._y, closest._x - self._x) self.move()
def update(self, model): Pulsator.update(self, model) self.move() # finding prey all_prey = model.find(lambda x: isinstance(x, Prey)) close_prey = [] for prey in all_prey: position = prey.get_location() if self.distance(position) < self.in_distance: close_prey.append((self.distance(position), prey)) if len(close_prey) != 0: prey_object = sorted(close_prey, key = lambda x: x[0])[0][1] px, py = prey_object.get_location() hx, hy = self.get_location() new_angle = atan2(py - hy, px - hx) self.set_angle(new_angle)
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)
def update(self): Pulsator.update(self) temp = model.find(self.hunt_contains_obj) closest = None ticker = None for i in temp: if ticker == None: ticker = self.distance(i.get_location()) closest = i else: if self.distance(i.get_location()) < ticker: ticker = self.distance(i.get_location()) closest = i if closest != None: self._angle = atan2((closest.get_location()[1] - self._y), (closest.get_location()[0] - self._x)) self.move()
def update(self,balls): self.move() alist = self.return_alist(balls) if 0 < len(alist): self.return_diff(alist) return Pulsator.update(self,balls)
def update(self, model): def seek(xy): return self.distance(xy) <= Hunter.range target = model.find(seek) if len(target) != 0: closest = min( [self.distance(mark.get_location()) for mark in target]) for mark in target: if closest == self.distance(mark.get_location()): lock = mark trail = atan2(lock._y - self._y, lock._x - self._x) self.set_angle(trail) self.move() Pulsator.update(self, model) ate = model.find(self.contains) if self.get_dimension() == (0, 0): ate.add(self) return ate
def update(self): temp = model.find(lambda x: self.distance(x.get_location( )) < Hunter.hunt_range if isinstance(x, Prey) or (isinstance(x, Special) and x.host) else False) if len(temp): target = sorted(list(temp), key=lambda x: self.distance(x.get_location()))[0] self._angle = math.atan2(target._y - self._y, target._x - self._x) self.move() return Pulsator.update(self)
def update(self, model): Pulsator.update(self, model) Mobile_Simulton.move(self) prey_set = model.find(lambda x: isinstance(x, Prey)) can_see = set() for prey in prey_set: distance = ((self._x - prey._x)**2 + (self._y - prey._y)**2)**0.5 if distance < self.vision: can_see.add(prey) nearby = [] for prey in can_see: distance = ((self._x - prey._x)**2 + (self._y - prey._y)**2)**0.5 nearby.append((prey, distance)) if len(nearby) > 0: closest = sorted(nearby, key=lambda x: x[1])[0] self.set_angle( atan2((closest[0]._y - self._y), (closest[0]._x - self._x)))
def update(self,model): chase=set(a for a in model.simuls if isinstance(a,Prey)) want=set() try: for item in chase: if self.distance(item.get_location())<=Hunter.dist: want.add(item) if len(want)==0: self.move() else: fez=min(want,key=lambda prey_on: self.distance(prey_on.get_location())) dif_y=fez.get_location()[1]-self.get_location()[1] dif_x=fez.get_location()[0]-self.get_location()[0] self.set_angle(atan2(dif_y,dif_x)) Pulsator.update(self,model) self.move() except RuntimeError: pass
def update(self,model): eaten = Pulsator.update(self,model) seen = model.find(lambda x : isinstance(x,Prey) and self.distance(x.get_location()) <= Hunter.see_distance) if seen: min_dist,who = min([(self.distance(s.get_location()),s) for s in seen]) sx,sy = self.get_location() x,y = who.get_location() self.set_angle(atan2(y-sy,x-sx)) self.move() return eaten
def update(self): Pulsator.update( self ) #calling update on Pulsator class in order to decrease or increase the size of hunter every 30 seconds self.wall_bounce() all_Prey_obj = [x for x in model.find(lambda x: isinstance(x, Prey))] #if any of these objects is within 200 (distance_constant) # for each_object in all_Prey_obj: # if self.within_target(each_object) == True: # if there are prey objects left, compute the closest prey and angle if len(all_Prey_obj) > 0: target_prey = self.closet_prey(all_Prey_obj) self._angle = atan2(target_prey._y - self._y, target_prey._x - self._x) # tell Hunter to chase that closest Prey self.move() # remove that Prey from simulation after being eaten self.delete_eaten()
def update(self): eat = Pulsator.update(self) Mobile_Simulton.update(self) aim = model.find(lambda x: isinstance(x, Prey) and self.visible_distance(x.get_location())) if aim: first_target = min([s.get_location() for s in aim], key = lambda x: self.distance(x)) x,y = first_target self.set_angle(self.angle_to(x,y)) return eat
def update(self, m): goner = Pulsator.update(self, m) major = lambda x: self.distance(x) peaceout = m.find( lambda x: isinstance(x, Prey) and self.peace(x.get_location())) if peaceout: x, y = min([y.get_location() for y in peaceout], key=major) #x,y = p self.set_angle(self.angl(x, y)) #Hunter is instructed to move self.move() return goner
def update(self, model): eaten = Pulsator.update(self, model) seen = model.find(lambda x: isinstance(x, Prey) and self.distance( x.get_location()) <= Hunter.see_distance) if seen: min_dist, who = min([(self.distance(s.get_location()), s) for s in seen]) sx, sy = self.get_location() x, y = who.get_location() self.set_angle(atan2(y - sy, x - sx)) self.move() return eaten
def update(self, model): list_food = [] food_distance = [] Pulsator.update(self, model) for e in model.find(lambda x: isinstance(x, Prey)): if 0 <= self.distance(e.get_location()) <= 200: list_food.append(e) if list_food: for i in list_food: food_distance.append((self.distance(i.get_location()), i)) food = (sorted(food_distance))[0][1] hunt_x, hunt_y = self.get_location() food_x, food_y = food.get_location() self.set_angle(atan2(food_y - hunt_y, food_x - hunt_x)) self.move()
def update(self, model): eaten = Pulsator.update(self, model) to_eat = model.find(lambda x: isinstance(x, Prey) and self.distance( x.get_location()) <= 200) if to_eat: _, catch = min([(self.distance(i.get_location()), i) for i in to_eat]) sx, sy = self.get_location() x, y = catch.get_location() self.set_angle(atan2(y - sy, x - sx)) self.move() return eaten
def update(self,model): if not model.find(lambda x : isinstance(x,Prey) and self.distance(x.get_location()) <= Hunter.see_distance): pass elif model.find(lambda x : isinstance(x,Prey) and self.distance(x.get_location()) <= Hunter.see_distance): list_for_min = [] for i in model.find(lambda x : isinstance(x,Prey) and self.distance(x.get_location()) <= Hunter.see_distance): list_for_min.append((self.distance(i.get_location()),i)) unused,who = min(list_for_min) x,y = who.get_location() sx,sy = self.get_location() self.set_angle(atan2(y-sy,x-sx)) self.move() return Pulsator.update(self,model)
def update(self, model): targets = model.find(lambda s: isinstance(s, Prey) and self.distance( s.get_location()) <= Hunter.killzone) if len(targets) > 0: target = sorted([t for t in targets], key=lambda t: self.distance(t.get_location()))[0] x, y = self.get_location() tx, ty = target.get_location() self.set_angle(atan2(ty - y, tx - x)) self.move() return Pulsator.update(self, model)
def update(self, model): eaten_set = Pulsator.update(self, model) _range = model.find(lambda x: isinstance(x, Prey) and self.distance( x.get_location()) <= Hunter.in_range) eat_list = [] if len(_range) != 0: for s in _range: eat_list.append((self.distance(s.get_location()), s)) d, chosen_eat = sorted(eat_list)[0] x, y = chosen_eat.get_location() sim_x, sim_y = self.get_location() self.set_angle(atan2(y - sim_y, x - sim_x)) self.move() return eaten_set
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)