Skip to content

Two-dimensional predator-prey simulation in C++

License

Notifications You must be signed in to change notification settings

lcary/doodlebug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

doodlebug

Project inspired by Walter Savitch's 2014 C++ textbook. This program essentially answers Chapter 16, Question #9 of Problem Solving with C++ (ninth edition).

Overview

The goal for this project is to create a simple two-dimensional predator-prey simulation. In this simulation the prey are ants and the predators are doodlebugs. These critters live in a world composed of a 2D grid of cells. Only one critter may occupy a cell at a time. The grid is enclosed, so a critter is not allowed to move off the edges of the world. Time is simulated in time steps. Each critter performs some action every time step. 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.

Usage

Run make run to build and run the C++ program, starting the simulation.

% make run
Grid created.
Creating organisms...
total # of doodlebugs: 5
total # of ants: 100
o - - - o - - - - o - - - - - o o - o -
- - o o - - - - - - - X - - - - o - - -
- o o - - - - - - - - - o o o - - o - -
- o o - o - - - o - - - - - o - - - - o
o o - - - - - o - - - - o - - - - - - -
o o - X X - - - - - o - o - - o o - o -
- - o - - - - o - - o o - - o - - - o -
o - - - - - - - - - - - - - o - - - - o
- - - o - - - - - o - - - - - - - - - -
- - - - - - - - o - - o - - - - - - - -
- - o - - o - - - o o - - - - o - o o o
- - - - - o - - - - - - - o - - - o o o
- - - - - - o - o - - - o - o - - - - -
o - - - - - - o o - - - o X - - o - - -
o - o - o - - - - - - - - - - o - - o -
- - - o - - - - - o o o o o o o - o - o
- o - - - - - - - - - - o - - - o - - -
- - - - - - - - - - - - o - - o - - - o
o o - o - o o - o - - - - o - - X o o -
- o - - - o - o - - - - - - - - - - - -

...

Graph

Run make graph to show a graph of the organism counts over a given number of iterations.

organism count graph

About

Two-dimensional predator-prey simulation in C++

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published