def update(self): target_set = model.find(lambda x: isinstance(x, Prey)) eaten_set = model.find( lambda x: self.contains(x) and isinstance(x, Prey)) for ball in eaten_set: model.remove(ball) alist = [(i, i.distance(self.get_location())) for i in target_set if i.distance(self.get_location()) < Special.valid_distance] alist = sorted(alist, key=lambda x: x[1]) if alist == []: self.set_speed(5) pass else: close_one = alist[0][0] y_differ = close_one.get_location()[1] - self.get_location()[1] x_differ = close_one.get_location()[0] - self.get_location()[0] new_angle = atan2(y_differ, x_differ) self.set_angle(new_angle) self.set_speed(40) self.move()
def update(self): main = set() for item in (list(model.find(Ball)) + list(model.find(Floater))): if self.contains((item._x, item._y)): main.add(item) model.removed.add(item) return main
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): #New Movement seeks = model.find(lambda ob: self.distance(ob.get_location()) < 200) #print(seeks) min = 200,None for sim in seeks: if self.distance(sim.get_location()) < min[0] and isinstance(sim, Prey): min = self.distance(sim.get_location()),sim if min != (200,None): seek = min[1] self.set_angle(atan2(seek.get_location()[1]-self.get_location()[1],seek.get_location()[0]-self.get_location()[0])) self.move() self.wall_bounce() global starvation checks = model.find(lambda ob: self.contains(ob.get_location())) destroys = set() foundPrey = False for ch in checks: if isinstance(ch, Prey): destroys.add(ch) foundPrey = True #pulsator code global starvation checks = model.find(lambda ob: self.contains(ob.get_location())) destroys = set() foundPrey = False for ch in checks: if isinstance(ch, Prey): destroys.add(ch) foundPrey = True #print(destroys) starvation -= 1 #check if shrunk if starvation == 0: self._radius -= 0.5 starvation = 30 #check if dead if self._radius == 0: return({self}) if foundPrey: starvation = 30 self._radius += 0.5 #print('returned') return destroys
def update(self,p): result = set() target = model.find(p) for value in target: if self.contains(value.get_location()): result.add(value) return result
def update(self): x = Black_Hole.update(self) if x != set(): self.change_dimension(1,1) targets_in_range = model.find(self.hunt_contains_obj) closest = None ticker = None for i in targets_in_range: if ticker == None: if self.target1 != i and self.target2 != i: ticker = self.distance(i.get_location()) closest = i else: if self.distance(i.get_location()) < ticker: if self.target1 != i and self.target2 != i: ticker = self.distance(i.get_location()) closest = i if closest != None: if self.target1 == None: self.target1 = closest self.launch_parasite(True) elif self.target2 == None: self.target2 = closest self.launch_parasite(False) self.remove_close_parasites() #print(self.get_dimension()) self.move()
def update(self): eaten = set() preys = model.find(lambda x: isinstance(x, Prey)) for s in preys: if self.contains(s.get_location()): eaten.add(s) return eaten
def update(self): if self.status != "Dead": self.move() if self.status == "Infected": self.counter += 1 if self.counter >= 10: death_rate = random.randint(1,100) if death_rate in range(1, 2): self.status = "Dead" Person.person_dict["Dead"] += 1 Person.person_dict["Infected"] -= 1 elif death_rate in range(94, 100): self.status = "Recovered" Person.person_dict["Recovered"] += 1 Person.person_dict["Infected"] -= 1 self.set_color() self.counter = 0 elif self.status == "Healthy": my_set = model.find(lambda x: self.contains((x._x, x._y)) and x.status == "Infected") if len(list(my_set)) != 0: self.status = "Infected" self.set_color() Person.person_dict["Healthy"] -= 1 Person.person_dict["Infected"] += 1
def update(self): blackhole_can_eat = model.find(lambda temp: isinstance(temp, Prey) and temp.contains((self._x, self._y))) for each in blackhole_can_eat: model.remove(each) return blackhole_can_eat
def update(self): eaten_1= model.find(lambda x:isinstance(x, Prey)) eaten=set() for i in eaten_1: if self.contains(i.get_location()): eaten.add(i) for i in eaten: model.remove(i) return eaten
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): eaten = set() for item in model.find(Prey): if self.contains(item.get_location()): if type(item)==Special: model.things = set([i for i in model.things if i != self]) else: model.things = set([i for i in model.things if i != item]) eaten.add(item) return eaten
def update( self): #,model):#:,model):# model): #,model):#, model): #,model): #variable = 10 # self.set_location(self._new_x, self._new_y) #v = ((self._new_x, self._new_y)) new_items = model.find( lambda u: isinstance(u, Prey) and self.contains(u.get_location())) for x in new_items: model.remove(x) return new_items
def update(self): Ball.update(self) def p(arg): return isinstance(arg, Black_Hole) and self.distance(arg.get_location()) <= 50 dangerous = model.find(p) if len(dangerous) != 0: nearest = list(dangerous)[0].get_location() for i in dangerous: if self.distance(i.get_location()) < self.distance(nearest): nearest = i.get_location() self.set_angle(atan2(self._y-nearest[1], self._x-nearest[0]))
def update(self): eaten = set() def p(arg): return isinstance(arg, Prey) and self.contains(arg) eatable = model.find(p) for i in eatable: model.remove(i) eaten.add(i) return eaten
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): 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): checks = model.find(lambda ob: self.contains(ob.get_location())) destroys = set() foundPrey = False for ch in checks: if isinstance(ch, Prey): destroys.add(ch) foundPrey = True #print(destroys) if foundPrey: #print('returned') return destroys
def infect(self): location = self.get_location() temp = model.find( lambda x: x.distance(location) < Special.infection_range if x != self and isinstance(x, Prey) else False) infected = set() for i in temp: if random.randrange( 0, Special.infection_range) >= i.distance(location): infected.add(i) obj = Special(i._x, i._y, i, self.genes) infected.add((obj, 'add')) return infected
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): self.move() self.wall_bounce() if not self._infected: for item in model.find(Phage): if self.contains(item.get_location()): model.things = set([i for i in model.things if i != item]) self.infected(item) if self._infected: if self._infection_timer == 0: self.lyse() else: self._infection_timer -= 1
def update(self): self.counter += 1 target_set = model.find(lambda x: isinstance(x, Prey)) alist = [(i, i.distance(self.get_location())) for i in target_set if i.distance(self.get_location()) < Hunter.valid_distance] alist = sorted(alist, key=lambda x: x[1]) if alist == []: pass else: close_one = alist[0][0] y_differ = close_one.get_location()[1] - self.get_location()[1] x_differ = close_one.get_location()[0] - self.get_location()[0] new_angle = atan2(y_differ, x_differ) self.set_angle(new_angle) eaten_set = model.find( lambda x: self.contains(x) and isinstance(x, Prey)) for ball in eaten_set: model.remove(ball) if len(eaten_set) != 0: self.change_dimension(len(eaten_set), len(eaten_set)) self.counter = 0 else: if self.counter == Pulsator.counter_constant: self.change_dimension(-1, -1) self.counter = 0 if self.get_dimension() == (0, 0): model.remove(self) self.move()
def remove_close_parasites(self): all_parasites = model.find(self.is_parasite) for i in all_parasites: if self.distance(i.get_location()) <= self._width/2: #print(i.immunity) if i.immunity == False: #print('removing') ######################## model.remove(i) if i.target == self.target1: self.target1 = None elif i.target == self.target2: self.target2 = None if i.success == True: self.change_dimension(1,1)
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): self._pulse_count += 1 inside = model.find(lambda x: self.contains(x.get_location()) and isinstance(x, Prey)) for i in inside: model.remove(i) if len(inside) > 0: self._width += len(inside) self._height += len(inside) self._pulse_count = 0 if self._pulse_count == Pulsator.shrink_timer: self._height -= 1 self._width -= 1 self._pulse_count = 0 if self._width == 0: model.remove(self)
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): 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) 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): 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): temp = model.find(lambda o: o != None) if self.check == True: if self.target not in temp and self.immunity == True: self.immunity = False self.success = False self.check = False if self.immunity == True and self.target in temp: self._angle = atan2((self.target.get_location()[1] - self._y), (self.target.get_location()[0] - self._x)) if self.distance(self.target.get_location()) <= 5: model.remove(self.target) self.immunity = False self.check = False else: self._angle = atan2((self.mothership.get_location()[1] - self._y), (self.mothership.get_location()[0] - self._x)) self.move()
def update(self): self.coory = Simulton.get_dimension(self) if self.coory[0] == 0: model.removed.add(self) else: self.move() Black_Hole.update(self) current = 501 chase = 0 for b in model.find(special.Special): coord = (b._x, b._y) leng = math.hypot(coord[0]-self._x, coord[1]-self._y) if leng<500: if leng<current: current=leng chase = b if chase != 0: self._angle = math.atan2(chase._y-self._y, chase._x-self._x)
def update(self): #,model): new_list = [] m = Pulsator.update(self) # self.set_location(self._new_x, self._new_y) # v = ((self._new_x, self._new_y)) # new_thing = model.find(lambda u : isinstance(u,Prey) and self.distance(u.get_location()) <= 200)#.contains((v))) new_thing = model.find(lambda object: self.distance( object.get_location()) <= 200 and isinstance(object, Prey)) if new_thing: for x in new_thing: new_list.append((self.distance(x.get_location()), x)) new = min(new_list) first = self.get_location() second = new[1].get_location() first_variable = second[1] - first[1] second_variable = second[0] - first[0] self.set_angle(atan2(first_variable, second_variable)) self.move() return m
def update(self): possible_prey = model.find(lambda temp: isinstance(temp, Prey)) chosen_target = None if possible_prey: chosen_target = min( possible_prey, key=lambda temp: self.distance(temp.get_location() ) <= Hunter.max_distance) if chosen_target != None: self.set_angle( atan2(chosen_target.get_location()[1] - self.get_location()[1], chosen_target.get_location()[0] - self.get_location()[0])) self.move() self.wall_bounce() return Pulsator.update(self)
def host_reproduce(self): temp = model.find(lambda x: self.host.contains(x.get_location( )) if x != self and ((isinstance(x, Special) and type(x.host) == type( self.host)) or isinstance(x, type(self.host))) else False) result = set() for i in temp: obj = None if isinstance(i, Special): if i.host and not i.reproduced: h = type(i.host)(i._x, i._y) if random.randrange( 0, 2) else type(self.host)(i._x, i._y) obj = Special(i._x, i._y, h, self.gene_reform(self.genes, i.genes)) i.reproduced = True i.counter += 10 else: obj = Special(i._x, i._y, i, self.gene_reform(self.genes)) result.add(i) if obj: result.add((obj, 'add')) return result
def update(self): mw,mh = model.world() if (self._x-self._width) < 0: model.removed.add(self) elif (self._x+self._width) > mw: model.removed.add(self) if (self._y-self._height) < 0: model.removed.add(self) elif (self._y+self._height) > mh: model.removed.add(self) else: self.move() main = set() for item in model.find(special3.Hunter2): if self.contains((item._x, item._y)): main.add(item) item.shrink() model.removed.add(self) break return main
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): eaten = model.find(lambda x: isinstance(x, Prey) and self.contains(x)) for e in eaten: model.remove(e) return eaten