Bird Flocking Behavior Algorithms

Screen shot of Flocking Behavior Simulator
Run the Flock Simulator

Flocking / swarming behaviors are an example of emergent behaviors, where complex global behavior can arise from the interaction of simple local rules.

In this example, the birds follow three simple rules that together cause the flock / swarm behavior.

Bird Detection
Each bird has a detection and separation range. The applet program has the option of displaying or hiding the ranges. The detection range is the distance at which birds can detect predators, obstacles, food and other birds. The separation range is the distance at which a flock of birds might split up to avoid a predator, obstacle, or bird. Until something falls within a birds detection range, it will not react to it. Don't get confused by the overlapping circles in the example to the left. It this example, the birds cannot see each other until the bird itself falls within the other birds detection circle.
Separation
Birds are repelled by birds of different colors and by obstacles. The closer the bird, the greater the repel effect. This causes birds to turn away from predators, obstacles, and different color birds.
Alignment
In a flock of birds that are all the same color, each bird will try to match the direction of the birds around it that it can detect. If some of the birds in a flock detect an obstacle, they will turn. This causes the rest of the flock that can't even detect the obstacle to also turn away from it.
Cohesion
Birds within a flock are attracted to each other as long as they are within the detection range, but outside the separation range. This goal is to have the birds flock together, but not to be so close that they are on top of each other. If there are too many birds in the flock, the separation range will need to be increased.

You can download this program here:

See a online video game designed using flocking behaviors

See some of the other AI projects on the site