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...")
 
 
(2 intermediate revisions by the same user not shown)
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++)
 
             {
 
             {
Line 18: Line 18:
 
         }
 
         }
 
</syntaxhighlight>
 
</syntaxhighlight>
* L3 Adds a new variable called DiseaseProb that increases with the rabbit population
+
* L4 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.
 
* L7 Generates a random number and compares it to the probability of disease.
 +
So for example if there were 100 rabbits there would be a 25% chance for one to die from disease

Latest revision as of 15:13, 13 March 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         }
  • L4 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.

So for example if there were 100 rabbits there would be a 25% chance for one to die from disease