Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions