Exemplo n.º 1
0
    def sense(self, animal_base):
        surrounding_res = Surroundings()
        for spec in self.animals.keys():
            for animal2 in self.animals[spec]:
                animal2_dist = self.distanceToAgent(animal_base, animal2)
                if (animal2_dist < animal_base.genes.sense):
                    if Species.predator(
                            animal_base._species) == animal2._species:
                        surrounding_res.closest_predator = animal2
                        surrounding_res.closest_predator_dist = animal2_dist

                    elif Species.prey(
                            animal_base._species) == animal2._species:
                        surrounding_res.closest_prey = animal2
                        surrounding_res.closest_prey_dist = animal2_dist

        for spec in self.plants.keys():
            for plant in self.plants[spec]:
                plant_dist = self.distanceToAgent(animal_base, plant)
                if (plant_dist < animal_base.genes.sense):
                    if (surrounding_res.closest_plant is None or
                            plant_dist < surrounding_res.closest_plant_dist):
                        surrounding_res.closest_plant = plant
                        surrounding_res.closest_plant_dist = plant_dist

        return surrounding_res