Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2 This is the file name you would need testif.py Write the code for this problem in a file named p 3 _ Lastname

Problem 2
This is the file name you would need testif.py
Write the code for this problem in a file named p3_Lastname_Firstname.py, as required above.
Take the prey-predator problem described in Chapter 13 and add
humans
. Start from file
program13-
14.py
, attached to the assignment page.
A human
is an animal
that kills and eats
only prey
, and also moves and breeds like an animal. Humans
do
not
kill predators.
Here are the detailed rules pertaining to humans:
A Human object moves like an Animal object on the island grid.
A Human object does not kill predators.
A Human object eats Prey objects periodically. Every Human.hunt_time clock ticks (starting with
the Human objects creation time), if a Prey is in a neighboring cell (using check_grid()), the
Human will move to its cell and remove the Prey from the island, in the same way as Predators eat
Prey objects.
A Human object starves and is removed from the island if it has not killed a Prey within a
starving time given by a Human.starve_time class attribute, initialized in main().
A Human object breeds like an Animal object, with the breeding period given by a
Human.breed_time class attribute, initialized in main().
All other rules for Prey and Predators remain in effect.
We want to study the impact of humans on the island animal populations. Add the following to the
Island class:
Proper initialization for Human objects. The constructor and
init_animals
() should take each an
extra parameter
count_humans
and
init_animals
() should position Human objects at random
positions.
A method
count_humans
() that returns the number of Human objects on the grid.
The
main
() method should:
Take extra parameters for the Human class attributes described above and should properly
initialize them.
Keep track of the Human population for each clock tick in the same ways its done for Predator
and Prey objects.
Stop the simulation after 1000 time units.
Display at the end with matplotlib the evolution in time of the Prey, Predator, and Human
populations.
Display the island grid to the terminal, at the beginning and at the end of the simulation.
More requirements:
1.
Add a Human class to the existing class hierarchy so that code is properly reused. Use the
problem description above to decide what class is Humans superclass.
2.
Use the object-oriented design process. Integrate class Human smoothly into the existing design
and code.
3.
Print a Human object on the Island grid with character H.
4.
Apply the proper coding style and techniques taught in this class.
5.
Run the program with different combinations of parameters and find an interesting case.
6.
Take a screenshot
with the matplotlib chart showing the evolution of the three populations vs.
time. Insert this screenshot in the Word document. This chart looks like that on slide 46 in the
Chapter 13 lecture notes PDF flle.
7.
Take a screenshot
with the terminal showing the island grid printout (first tick and last tick)+
any other statistics displayed in main(). Insert this screenshot in the Word document

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions