CS30 -- Introduction to Computer Science II
Fall, 2004
Project 2
(updated 11/9/2004)


Programming Project:
This week, you will continue the general puzzle framework we have been developing.  In summary, you will develop a world reader, a monster, and extend your agent to pick up and use tools.  Get started right away.

1. World Reader.  You will add a method, initWorldFromFile(String filename), to the Grid class that will read an initialization file such as this one.  The file contains the information for the size of the world, the initial position and orientation of the agent, and the contents of each grid cell.  The format is as follows:  line 1 -- the name of the world. this should be displayed on the titlebar of your window.  line 2 -- the size of the grid in X/columns followed by Y/rows.  line 3 -- initial heading of agent, one of north, south, east, or west.  lines 4 through end of file -- the contents of each cell where a line represents the contents of a single row.  You should create GridObjects in a cell according to the following key:
<space>
B
+
*
@
#
K
T
M
nothing
agent
food
wall
rock
door
key
hammer
monster
In your main function when you create your Grid instance, you should call <yourgrid>.initWorldFromFile("theFileName"); which will in turn create the appropriately sized grid and the necessary GridObjects in their appropriate locations.  Note, you will not know in advance the dimensions of your grid or the appropriate size of the window.

2.  A Monster.  You need to create a monster controller that will (indirectly) manipulate a second agent object.  The monster can sense the direction toward the first agent you created.  Given that direction, the monster will move toward the agent some percentage of the time (say 50%).  The rest of the time it moves randomly.  If the monster moves into the cell where the first agent is located, the monster eats the agent and the game is over.  A monster's initial heading should be randomly selected at time of creation.

3.  Agent Extensions.  Extend your agent to select among a more complete set of possible actions.  (They are: moveForward(), moveBackward(), turnRight(), turnLeft(), grab(), drop(), and use().)  The new methods -- grab(), drop() and use() -- should do the appropriate things when executed in appropriate situations.  For example, if grab() is selected while the agent is in the same cell as a key, the key should become part of the agent's inventory and should move with the agent when the agent moves.  Similarly, if the agent has a hammer in its inventory and selects the use() method while facing a rock, the rock should disappear (and subsquently, the agent could walk over the cell where the rock had been).


Submission Instructions:
On your machine where you are doing your homework, create a folder called <your email name> followed by "P2".  For example, someone with email address "cjones" would create a folder called "cjonesP2".  Inside that folder, place plain text file(s) containing your answers to any exercises.  Also, place whatever Java files are necessary for your Programming Projects in the same folder.  Finally, either tar or zip the folder so that when I extract it, the folder "<emailname>P2" will be createdIf you choose to use zip instead of tar, change the extension of the resulting zip file from "<something>.zip" to "<something>.foo".  This way, our webmail will allow you to attach the file.  If I get an attachment with extension .foo, I will change it back to .zip and all should be well.