The goal of this lab is to practice using the Adaptor and Decorator patterns.
Copy the current version of the simulation code into your directory. This "current version" uses the strategy pattern for hunting, but the only supported strategy is the RandomStrategy (not the ones you made).
cp /homeemp/tvandrun/pub/245/lab12 .
Evil Professor NenurdNav has prepared his own version of
a predator-prey simulation for Lab 21 of his course CS 542.
It is similar to ours conceptually, but all the code is different.
It includes a class Snake
, which has some interesting behavior:
You like this idea and want to plug this Snake
class into
our version of the simulation.
However, it uses all different interfaces.
You must use the adaptor pattern in order to make the Snake
class work in our simulation.
Copy all the files from a directory where I've put the
alien code.
This includes Snake.java
and three interfaces that
Snake
depends on.
cp /homeemp/tvandrun/pub/542/lab21/* .
Your task here, after you have looked over the files and gotten a basic feel for how they work, has four parts:
Snake
.
This class will have to be a subtype of Agent
, but it
is up to you whether it should be a subclass of Animal
.
Snake
, however, depends on Island
instead
of AgentGrid
and Organism
instead of Agent
You will need to write an Adaptor for AgentGrid
.
Agent
.
PreyArbitor
for
the PredatorDeterminer
interface.
This is trickier because PreyArbitor
is used only for static purposes,
whereas a Snake
expects a PredatorDeterminer
object.
To test your changes, you will need to make some modifications to
PredPrey.java
and predprey.day
.
Next, add a new feature to the simulation: a disease which infects animals. A diseased animal will act the same way as it would otherwise except that
Implement this by writing a class DiseasedAnimal
which
is a decorator for the Animal
abstract class.
You will need to modify PredPrey.java
to test your changes.
You will also (unfortunately) need to change PreyArbitor
to
deal with diseased animals.
Turn in a hardcopy of the classes you wrote.