Giter Site home page Giter Site logo

ertyumpx / boids Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 5.6 MB

Simulation of Boid artificial life program

License: GNU General Public License v3.0

Makefile 12.36% C++ 87.64%
agent-based-simulation boids boids-behaviour boids-simulation cpp cpp11 flocking flocking-agents flocking-simulation functional-programming makefile sdl sdl2 sdl2-image simulation

boids's Introduction

Boids

Simple simulation of Boid artificial life program initially developed by Craig Reynolds in 1986.



The main source that I followed while developing the simulation is Boids - Cornell ECE, I appreciate the detailed explanation and the code provided.

License

This project is licensed under the GNU GPL-3.0 license.

Feel free to use the source code. Referring to the repository would be very much appreciated.

Setup

Project is currently compiled with GNU G++ 13.2.1.

The only third-party dependency is SDL2. Used version of SDL2 in project is 2.28.5, should work as long as it is SDL2 and not SDL.

For compiling and linking rules GNU Make 4.4.1 was used. After downloading dependencies, make sure to change the include paths inside the Makefile.

# change the paths for '-I' 
CC := g++
CFLAGS := -Wall -std=c++11 -I/usr/include/SDL2           # here
TEST_CFLAGS := -Wall -std=c++11 -Iinclude/SDL2 -Isrc/    # and here
LDFLAGS := -lSDL2 -lSDL2_image
...

After fulfilling dependencies, download or clone the project and use Makefile to easily compile:

> make all
> make run

Since SDL2 is a cross-platform media library, output should work on Windows, MacOS and Linux.

Rules

As with most artificial life simulations, Boids is an example of emergent behavior; that is, the complexity of Boids arises from the interaction of individual agents (the boids, in this case) adhering to a set of simple rules. The rules applied in the simplest Boids world are as follows:

  • Separation: steer to avoid crowding local flockmates
  • Alignment: steer towards the average heading of local flockmates
  • Cohesion: steer to move towards the average position (center of mass) of local flockmates

Source: Wikipedia Boids

Simulation

The simulation allows you to:

  • Speed up/down the simulation using q and e keys
  • Toggle the debug mode for seeing each agents' visual and protected range using d key
  • Restart the simulation using r key

Speeding Up/Down

Debug Mode

General Structure

Directory Structure and Files

  • src/ directory contains the source code
    • src/main.cpp is the entry point of the program
    • src/game.hpp contains the declarations of the core functions
    • src/game.cpp contains the implementation of core functions
    • src/agent.hpp has the struct of the boid agents
    • src/master.cpp has the struct of all the configurations for the simulation
  • stable/ directory contains the stable output
    • stable/boids.follow is the executable

How It Goes

Will be updated soon.

boids's People

Contributors

ertyumpx avatar

Stargazers

 avatar

Watchers

 avatar

boids's Issues

Obstacles

Next step for the simulation is to be able generate a 2D map with different shaped obstacles that agents cannot cross.

This would require a complete different functionality for the agents.

Further details can be discussed later.

Friend and Enemy Agents

Currently the entire idea of the simulation is about the flocking behaviour and all the agents are acting as the members of the same class.

We can change the concept a little and create different classes, so the agents may be neutral or be repelled by each other. This idea could be considered as colonizing of the different groups.

Further details can be discussed later.

Fixing Frame Rate for Rendering

While the speed up and down functionality works fine, it directly decrases the rendering frame count per second.

It would be much better to separate rendering fps and agent update rate, so that even the simulation runs very slow, frame rate would remain the same and the simulation would seem much smoother.

Setting a Target/Attractor for the Agents

Another next step that we can set to the simulation is to be able set a target for the agents, such as the cursor, so that they will try to follow and reach to that target.

Another idea is to set - not a target but - attractors, which could be considered like food. The difference is that attractor can only be seen by the agent if it's in the visual range.

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.