Question: 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 p
3
_
Lastname
_
Firstname.py
,
as required above.
Take the prey
-
predator problem described in Chapter
1
3
and add
humans
.
Start from file
program
1
3
-
1
4
.
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 object
s 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 it
s done for Predator
and Prey objects.
Stop the simulation after
1
0
0
0
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 Human
s 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
4
6
in the
Chapter
1
3
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 plz type code to run and include the testif.py

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!