CS010 Introduction to Computer Science I
Term Project
Deliverable Three

Swarm and Flocking Behavior:
Swarming and Edge Avoidance
(last updated 4/12/2005)

For the third deliverable, you will combine the first and second deliverables, implementing actual swarm behavior.  You will of course need to modify your first week's animation code to handle critters with velocity vectors (if you have not done so already).

This week, you should modify your update-critter function so that the new velocity vector reflects the combination of steering vectors from alignment, cohesion, and separation.  You may have to do some experimentation to discover how best to accomplish this.  There are ideas in this paper, but you are encouraged to think about alternatives of your own design.  Be especially careful to document this part of your code.

In addition, you should modify your update-critter so that instead of wrapping around the edge of the canvas, the edges exert a repelling force (like that of separation) causing critters to steer away from them.  You might choose to apply this avoidance only in situations where the wall is closer than the defined radius of vision; that is, if the wall is close enough to be a neighbor (if it was a critter) then apply the appropriate avoidance vector.

For this week's project deliverable, you should have working code that implements:
  1. Swarming.  Groups of critters should coalesce and move together.  They should not bunch up but should move as a group.
  2. Edge avoidance.  When a swarm of critters approach an edge, it (the swarm) should steer away from it.  This should happen as a consequence of the individual critters steering away from the edge.  However, the front of the swarm will naturally notice and turn first, which should have a cascading effect on the rest of the swarm.
  3. animate-swarm: swarm number -> true.  Make sure you have this function from the first week.

To grade this deliverable, I will review your code (including contracts, purpose statements, indentation, etc.) and I will run the animate-swarm with my own swarm.  It is important that you follow the instructions carefully.