From TRCCompSci - AQA Computer Science
1 private void KillByOtherFactors(bool ShowDetail)
2 {
3 int DeathCount = 0;
4 float DiseaseProb = RabbitCount * 0.1f;//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.