About

A collection of raylib projects in C++. In there I explore optimization techniques for classic computer algorithms.

Boids — Flocking Simulation

Boid flocking simulation with competitive team dynamics. Multiple families hunt one another — larger boids consume smaller ones and absorb them into their team. View on GitHub

Raylib C Simulation

Boids

  • Boids follow standard flocking rules but also hunt one another according to their team
  • When a boid catches its prey, it grows in size and the prey shrinks and joins the hunter's team
  • Size affects a boid's view range, speed, and steering speed
  • Create and delete obstacles using mouse clicks to shape the environment
  • Team scores are tracked live

Optimisations

  • Bounding-box spatial partitioning: boids only check neighbors in adjacent cells rather than every other boid
  • Boids regularly ping neighboring cells to detect when they've switched position
  • Only 8–9 directional checks needed per boid for a good approximation — after reaching 8 successful checks from neighboring cells, only the current cell is checked for prey
A* Pathfinding

A pathfinding experiment that grew beyond its original scope — customizable grid world with hexagonal movement and boid-like soldier awareness. View on GitHub

Raylib C Pathfinding

Aesthetics

  • Customizable world grid: draw the world freely — wall shapes adapt to neighboring walls for a smooth look
  • Hexagonal movement grid: pathfinding operates on a hex grid instead of a square grid, leading to more organic paths
  • Boid-like movement: soldiers follow their assigned paths but also align with and avoid their neighbors
  • Sunflower objective assignment: when selecting multiple soldiers, destinations follow a sunflower distribution for even spacing

Optimisations

  • Hexagonal grid: 6 neighbors with uniform distance, more optimal than a square grid for A*
  • Multithreaded pathfinding: A* searches run on separate threads
  • Path pooling: soldiers with the same start and destination share paths instead of recalculating
  • Boundary boxes: soldiers only check nearby units for collision avoidance and alignment
  • Bresenham's line algorithm: fast line-validity checks used to skip A* when a straight line suffices, to shortcut during A*, and to simplify the final path
  • Memory safety: heavy use of shared and unique pointers for robust multithreaded operations