Last update: Monday, December 01, 2003 01:23 PM
Assigned Date: Monday, November 24, 2003
Due Date: Friday, December 5, 2003
Due Time: Noon
Program file names to be submitted: Matrix.java, MatrixBeing.java, Human.java, Agent.java, Matrix.kwld, Readme.txt
Skills Developed: Object-oriented design, inheritance, having fun!
You are a Matrix operator.
You will be working with a new Matrix simulator to develop strategies for dealing with Agents in the Matrix. Neo, Morpheus,
Trinity and the rest of humanity depend on your programming skill!
This new simulator has been developed by the legendary Matrix hacker, Joseph Bergin. Joseph Bergin is living in the Matrix disguised as a university CS professor. His Matrix simulator has been disguised as a simulator for a robot called Karel J. Robot.
Here is a concise description of the Karel J. Robot simulator discovered somewhere in the Matrix.
Install Karel J. Robot (see instructions) and experiment with its possibilities. For instance, build a new world and load it into a simulation. Then create a robot and make it move around (see KarelSample.java).
The problem with the previous model is that you can only run one robot at a time. So, let's experiment with robots that run in parallel.
First take a look at the classes provided with the simulator. In
particular see ur_Robot,
The MatrixBeing class (MatrixBeing.java) extends a Robot in several ways. Familiarize yourself with its operations. For instance, MatrixBeing objects have a name (a String). They also have a boolean method isHere(name), to check if they are at the same place in the Matrix with a being called 'name'.
Create a few beings (MatrixBeing objects) and have them run around (see MatrixSample.java). The behavior exhibited by the beings is implemented in method MatrixBeing.run(). If this method contains an infinite loop, MatrixBeing objects will run forever (or until they hit a wall, or until they run off the edge of the Matrix, or ... until you terminate the simulation).
Finally, let's improve the MatrixBeing class by adding method wander(). This method makes the being select one move randomly (Hint: use an Oracle object). Call method wander() within run(). Instantiate a few beings and let them run loose in the Matrix.
Although you can have several beings running in parallel, they all exhibit the same behavior (this is called
To make things more interesting, let's create an Agent class that extends MatrixBeing. Override the Agent run() method to make agents behave a certain way. Instantiate a few Agent objects and let them run loose in the Matrix.
Now, let's create a Human class that extends MatrixBeing. Override the Human run() method to make humans behave a different way from agents. Instantiate a few Agent and Human objects and let them run loose in the Matrix.
Part 4 (bonus):
Update the behavior of agents and humans as follows:
Agents move aimlessly in the Matrix until one of them encounters a Human named "Neo". Then they all start converging towards that Human (Hint: define static variables Agent.humanSighted (a boolean) and Agent.targetStreet and Agent.targetAvenue (two integers)).
If agents "terminate" a human, then they start moving aimlessly again. You decide under what circumstances an agent may terminate a human (and vice versa).
Humans try to get to Source (Street 1, Avenue 1). When they get there, they exit the Matrix (become invisible and turn themselves off).
Alternatively, when humans encounter a phone (i.e., a beeper), they exit the Matrix. If you follow this route, then agents should pick up beepers when they encounter them, or even better hover() around a beeper waiting for a human to arrive.
Part 5 (extra bonus):
Another interesting issue is what happens when an Agent and a Human encounter each other. Do they fight? If so, how? (For possible ideas see the Karel textbook's chapter 8 and chapter 9.)
Part 6 (super duper bonus):
Note that under the 'goodies' subdirectory, there is a RemoteControl class. Feel free to experiment with it to control
a human and turn the simulation into a video game.