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

Update [10/29/2004]
As discussed in class, the due date for this assignment has been extended one week, until Friday Nov. 5.  This update is intended to provide some clarification and some guidelines on completing this assignment.

With the extra week and these guidelines, I now do expect you to provide more functionality for some of the object types you are creating.

The trick is the agent and the requirement that the agent controller not have actual direct control over the agent GridObject.  Eventually, the Grid object (the world simulator) will interact with separate agent processes, gathering their action requests and delivering their sensory information.  This will happen through network sockets that we will cover later on.  For this version, I propose you handle it as follows.  In your Grid class, create a dummy controller that randomly selects one of four moves: moveForward(), moveBackward(), turnRight(), turnLeft().  The infinite loop in your grid run() method should be organized along the following lines: process agent actions, update gridObjects, repaint(). 

So what should your "process agent actions" do?  Your dummy controller should randomly generate/call an action method in your agent GridObject.  Your agent GridObject should contain all the neccessary methods to update the position or heading of the agent according to the action executed.  Note however, that you will need to have logic somewhere (either in the "process agent actions" part or within the agent GridObject -- I'll let you think about that) that will only update the position in response to a move if the intended direction of movement is not blocked by an obstacle.

In summary, for next Friday, you should have a randomly turning and moving agent in a world with assorted GridObjects (and a wall around the border).  The hammers do not need to break rocks and the keys do not need to open doors.  However, your world should be populated with representatives of each type and the randomly moving agent should be able to walk over keys and hammers and through narrows but not over doors, rocks, and walls.  Also note, that since the agent is not picking up any GridObjects, there will not be any issue about narrows at this time.


Programming Project:
This week, you will continue the general puzzle framework you started last week.  You will be extending the framework for a specific puzzle world, Eden2, but you will also be continuing your abstract design work that was part of last week's assignment.

On the concrete side: you should create a set of specific GridObject types with the following names and characteristics:

Walls: are impenetrable and immovable

Rocks: are obstacles but can be broken by using a hammer

Hammers: can be picked up and carried.  They break rocks when used on a rock immediately ahead (in the current direction) of an agent using the hammer.

Doors: are obstacles but are opened when a key is used on them.  Once opened, they disappear.

Keys: can be picked up and carried.  They open doors but are consumed when used.  That is, one key opens one door.

Narrows: a cell that an agent can squeeze through only if not carrying anything (e.g., hammer or key).

Food: the goal of the Eden agents.  Once found, it can be picked up and "used" to finish the level and get a reward.

Agent: this is not a full-blown autonomous agent.  Primarily, it is just a place holder to display where an agent would be located at a particular point in time and which direction it is pointed.

Each of these should extend GridObject.  They should be visually distinguishable.  I suppose at a minimum, they should be different colors and you should figure out how to use text to label the objects.  (If you distinguish the objects graphically, you do not need to label them with text.)  Feel free to spend a little time trying to make nice graphics but do NOT get carried away!  Your score will be much better if you complete the assignment and have simple display functionality than if you have stellar graphics but do not complete the assignment.  If you encounter methods that are common to many or all of these classes, consider making it a method of your GridObject class.  Be prepared to discuss why or why not any such methods actually should be promoted to the GridObject class.

Although you will not be implementing the complete functionality in every case above, try to provide the data fields that will be needed to support the required functionality.

Modify your Grid class so that it has a "run()" method analogous to those we have seen in other applications from the text.

Finally, create a simple world that contains each of the elements you have just created.

On the abstract side: I want you to think carefully about the design of an Agent class.  Think about the heading feature of an agent and different contexts where the heading will be used.   

Also,  remember that the full-blown agent class is not simply another type of GridObject.  The control code for an agent will exist apart from the Grid and will communicate with the Grid to get sensory information and to send action information.  However, the agent is embodied in a particular instance of an agent object (a type of GridObject).  (We have a sort of Cartesian dualism going here.) 

Try to focus your thinking on what features need to be provided.  What data elements and public methods would you implement.  In the Eden environment, agents can perform actions such as: move forward and backward, turn right and left, pick up certain objects, use objects that it is carrying.  Think about how an instance of a Grid is going to manage the interactions between an agent instance and various GridObjects or even between multiple agent instances.  For example, think about how the Grid is going resolve an agent's attempt to move forward into a narrows if it is carrying a hammer. 

The abstract aspect here is that you should think about agents in general for other puzzles and games.  What are the common methods that would most likely be necessary. 

For this part of your assignment, you should turn in a design.  It should be reasonably detailed in content, but with respect to code, it need not even be interfaces.  That is, you do not need method signatures (return type and parameters).  However, you should provide distinct methods with extensive documentation on what each must do.  Overall, try not to think about how you would implement things.  Your task is to specify what you want these things (Agents) to do.

Submission Instructions:
On your machine where you are doing your homework, create a folder called <your email name> followed by "P1".  For example, someone with email address "cjones" would create a folder called "cjonesP1".  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>P1" 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.