This is a simple finite state machine (FSM) in action. Sheep have states: Grazing, Sleeping, Fleeing, Dead. Some behaviors and transitions are random (like a sheep falling asleep, or how it moves when grazing), and some behaviors and transitions are governed by the presence and proximity of a big bad wolf.