Пример #1
0
        /// <summary>
        /// Returns the species that results if an animal of this species breeds
        /// with an animal of the given other species.
        /// </summary>
        /// <remarks>
        /// This may create a new species. If this happens, the new species is added
        /// to <c>allSpecies</c>.
        /// </remarks>
        /// <returns>
        /// The resulting species.
        /// </returns>
        /// <param name='other'>
        /// An other species.
        /// </param>
        /// <param name='allSpecies'>
        /// All species.
        /// </param>
        /// <param name='rand'>
        /// Random number generator to be used.
        /// </param>
        public Species BreedWith(Species other, SpeciesManager allSpecies, Random rand)
        {
            // Comparision by object identity is intentional!
            if (other == this)
            {
                return(this);
            }

            if (rand.NextDouble() <= _mutationProbability)
            {
                return(allSpecies.GetRandomSpecialSpecies(rand));
            }

            // Create a new species that is a combination of the both breeding species
            Species newSpecies = new Species(Name + other.Name);

            newSpecies._food             = Mutate(_food, other._food, rand);
            newSpecies._preys            = Mutate(_preys, other._preys, rand);
            newSpecies._enemies          = Mutate(_enemies, other._enemies, rand);
            newSpecies._breedingPartners = Mutate(_breedingPartners, other._breedingPartners, rand);

            allSpecies.Add(newSpecies);
            return(newSpecies);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Jantu.DataManager"/> class
 /// from serialized data.
 /// </summary>
 /// <param name='info'>
 /// Info.
 /// </param>
 /// <param name='ctx'>
 /// Context.
 /// </param>
 public DataManager(SerializationInfo info, StreamingContext ctx)
 {
     _foodKinds = (FoodKindManager)info.GetValue("FoodKinds", typeof(FoodKindManager));
     _species   = (SpeciesManager)info.GetValue("Species", typeof(SpeciesManager));
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Jantu.DataManager"/> class.
 /// </summary>
 public DataManager()
 {
     _foodKinds = new FoodKindManager();
     _species   = new SpeciesManager();
 }