Fish Swarm Simulator (Boids Algorithm)
A C++ and SFML implementation of Craig Reynolds' Boids algorithm, simulating emergent flocking behavior in a 2D fish swarm.
Project Overview
Programmed from scratch using clean, standard C++ object-oriented practices, this simulator implements the classic Boids algorithm developed by Craig Reynolds in 1986. Hundreds of independent “fish” agents follow three simple local rules — separation, alignment, and cohesion — and flocking behavior emerges naturally from their interaction, without any centralized control.

Technical Details
- Built with C++ and the SFML library (fetched automatically via CMake’s
FetchContent) for real-time 2D rendering. - Each fish steers based on the average heading and position of nearby flockmates while avoiding crowding.
- The project ships with manual and unit tests (run via CTest) to validate the underlying vector math.

Benchmarked by spawning 20 fish per second for a minute: frame rate holds steady near 60 FPS until a few hundred fish are on screen, then degrades as the flock grows past what the naive O(n²) neighbor search can keep up with.
Project History
Originally built in 09/2024, the codebase was significantly reworked two years later: bugs in the direction-handling logic were fixed, the class structure was made more readable, and unit tests were added. Velocity-vector-based steering — a more physically accurate version of the algorithm — is planned for a future iteration.