April 2016
Beginner to intermediate
384 pages
8h 36m
English
One of the most famous agent-based simulations is the sheep-wolf predation example.
The model simulates two populations of animals: sheep and wolves coexisting together on a plane. Sheep move around and eat grass that grows on the plane; eating grass gives the sheep energy. Wolves predate sheep and that is how they get their energy. To move around the plane costs the animal some energy. If any animal's energy falls below 0, it dies.
In this recipe, we will build a 300-by-300 plane (grid) and populate it with 6,000 sheep and 200 wolves (initially). We will also introduce the concept of inheritance: we will create a generic Animal class and then derive Sheep and Wolf ...
Read now
Unlock full access