Assignment 5

I’m using the state pattern to control all the behaviors of my animates: predators and prey.  This requires them to change their behaviors in response to events in their environments or actions performed by other organisms.   The states that will apply to both predators and prey are healthy, pregnant, starved, and dead.  A state that will apply only to prey will be frightened.    A state that will apply only to predators will be enraged.

Healthy will be the default state, where everything runs as normal.  Pregnant will occur when an organism has an excess supply of energy.  After a gestation period, a pregnant organism will reproduce.  Starved will cause an organism to use all of its resources in searching for food.  Dead will provide a way to remove organisms from the simulation by having them perform no actions until they can be deleted.  Frightened will allow a prey organism to move faster for a short period of time at the expense of efficient use of its energy.  Enraged will allow a predator to run faster for a short period of time to catch an evasive prey.

 At the moment, I only have one method and two states for prey: Healthy and Dead.   Predator also has a Starved state.   I’ll add more this coming week – this pattern is great for my simulation.

To implement the State Pattern, you must first create a state interface that contains methods that will map to actions that could happen to the object that will implement the interface.  You need setter methods to set the states of objects in response to some event in the simulation.   In my simulation, the event is declining energy levels.   This is very similar to the Strategy Pattern, but it’s more directed towards specific goals.

Advertisements

One Response to “Assignment 5”

  1. Waht does my name mean? Says:

    sup wat is your myspace page?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: