# Advanced Boids with Spatial Hashing **Track:** Simulation & Complexity — Advanced Creative Coding — proposed (50) **Framework / surface:** p5.js **Level:** Hard **Prerequisites:** Autonomous Agents & Steering, Hash Maps & Lookup **In one line:** Reynolds' three rules plus a hash grid to break the O(n²) wall. ## Theory, aesthetics & inspiration Craig Reynolds' 1987 boids, introduced in "Flocks, Herds, and Schools: A Distributed Behavioral Model," derive flocking from three local rules: separation to avoid crowding, alignment to match neighbors' heading, and cohesion to steer toward the local center. No agent sees the whole; the murmuration is emergent. The naive implementation compares every pair, an O(n²) cost that throttles large flocks. A spatial hash divides space into a grid of buckets, so each boid queries only its own cell and its neighbors, collapsing the cost toward linear. Visually the payoff is scale — thousands of agents banking, splitting, and rejoining in fluid, leaderless waves.