Boids are a way of modeling the complex flocking behavior of birds as well as many marine life including schools of fish; the simple rules which are able to generate complex behaviors have been described by Craig Reynolds https://www.red3d.com/cwr/boids/