THRESHOLD: 2
MAX HEALTH: 10
EMPTY: 30%
PREY: 30%
SPEED: 50%

Predator and Prey Model

The model is based on the following simple rules:

Prey: Predator:

How it works

The AgentModel class creates a grid of agents, the agets can be: preys, predators or nothing.
Each frame the model is updated. First by updating the health of the agents, than they are moved. The agents can move only in the adiacent free cells, it means either up, down, left and right, Diagonal movement are not allowed. move(x, y) tries to move the agent to a random direction moveUp(x, y) moveRight(x, y) moveDown(x, y) moveLeft(x, y), if the agent finds himself at one of the edges than the move(x, y) function is called again until it can move to one of the directions.
Once the agent is moved the moveUp/Right/Down/Left(x, y) function checks wheter the neighbour was a predator in that case the prey is eaten and the predator reproduces getting the health of the eaten prey.
There are four values to change wth the slider The play button restarts the model with the new values.
With the LEFT mouse button is possible to add new predators, and with the RIGHT mouse button is possible to add new preys.
The infographic on the left side shows how many preys and predator are still alive.

Reference

Predator & Prey Model by Matthew Hopson

FORK IT HERE




< < < < < < < < < < < < < <


RESIZE THE WINDOW TO THE LEFT TO START THE MODEL