def breed(self): neighbor_space = choose_empty_neighbor(self.location) if neighbor_space: self.surrounded = False self.energy = self.energy - self.breed_energy g.creatures[neighbor_space] = bud(self, loc=neighbor_space) # try to breed sexually - look for a mate in a neighboring loc # mate_space = choose_specific_neighbor(self.location, SimPlant) else: self.surrounded = True
def step(self): self.energy = min(self.energy + 1, 40) if self.energy > 20: neighbor_space = choose_neighbor(self.location) if neighbor_space and space_empty(neighbor_space): self.energy = self.energy - 20 mate_space = choose_neighbor(self.location) if space_empty(mate_space): g.creatures[neighbor_space] = bud( self, loc=neighbor_space) elif type(g.creatures[mate_space]) == self.__class__: g.creatures[neighbor_space] = breed( self, g.creatures[mate_space], loc=neighbor_space)
def step(self): self.energy -= 2 self.age = self.age + 1 if self.energy <= 0 or self.age > 300: kill(self.location) return neighbor_space = choose_neighbor(self.location) neighbor = g.creatures.get(neighbor_space) if neighbor: if type(neighbor) == SimPlant: color_similarity = compare_color([self.r, self.g, self.b], [neighbor.r, neighbor.g, neighbor.b]) if random.random() < color_similarity: self.energy = self.energy + neighbor.energy kill(neighbor_space) neighbor = None elif type(neighbor) == self.__class__: might_have_space = True while self.energy > 70 and might_have_space: child_space = find_or_make_empty_space( self.location, victims=[SimPlant]) if child_space: self.energy = self.energy - 20 g.creatures[child_space] = breed( self, neighbor, loc=child_space) else: might_have_space = False if not neighbor: # either was empty or got eaten. old_loc = self.location self.location = neighbor_space g.creatures[neighbor_space] = self del g.creatures[old_loc] self.energy = min(200, self.energy) if self.energy == 200: # SOO MUCH ENERGY! GONNA BUD child_space = find_or_make_empty_space(self.location, victims=[SimPlant]) if child_space: g.creatures[child_space] = bud(self, loc=child_space) self.energy == 100
def step_subclass(self): self.energy -= self.metabolism self.age = self.age + 1 if self.energy <= 0 or self.age > self.max_age: kill(self.location) return neighbor_space = choose_neighbor(self.location) neighbor = g.creatures.get(neighbor_space) if neighbor: if type(neighbor) == SimPlant: color_similarity = compare_color([self.h, self.s, self.l], [neighbor.h, neighbor.s, neighbor.l]) eat_chance = chance_to_eat([self.h, self.s, self.l], [neighbor.h, neighbor.s, neighbor.l]) if random.random() < eat_chance: self.energy = self.energy + neighbor.energy * color_similarity self.energy = min(self.max_energy, self.energy) kill(neighbor_space) neighbor = None elif type(neighbor) == self.__class__: if self.energy > self.min_breed_energy: child_space = find_or_make_empty_space( self.location, victims=[SimPlant]) if child_space: self.energy = self.energy - self.breed_energy_loss g.creatures[child_space] = breed( self, neighbor, loc=child_space) if not neighbor: # either was empty or got eaten. # move there self.move(neighbor_space) if self.energy > self.min_bud_energy: # SOO MUCH ENERGY! GONNA BUD child_space = find_or_make_empty_space(self.location, victims=[SimPlant]) if child_space: g.creatures[child_space] = bud(self, loc=child_space) self.energy == self.energy - self.bud_energy_loss