Example #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Creature" /> class.
 /// </summary>
 /// <param name="idOfSpecies">
 ///     The id of species.
 /// </param>
 /// <param name="world">
 ///     The world.
 /// </param>
 public Creature(int idOfSpecies, World world)
 {
     Contract.Requires <ArgumentNullException>(world != null);
     Contract.Ensures(this.IdOfSpecies == idOfSpecies);
     this.IdOfSpecies = idOfSpecies;
     this.world       = world;
     for (var i = 0; i < this.genes.Length; i++)
     {
         this.genes[i] = EnumHelper.CreateRandomGene();
     }
 }
Example #2
0
        /// <summary>
        ///     Mutates creature.
        /// </summary>
        public void Mutate()
        {
            // Tries to change 6 genes with 50% probability
            var length = this.genes.Length;
            var rnd    = RandomProvider.GetThreadRandom().Next(length << 1);
            var limit  = Math.Min(length, rnd + 6);

            for (; rnd < limit; rnd++)
            {
                this.genes[rnd] = EnumHelper.CreateRandomGene();
            }
        }