Exemplo n.º 1
0
 /// <summary>
 /// Adds or updates the mutation going to the creature with the given id with the given chance.
 /// </summary>
 /// <param name="id">The id to add or update.</param>
 /// <param name="chance">The chance this creature will produce a creature with the given id.</param>
 public void AddMutation(int id, double chance)
 {
     if (MutationChances.ContainsKey(id))
     {
         MutationChances[id] = chance;
     }
     else
     {
         MutationChances.Add(id, chance);
     }
 }
Exemplo n.º 2
0
 public static bool DoMutation(this Random rand, MutationType type)
 {
     return(rand.NextDouble() <= MutationChances.GetChanceFor(type));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a random number used to determine if the creature mutates or replicates perfectly.
        /// </summary>
        /// <returns>The roll for mutation.</returns>
        private double GetRollForMutation()
        {
            var maxValue = MutationChances.Sum(item => item.Value) + ReplicationChance;

            return(RandomGenerator.NextDouble() * maxValue);
        }