# Python Game of Rat and Berry

July 06, 2024
Prof. James
🇦🇪 United Arab Emirates
Python
Prof. James Harper is an experienced software developer and educator with a Master's degree in Computer Science from the University of Melbourne. With over 900 completed assignments, he specializes in Python programming and application development. Prof. Harper's passion for teaching and extensive industry experience ensure that his solutions are not only functional but also well-documented and easy to understand.
Key Topics
• Python Game of Rat and Berry
Tip of the day
News

## Python Game of Rat and Berry

Once upon a time, there was an island…

• The island is 10 sq km in area.
• Every day there is a 30% chance it will rain on the island.
• When it rains, the rainfall has a normal distribution with a mean of 20 mm and a standard deviation of 5 mm.
• Rain nourishes the local plant life. The day after it rains, the plants will produce berries. The number of berries produced is equal to (previous day’s rainfall in mm) * (area of the island in sq km) * (100).
• Berries persist for 10 days after which they become inedible.

On the island there were rats...

• Initially, there are 10,000 rats on the island with ages randomly chosen in the range 1 through 20 days (uniform and inclusive).
• Every day a rat will eat a berry (randomly chosen regardless of age) if one is available somewhere on the island.
• If a rat does not eat for 3 days, it dies.
• After 50 days, the rat has a 5% chance of dying from old age. This probably increases by 5% every day thereafter (e.g. 5% after 50 days, 10% after 51 days, 15% after 52 days, etc.).
• After a rat eats a total of 10 berries and every 8 berries thereafter, it will give birth to a litter of new rats. The litter size is random and uniformly distributed between 6 and 10 inclusive.

On the island, there were also cats…

• Initially, there are 1000 cats on the island with ages randomly chosen in the range of 1 through 1000 days (uniform and inclusive).
• Every day a cat will attempt to eat a rat. The probability that a cat will catch a rat is dependent on the density of rats on the island: p = (number of rats/area of the island in sq km) * 0.10. Notice that this probability should be capped at 100%.
• With experience, cats become better at catching rats. A cat receives an additive bonus to its probability of catching a rat: b = age of cat * 0.015. Again, the total probability should be capped.
• If a cat does not eat for 5 days, it dies.
• After 2000 days, the cat has a 1% chance of dying from old age. This probably increases by 0.1% every day thereafter.
• After a cat eats a total of 50 rats and every 35 rats thereafter, it will give birth to a litter of new cats.
• The litter size is random and uniformly distributed between 3 and 6 inclusive.

Then, ten thousand days later…

• Design a simulation to capture the interaction of life on the island over 10,000 days.
• Your simulation should begin by reading parameters from a parameter file. This file should include all of the numbers in marked bold above. For example…
1. island_size = 10 o rain_chance = 0.30
2. rain_mean = 20
3. rain_std = 5
4. berry_ coefficient = 100
5. berry_persist = 10 etc.

Use classes

Save to file information about the rainfall and the daily population of berries, rats, and cats.

 Subject Value island_size 10 rain_chance 0.3 rain_mean 20 berry_coefficient 100 rain_std 5 berry_persist 10 num_of_rats 10000 rat_coefficient 3 rat_range 20 rat_total_berries 10 rat_days 50 berry_after 8 uniform_dist_start 6 uniform_dist_end 10 num_of_cats 1000 max_cat_age 1000 cat_rat_catch_prob 0.1 exp_prob 0.015 cat_days_die 2000 cat_rat_eat 50 cat_rat_additional 35 litter_dist_start 50 litter_dist_end 35