Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Showcase / A Predator-Prey Simulation: Predation2110
- By josephhowse Date 2009-12-22 20:25
Some classmates and I used Gosu C++ in our term project for an algorithms and data structures course at Dalhousie University, Canada.  We designed and implemented a little Darwinian simulator, with 3 types of creatures (birds, fish, bugs) that attempt to forage, hunt and breed on a 12x12 map grid.  Birds can hunt fish or bugs, fish can hunt bugs, and bugs do not hunt.  Each map square has one of 4 terrain types: grasslands, forest, wetlands, or barren.  Several types of edible plantlife grow in each terrain type, in different amounts.  All creatures may eat plantlife.

There are initially 240 creatures with randomized characteristics, such as life expectancy, caloric requirements, age of maturity, mating cycle, gestation cycle, and efficiency in eating different types of food.  Each creature has a unique random color to help distinguish it and its descendants.  Depending on its characteristics and its current situation, a creature will choose when and where to forage, hunt, mate or flee.  Newborn creatures acquire an average of their two parents’ characteristics, adjusted by some random factor to reflect genetic mutations.  The simulation is self-running: as time passes, the user just observes and reads statistics.

Controls include Esc (quit), Space (pause/unpause), Left-Ctrl (decrease speed), Left-Alt (increase speed), Home (previous statistics), End (next statistics), PageUp (first statistics), and PageDown (last statistics).

The AI and the simulation constants are not currently fine-tuned to produce an equilibrium among the species.  Sometimes all species die, sometimes 2 of 3, and sometimes one dies while another becomes a minority surviving in a map corner.

On my test machine, the program can handle a total population (across species) of up to around 5,000.  Exponential growth sets in thereafter, and memory requirements become prohibitively high. An unanticipated outcome is that carrion becomes an important resource for sustaining a dense population.  Even though a creature is forbidden to hunt and kill a fellow member of its own species, it is not forbidden from eating the carrion of any already dead species.  Under the simulation’s current implementation, carrion is a uniform resource, not having a defined species.

The current hunting AI seldom succeeds in obtaining a kill, but it does serve to chase off members of a lesser species.  This gives the birds an advantage in monopolizing map space, and thus securing better grazing grounds.  Meanwhile, the bugs have an advantage in relying only on the foraging AI, which is more successful in securing food for the individual creature.  The middle species, fish, seems to be disadvantaged in that it both hunts and flees, so many of its actions are not conducive to successfully securing food for the individual.  A few cases of long-term bird and bug coexistence were observed, but not cases of long-term fish coexistence with another species.

I'm attaching screenshots.  A zip file of the Visual Studio 2008 project, including the exe and media files, can be found here: http://nummist.com/ncc/Predation2110.zip .  The Visual Studio 2008 project needs the usual Gosu and Boost library dependencies to compile, but the executable should run out-of-the-box on a supported platform.

Credits:

Implementation:
Joe Howse
Bruce Delo

Additional Design & Prototyping:
Ross Story
David Goodwin
Katie Brown
Up Topic Gosu / Gosu Showcase / A Predator-Prey Simulation: Predation2110

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill