Create a predator-prey simulation in a two-dimensional


Project Description: The goal for this programming project is to create a Predator-Prey Simulation in a two-dimensional ecosystem based on agent-based modeling. The Predator and Prey will act as agents in an ecosystem in this simulation.

The ecosystem should be modeled as an N x N grid of cells. Only one prey can occupy a cell at a time. The grid is enclosed, so a prey always stays inside the grid of cells. A prey is not allowed to move outside of the eco-system.

Time is simulated in time steps. Each prey and predator agent performs some action in every time step.

The Prey follows the following rules at each time step:

• Move: Every time step, randomly try to move up, down, left, or right. If the cell in the selected direction is occupied or would move the prey off the grid then the prey stays in the current cell.

• Breed. If a prey survives for three time steps, then at the end of the third time step (i.e., after moving), the prey will breed. This is simulated by creating a new prey in an adjacent (up, down, left, or right) cell that is empty. If there is no empty cell available, no breeding occurs. Once an offspring is produced, the prey cannot produce an offspring until three more time steps have elapsed.

A Predator behaves according to the following model:

• Move. Every time step, if there is an adjacent cell (up, down, left, or right) occupied by a prey, then the predator will move to that cell and eat the prey. Otherwise, the predator moves according to the same rules as the prey. Note that a predator cannot eat other predator objects.

• Breed. If a predator survives for eight time steps, then at the end of the time step, it will spawn off a new predator in the same manner as the prey.

• Starve. If a predator has not eaten a prey within the last three time steps, then at the end of the third time step, it will starve and die. The predator should then be removed from the grid of cells. During one turn, all the predators should move before the preys.

Before the simulation begins, the initial positions of all Preys should be randomly assigned first. Then the initial positions of the Predators should be assigned next. Note that the Simulation stops when the number of time steps ends or when one or both species population become zero.

Implement a java GUI that will allow the user to interact with the system. A suggested GUI is given below. User should be able to enter the following through the GUI:

Initial Predator count

Initial Prey count

No. of row cells in the ecosystem

No. of column cells in the ecosystem

No. of time steps.

The user clicks the "Simulate" Button and this should run the simulation. Once the simulation is over, a separate window should be shown that shows how the population of predator and prey with respect to time (x-axis: time and y-axis: No. of predator and prey).

Most likely, you should see a cyclical pattern between the population of predators and prey, although random perturbations may lead to the elimination of one or both species.

The GUI should also have a button ("Positions") which when clicked will simply print to the console the grid of cells as ASCII characters (‘x': if cell is occupied by a Predator, ‘o': if cell is occupied by a Prey, and ‘.' If cell is empty).

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Create a predator-prey simulation in a two-dimensional
Reference No:- TGS02902750

Expected delivery within 24 Hours