CS010 Introduction to Computer Science I
Term Project
Deliverable Three

Swarm and Flocking Behavior:
Swarming and Edge Avoidance
(last updated 4/14/2006)

For the third deliverable, you will combine the first and second deliverables, implementing actual swarm behavior.

This week, you should modify your update-critter function so that the new velocity vector reflects the combination of the existing velocity and the steering vectors from alignment, cohesion, and separation.  You may have to do some experimentation to discover how best to accomplish this.  For example, the different steering components may need to be weighted differently.  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.  Note: you may want to modify the contract of your update-critter function to also consume a swarm in addition to the critter to be updated.

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 construct and apply the appropriate avoidance vector.  The wall avoidance steering vector should be included in the same context as alignment, cohesion and separation.

Lastly, without some help your critters will tend to form a group and then sit there in one place or move very slowly.  To look more interesting and life-like, you should add a default-speed or nominal speed to your critter definition.  Thus, our structure definition is (define-struct critter (location velocity type color default-speed)).  Critters will tend to move at this speed unless influenced by other critters and walls.  Notice, that speed is directionless; the speed of a critter is merely the magnitude of its velocity vector.  You will need to add or subtract a small amount to your new velocity if the critter is moving slower or faster (respectively) than its nominal speed.  Again, the speed-adjustment should be included in the same context as the other steering vectors.

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 deliverable.

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.