def reproduce(self, other, board): if self is other: print(self.debug()) print(str(other)) raise Exception('⛔ the father and the mother are the same') if self.debugging: print('⚤ ' + str(self) + ' copulates with ' + str(other)) if self.actions < 1: if self.debugging: print('☹ ' + str(self) + ' is exausted and can not repreduce') return False if other.actions < 1: if self.debugging: print('☹ ' + str(other) + ' is exausted and can not repreduce') return False if self.gender is other.gender: print(self.debug()) print(str(other)) raise Exception('⛔ Can not copulate animals with same gender') empty_cells = self.look_for_empty_cells(board) if empty_cells is None or not empty_cells: if self.debugging: print('⚠ ' + self.race.capitalize() + ' has not empty location to reproduce: ' + str(self)) return False cell = empty_cells[random.randint(0, len(empty_cells)-1)] father = self if self.gender is Genders.MALE.value else other mother = self if self.gender is Genders.FEMALE.value else other # cell division if random.randint(1, 100) <= self.mutation_probability: if self.debugging: print('⚛ child mutates!!!') color = Colors.melt(Colors, Colors.random( Colors), Colors.melt(Colors, father.color, mother.color)) size = int((father.size + mother.size)/3 * random.uniform(1 - self.mutation_factor, 1 + self.mutation_factor)) else: color = Colors.melt(Colors, father.color, mother.color) size = int((father.size + mother.size)/3 * random.uniform(1.1, 1.5)) size = min(100, max(1, size)) self.expend_action() other.expend_action() baby = self.__class__(cell.pos, father.race, color, size, None, father, mother) cell.occupy(baby) if self.debug: print('❤ New ' + baby.race.capitalize() + ' born: ' + str(cell.content))