Esempio n. 1
0
 def delete_being(self, being):
     """
     Lorsqu'un individu meurt, 
     il est rétiré de la map, 
     sa position dans la liste des individus est ajouté à l'ensemble,
     et change son état à mort.
     """
     self.remove_being_from_map(being)
     self.free_indexes_set.add(being.get_position_in_list())
     being.is_dead = True
Esempio n. 2
0
 def create_being(self, species, random_position, position=None):
     if random_position:
         position = np.array((np.random.rand() * self.beings_map.shape[0],
                              np.random.rand() * self.beings_map.shape[1]))
     else:
         position = position.copy()
     being = source.being.Being(species, position, self.beings_map.shape)
     if (len(self.free_indexes_set) == 0):
         being.set_position_in_list(len(self.beings_list))
         self.beings_list.append(being)
     else:
         being.set_position_in_list(self.free_indexes_set.pop())
         self.beings_list[being.get_position_in_list()] = being
     self.add_being_to_map(being)
Esempio n. 3
0
 def find_and_eat(self, being):
     for i in range(-1, 2):
         for j in range(-1, 2):
             current_cell_position = being.modify_position(
                 (i, j), self.beings_map.shape, change_position=False)
             for being_index in self.beings_map[current_cell_position]:
                 if (not self.beings_list[being_index].is_dead
                         and being.get_position_in_list() != self.
                         beings_list[being_index].get_position_in_list()
                         and self.beings_list[being_index].type_id
                         in being.edible_species_id):
                     self.eat(being, self.beings_list[being_index])
                     return True
     return False
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
0
 def delete_being(self, being):
     self.remove_being_from_map(being)
     self.free_indexes_set.add(being.get_position_in_list())
     being.is_dead = True