Ejemplo n.º 1
0
 def iterate_being(self, being):
     """
     Fonction qui itère un individu de l'état n à l'état n+1.
     """
     being.age += 1
     if being.age >= being.life_duration:
         self.stats["died_of_old_age"][being.type_id] += 1
         self.delete_being(being)
         return
     if being.reproduction_current_cooldown > 0:
         being.reproduction_current_cooldown -= 1
     if being.is_plant():
         being.satiation += max(
             1 / self.plant_count_map[being.get_int_position()] - 0.3, 0)
     else:
         being.satiation -= 1
         if self.decease_iteration(being):
             return
     if (being.satiation <= 0):
         self.stats["died_of_hunger"][being.type_id] += 1
         self.delete_being(being)
         return
     if (being.satiation < being.hunger_threshold and not being.is_plant()):
         if self.find_and_eat(being):
             return
         else:
             if self.move_towards_prey(being):
                 return
     if (being.satiation > being.reproduction_threshold
             and being.reproduction_current_cooldown <= 0):
         self.reproduction(being)
     if not being.is_plant():
         self.move_being(being)
Ejemplo n.º 2
0
 def reproduction(self, being):
     being.reproduction_current_cooldown = being.reproduction_cooldown * (
         np.random.rand() + 0.5)
     being.satiation /= 2
     if being.is_plant():
         self.create_being(being.get_species(), True)
     else:
         position = being.get_position() + np.random.rand(2) - 0.5
         self.create_being(being.get_species(), False, position=position)
Ejemplo n.º 3
0
 def eat(self, being, prey):
     """
     lorsqu'un individu mange une proie, il ingurgite la moitié de son niveau de satiation.
     La moitié est arbitraire ici. On ne prend que la moitié pour éviter une croissance trop importante des espèces prédateurs.
     On <delete_being> la proie
     """
     being.satiation += prey.satiation
     self.delete_being(prey)
     if not being.is_plant():
         self.stats["eaten"][prey.type_id] += 1
Ejemplo n.º 4
0
 def iterate_being(self, being):
     if being.reproduction_current_cooldown > 0:
         being.reproduction_current_cooldown -= 1
     if being.is_plant():
         being.satiation += max(
             1 / self.plant_count_map[being.get_int_position()] - 0.3, 0)
     else:
         being.satiation -= 1
     if (being.satiation <= 0):
         self.delete_being(being)
         return
     if (being.satiation < being.hunger_threshold and not being.is_plant()):
         if self.find_and_eat(being):
             return
         else:
             if self.move_towards_prey(being):
                 return
     if (being.satiation > being.reproduction_threshold
             and being.reproduction_current_cooldown <= 0):
         self.reproduction(being)
     if not being.is_plant():
         self.move_being(being)
Ejemplo n.º 5
0
 def add_being_to_map(self, being):
     self.beings_map[being.get_int_position()].add(
         being.get_position_in_list())
     if being.is_plant():
         self.plant_count_map[being.get_int_position()] += 1
Ejemplo n.º 6
0
 def remove_being_from_map(self, being):
     self.beings_map[being.get_int_position()].remove(
         being.get_position_in_list())
     if being.is_plant():
         self.plant_count_map[being.get_int_position()] -= 1