Question: Write a Python class to simulate an ecosystem containing two types of creatures, bears and fish. The ecosystem consists of a river, which is modeled

Write a Python class to simulate an ecosystem containing two types of creatures, bears and fish. The ecosystem consists of a river, which is modeled as a relatively large list. Each element of the list should be a Bear object, a Fish object, or None. In each time step, based on a random process, each animal either attempts to move into an adjacent list location or stay where it is. If two animals of the same type are about to collide in the same cell, then they stay where they are, but they create a new instance of that type of animal, which is placed in a random empty (i.e., previously None) location in the list. If a bear and a fish collide, however, then the fish dies (i.e., it disappears). Write an initializer for the ecosystem class, the initializer should allow the user to assign the initial values of the river length, the number of fishes and the number of bears. Before the simulation, fishes and bears should be allocated randomly into the river. The ecosystem class should also contain a simulation() method, which will simulate the next N steps of the random moving process. N should be inputted by the user. In each step of your simulation, all animals in the river should try to take some random moves. For example, assume that before the simulation, the initial state of the river is: NNFNNNBNBNN In which, F, B and N denote fish, bear and empty location respectively. Assume that in the first step of simulation, the first fish will move to the left, the first bear will move to the right, and the second bear will remain still. Then after the first step, the state of the river is: NFNNNNNBBNN

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!