Beispiel #1
0
        /// <summary>
        /// Find whether or not the plant is currently toxic. Toxicity can change
        /// and is a semi-random property.
        /// The plant is toxic with probability (t/100) * (a/50), where:
        ///     t: toxicity factor of the plant, determined upon creation,
        ///     100: the maximum toxicity factor of a plant,
        ///     a: the age of the plant,
        ///     50: the maximum age of a plant.
        /// </summary>
        /// <returns>True if the plant is toxic, false otherwise.</returns>
        public bool IsToxic()
        {
            // Calculate the toxicity probability according to the formula above
            double prob = (((double)ToxicityFactor) / TOXICITY_FACTOR_UPPER_BOUND) *
                          (((double)Age) / Senescence);

            // Use the probability to determine whether the plant is toxic or not
            return(ProbabilityHelper.EvaluateIndependentPredicate(prob));
        }
Beispiel #2
0
        /// <summary>
        /// Checks if the unit should increase in age. This is probabilistic. A Unit
        /// cannot age past its age of senescence.
        /// </summary>
        /// <remarks>
        /// Author: Tiffanie Truong
        /// </remarks>
        /// <param name="gameEnv"></param>
        /// <returns>True if the Unit should age, false otherwise.</returns>
        private bool ShouldAge(Environment gameEnv)
        {
            // Calculate the probability that the Unit should age
            double ageProbability = AgeProbability(gameEnv);

            // If the Unit's age is at its max, do not age
            if (Age == Senescence)
            {
                return(false);
            }
            // Otherwise, probabilistically determine if it should age based on its conditions
            return(ProbabilityHelper.EvaluateIndependentPredicate(ageProbability));
        }
Beispiel #3
0
 /// <summary>
 /// Determines if the unique environmental event begins in the environment
 /// </summary>
 /// <returns> True if the environmental event begins and false otherwise </returns>
 public bool EventStarts()
 {
     // Probabilistically evaluate whether the event should occur in order to initiate it
     if (ProbabilityHelper.EvaluateIndependentPredicate(PROBABILITY_OF_ENV_EVENT / 100.0))
     {
         // Indicate that the environmental event will begin occurring for the next 5 generations
         EnvEventOccurring    = true;
         EventGenerationsLeft = 5;
         return(true);
     }
     // If the probability fails, the event does not start
     return(false);
 }
Beispiel #4
0
 /// <summary>
 /// Determines if it starts raining in the environment
 /// </summary>
 /// <returns> True if it starts raining in the environment and false otherwise </returns>
 public bool WillRain()
 {
     // Probabilistically evaluate whether it will rain in order to initiate raining
     if (ProbabilityHelper.EvaluateIndependentPredicate(probabilityOfRain / 100.0))
     {
         // Indicate that it is raining for the next 5 generations
         IsRaining            = true;
         EventGenerationsLeft = 5;
         return(true);
     }
     // If the probability fails, it does not start raining
     return(false);
 }
Beispiel #5
0
        /// <summary>
        /// Compute which Multicellular type a Colony should merge into: Plant or Animal.
        /// This is probabilistically based on the atmosphere of the Environment:
        /// The more carbon dioxide in the atmosphere, the more likely it is for a Plant to be formed.
        /// </summary>
        /// <remarks>
        /// Author: Rudy Ariaz
        /// </remarks>
        /// <param name="gameEnv">The Environment of the Colony.</param>
        /// <returns>Enums.Animal if an Animal should be formed upon merging, Enums.Plant if a Plant
        /// should be formed upon merging.</returns>
        private Enums.UnitType GetMergeType(Environment gameEnv)
        {
            // The probability to merge into a plant is the normalized percentage
            // of the atmosphere that is carbon dioxide
            double plantProbability = gameEnv.CarbonDioxideLevel / 100.0;

            // Check if a Plant should be formed
            if (ProbabilityHelper.EvaluateIndependentPredicate(plantProbability))
            {
                // Return Plant as the type of Multicellular organism to be formed
                return(Enums.UnitType.Plant);
            }
            // Otherwise, an Animal should be formed
            else
            {
                // Return Animal as the type of Multicellular organism to be formed
                return(Enums.UnitType.Animal);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Determine whether the LivingUnit is cured of infection.
 /// </summary>
 /// <remarks>
 /// Author: Rudy Ariaz
 /// </remarks>
 /// <returns>True if the LivingUnit is cured, false otherwise.</returns>
 protected bool IsCured()
 {
     // Evaluate whether the Unit is cured or not, depending on the cure probability
     return(ProbabilityHelper.EvaluateIndependentPredicate(CureProbabillity()));
 }