Thursday, March 10, 2011

Boids Sandbox

In an effort to discuss past projects that I've enjoyed working on, I'm going to start with one from my senior year of college. As part of my elective Artificial Intelligence course, we had to end the semester with a demonstration project from any area of AI. Having a double threat of recently reading about Boids as well as learning Python in my internship, my path was clear. I was going to develop my own bird flocking simulator.
Boids operate as an autonomous group, flying together in flocks without a defined "leader." Each boid is affected by neighboring boids according to three rules:

  1. Separation- ensures the boids don't get too close together and collide
  2. Cohesion- keeps the boids together in a loose flock
  3. Alignment- makes the boids point in the same direction as their neighbors, making the flock head the same way
As you can tell, the forces of Separation and Cohesion are direct opposites. However, each force is given a operation distance as well as a weight during calculation. Here are the values my model currently uses:
  separation_distance = 20**2
  cohesion_distance = 50**2
  alignment_distance = 50**2
  separation_weight = 2
  cohesion_weight = 1.5
  alignment_weight = 1.5
The Separation force doesn't kick in until a closer distance than Cohesion, but it operates with a greater weight.

You can check out the complete source code (and images) from Bitbucket (this project was before I discovered the wonder of git). It has a README to help you get set up (it's easy!), and start manipulating parameters to play with the sandbox yourself. The main module is embedded here so you can take a look:

No comments:

Post a Comment