Esempio n. 1
0
    def __init__(self, races, statistics=None):
        self._creature_counter = 0
        self._races = races
        self._space = Space(ConfigPhysics.SPACE_SIZE)
        self._time = 0
        self.statistics = statistics
        for race in races:
            num_fathers = ConfigPhysics.NUM_FATHERS

            fathers_locations_i = np.random.choice(ConfigPhysics.SPACE_SIZE,
                                                   num_fathers)
            fathers_locations_j = np.random.choice(ConfigPhysics.SPACE_SIZE,
                                                   num_fathers)
            ages = np.random.randint(low=0,
                                     high=ConfigBiology.BASE_LIFE_EXPECTANCY,
                                     size=num_fathers)
            for n in range(num_fathers):
                dna = Evolution.mutate_dna(race.race_basic_dna())

                self.create_creature(race,
                                     id=self.allocate_id(),
                                     dna=dna,
                                     coord=(fathers_locations_i[n],
                                            fathers_locations_j[n]),
                                     age=ages[n],
                                     parents=None)

        self.give_food(ConfigPhysics.INITIAL_FOOD_AMOUNT)
Esempio n. 2
0
    def creature_divide(self, creature):
        if creature.age() < ConfigBiology.MATURITY_AGE:
            if creature.energy() < ConfigBiology.MOVE_ENERGY:
                self.kill_creature(creature)
                return
            creature.reduce_energy(ConfigBiology.MOVE_ENERGY)
            return

        self.create_creature(creature.get_race(),
                             self.allocate_id(),
                             dna=Evolution.mutate_dna(creature.dna()),
                             coord=creature.coord(),
                             energy=int(creature.energy() / 2) + 1,
                             parents=[creature])
        creature.reduce_energy(amount=int(creature.energy() / 2))
        creature._age = 1