def die(self, world): world.grid[world.grid.index(self)] = World.Grass(self.energy + 2) self.alive = False
new_location[1] = new_location[1] + 1 elif output == 1: new_location[1] = new_location[1] - 1 elif output == 2: new_location[0] = new_location[0] + 1 elif output == 3: new_location[0] = new_location[0] - 1 # what is in the target square? current_occupant = world.item_from_grid(new_location) if current_occupant == -1: world.grid[world.grid.index(i)] = 0 i.alive = False elif type(current_occupant) == World.Grass: i.eat(current_occupant, world) if len(world.get_type(World.Grass())) < lower_food_bound: world.place_items(World.Grass(), 1) elif type(current_occupant) == Actors.Actor: i.fight(current_occupant, world) elif world.grid[world.list_from_grid(new_location)] == 0: world.grid[world.grid.index(i)] = 0 world.grid[world.list_from_grid(new_location)] = i # 3. death if i.alive: i.age += time_since_last_tick * time_scale i.energy -= (time_since_last_tick * time_scale * living_cost) if i.energy < death_energy: i.die(world) # population top up