Coder Social home page Coder Social logo

predatorprey's Introduction

About

Predator&Prey is a little OpenGL game that shows emergent behaviour of independent agents. In particular, it showcases herding of groups of animals, ala the boid model, in the presence of predators.

The behaviour is not hardwired. Rather, the agents follow a simple set of rules (using a built-in rules scripting engine), letting the patterns in their behaviour emerge naturally.

There are two agents in the world:

  • Blue Prey: graze leisurely; want to stay near each other; run away from predators.
  • Red Predators: wander around; if hungry go hunting; if exhausted or well-fed, go to sleep.

screenshot

Another, less visible but equally cool feature is the simulation itself. Rendering (as in frames per second, FPS) is completely decoupled from the agent's AI thinking (builds per second, BPS). You can render at 80 FPS, but still have the agents process their environment only once per second (or vice versa).

Also the simulation time is independent of the "real" time (your wall clock), so you can arbitrarily slow down/accelerate the simulation, or even freeze it.

Pro Tip

View the world directly from above, zoom out and keep pressing 0 (random world reset) until you get a world with no predators. Then increase the simulation speed to 1.0 and just watch the hordes of prey roam the world, making it barren (the grass they eat doesn't grow back).

The boid model is just mesmerizing. I could watch it for hours :)

prey roam

Controls

1: decrease the rendering speed (default is 60 FPS, minimum 0 FPS)

2: increase FPS

3: decrease the build speed (default 40 BPS, min 0 BPS)

4: increase BPS

5: decrease simulation speed (default 0.3; minimum 0.0)

6: increase simulation speed

0: reset the world (random size, mountains, number of prey&predators)

mouse: change view+zoom in/out

esc: exit the application

Install

Under Linux or OS X, just type make. Make sure you have the OpenGL Utility Toolkit installed (OS X has it by default, in some Linuxes you have to apt-get install libglut3-dev or equivalent).

Under Windows, either use the VS project files in folder build_windows or just run the already-compiled executable there. I also included glut32.dll in build_windows, in case your Windows didn't come with the OpenGL Utility Toolkit.

Tested on

  • Ubuntu with gcc 4.4.3 (2011)
  • OS X 10.5.8 with gcc 4.0.1 (2011)
  • Windows XP with VS 7.0 (2004)

The demo was created using Microsoft Visual Studio 7.0. I don't have MVS anymore, so I gently hacked the code to compile under Linux and OS X as well (with a few #ifdefs) in 2011.

I created this little demo ages ago (in 2004), when researching some AI game technologies. Don't expect any updates or support here.

predatorprey's People

Contributors

piskvorky avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.