<commit_before># -*- coding: utf8 -*-
#
# Defines the creatures class. It implements the storage and
# access to the basic features of our creatures. They are:
#    > gender (init=distribution)
#    > alive (init=true)
#    > age (init=distribution or 0)
#    > offspring (init=0)
#    > fertility (init=distribution)
#
# Two subclasses inherit from the main 'Creature' class, 'Moth'
# and 'Fly'. Only those subclasses are used on the world, never
# a generalized creature (instance of the 'Creature' class).

import numpy as np


class Creature:

    # defines a static universe, common to all creatures. It is initialized
    # at the same time the world is initialized.
    universe = None

    # a new creature is created.
    # we set the:
    #    - gender (with a uniform distribution specified by the universe)
    #    - fertility (same as above)
    #    - lifespan (yes, we say how much the creature will live when its
    #      born. Determinism rulez)
    #    - age (coming in as an argument, will be zero most of the time
    #      (for the newborn creatures) except the world initialization,
    #      where the ages might be different).
    #    - alive (control variable to know if a creature is alive or not)
    def __init__(self, gen, age=0):
        self.gender = 'm' if (np.random.uniform() < self.universe.mf_ratio[type(self)]) else 'f'
        self.fertility = True if (np.random.uniform() < self.universe.fertility_ratio[type(self)]) else False
        self.lifespan = max([1, int(np.round(np.random.normal(loc=self.universe.lifespan_mean[type(self)],
                                                              scale=self.universe.lifespan_var[type(self)])))])
        self.age = age
        self.alive = True
        self.generation = gen
        self.offspring = 0

    # uses the age of consent defined at the universe to decide
    # if the creature is an adult.
    #
    # Returns a boolean value:
    #    - True, if it is an adult
    #    - False, if its not
    def is_adult(self):
        return self.age >= self.universe.adult_age[type(self)]

    #
    # Returns a boolean value:
    #    - True, if it is an egg
    #    - False, if its not
    # In particular, for the flies, egg_period ~ larvae_period
    def is_egg(self):
        return self.age <= self.universe.egg_age[type(self)]

    # Checks gender-related information and returns a boolean value
    # that indicates whether the creature can procreate or not:
    #    - True, if it can procreate
    #    - False, if not
    def can_procreate(self):
        return (self.gender == 'f') and self.fertility

    # Returns a list of children with the same type as its parent (either
    # Fly or Moth, one of the subclasses).
    def children(self, gen):
        ncs = max([0, int(np.round(np.random.normal(loc=self.universe.offspring_mean[type(self)],
                                                    scale=self.universe.offspring_var[type(self)])))])
        return [type(self)(gen=gen, age=0) for _ in range(ncs)]

    # increments the current age
    def increment_age(self):
        self.age = self.age + 1

    # kills the creature
    def kill(self):
        self.alive = False
<commit_msg>Added a verification to count a creature as adult only if its alive (method is_alive())<commit_after># -*- coding: utf8 -*-
#
# Defines the creatures class. It implements the storage and
# access to the basic features of our creatures. They are:
#    > gender (init=distribution)
#    > alive (init=true)
#    > age (init=distribution or 0)
#    > offspring (init=0)
#    > fertility (init=distribution)
#
# Two subclasses inherit from the main 'Creature' class, 'Moth'
# and 'Fly'. Only those subclasses are used on the world, never
# a generalized creature (instance of the 'Creature' class).

import numpy as np


class Creature:

    # defines a static universe, common to all creatures. It is initialized
    # at the same time the world is initialized.
    universe = None

    # a new creature is created.
    # we set the:
    #    - gender (with a uniform distribution specified by the universe)
    #    - fertility (same as above)
    #    - lifespan (yes, we say how much the creature will live when its
    #      born. Determinism rulez)
    #    - age (coming in as an argument, will be zero most of the time
    #      (for the newborn creatures) except the world initialization,
    #      where the ages might be different).
    #    - alive (control variable to know if a creature is alive or not)
    def __init__(self, gen, age=0):
        self.gender = 'm' if (np.random.uniform() < self.universe.mf_ratio[type(self)]) else 'f'
        self.fertility = True if (np.random.uniform() < self.universe.fertility_ratio[type(self)]) else False
        self.lifespan = max([1, int(np.round(np.random.normal(loc=self.universe.lifespan_mean[type(self)],
                                                              scale=self.universe.lifespan_var[type(self)])))])
        self.age = age
        self.alive = True
        self.generation = gen
        self.offspring = 0

    # uses the age of consent defined at the universe to decide
    # if the creature is an adult.
    #
    # Returns a boolean value:
    #    - True, if it is an adult
    #    - False, if its not
    def is_adult(self):
        return (self.age >= self.universe.adult_age[type(self)]) and (self.is_alive())

    #
    # Returns a boolean value:
    #    - True, if it is an egg
    #    - False, if its not
    # In particular, for the flies, egg_period ~ larvae_period
    def is_egg(self):
        return self.age <= self.universe.egg_age[type(self)]

    # Checks gender-related information and returns a boolean value
    # that indicates whether the creature can procreate or not:
    #    - True, if it can procreate
    #    - False, if not
    def can_procreate(self):
        return (self.gender == 'f') and self.fertility

    # Returns a list of children with the same type as its parent (either
    # Fly or Moth, one of the subclasses).
    def children(self, gen):
        ncs = max([0, int(np.round(np.random.normal(loc=self.universe.offspring_mean[type(self)],
                                                    scale=self.universe.offspring_var[type(self)])))])
        return [type(self)(gen=gen, age=0) for _ in range(ncs)]

    # increments the current age
    def increment_age(self):
        self.age = self.age + 1

    # kills the creature
    def kill(self):
        self.alive = False

{'fraction_non_alphanumeric': 0.09852443897940363, 'fraction_numerical': 0.0027666769136181985, 'mean_word_length': 2.428345626975764, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2532667', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1866, 'n_words': 690}