Esempio n. 1
0
        public IAnimal Birth(int sameSpeciesInCell)
        {
            if (GivenBirth)
            {
                return(null);
            }
            double probability;

            if (Weight < (Params.Zeta * (Params.BirthWeight + Params.BirthSigma)))
            {
                probability = 0.0;
            }
            else
            {
                probability = Params.Gamma * Fitness * (sameSpeciesInCell - 1);
                probability = (probability > 1) ? 1 : probability;
            }

            if (probability > rng.NextDouble())
            {
                IAnimal newborn;
                if (this.GetType().Name == "Herbivore")
                {
                    newborn = new Herbivore(rng, this.Pos);
                    newborn.Params.OverloadParameters(Params.CopyParameters()); // Inherit params from parent
                }
                else
                {
                    newborn = new Carnivore(rng, this.Pos);
                    newborn.Params.OverloadParameters(Params.CopyParameters()); // Inherit params from parent
                }
                double bWeight = newborn.Weight;
                if (bWeight >= Weight || bWeight <= 0)
                {
                    return(null);
                }
                Weight    -= Params.Xi * bWeight;
                GivenBirth = true;
                return(newborn);
            }
            return(null);
        }