Difference between revisions of "Add a way for a disease to kill rabbits in warrens"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "<syntaxhighlight lang="csharp" line> private void KillByOtherFactors(bool ShowDetail) { int DeathCount = 0; float DiseaseProb = RabbitCount * 0...")
 
Line 2: Line 2:
 
         {
 
         {
 
             int DeathCount = 0;
 
             int DeathCount = 0;
             float DiseaseProb = RabbitCount * 0.1f;//the larger the rabbit population the greater the chance of disease
+
             float DiseaseProb = RabbitCount * 0.25f;//the larger the rabbit population the greater the chance of disease
 
             for (int r = 0; r < RabbitCount; r++)
 
             for (int r = 0; r < RabbitCount; r++)
 
             {
 
             {

Revision as of 14:48, 13 February 2017

 1  private void KillByOtherFactors(bool ShowDetail)
 2         {
 3             int DeathCount = 0;
 4             float DiseaseProb = RabbitCount * 0.25f;//the larger the rabbit population the greater the chance of disease
 5             for (int r = 0; r < RabbitCount; r++)
 6             {
 7                 if (Rabbits[r].CheckIfKilledByOtherFactor() || Rnd.Next(0, 100) < DiseaseProb)//adds a probability to die from disease
 8                 {
 9                     Rabbits[r] = null;
10                     DeathCount++;
11                 }
12             }
13             CompressRabbitList(DeathCount);
14             if (ShowDetail)
15             {
16                 Console.WriteLine("  " + DeathCount + " rabbits killed by other factors.");
17             }
18         }
  • L3 Adds a new variable called DiseaseProb that increases with the rabbit population
  • L7 Generates a random number and compares it to the probability of disease.