CS151 – Fall 2007: Programming Project 6

Due: Tuesday, November 20, 2007, 11:59:59:999 p.m. EST

 

In this project you will practice using inheritance by implementing several different kinds of virtual robots that navigate around a maze according to different sets of rules.  See Programming Project 10.1 in your textbook for additional details.  We will use the ideas of inheritance (super and subclasses) to minimize the amount of code duplication -- the enemy of any good implementation. This project also requires some design on your part, so start thinking about the design early, even if you don't start coding right away.

 

You will need a total of 5 classes: Maze, Robot, RandomRobot, RightHandRuleRobot, and MemoryRobot.  As the book indicates, Robot is the superclass.  RandomRobot should be a subclass of Robot. You decide if MemoryRobot and RightHandRuleRobot are subclasses of Robot, RandomRobot, each other, etc. You should create and submit your own RobotTester class to help the grader evaluate your robots.  Feel free to use mine as a starting point.  Don't let it influence your class design.  I'm planning to change my coordinate system and some other things.

Maze Class Details

Your book doesn't say much about the functionality of the Maze class.  The following suggestions are based on my solution, which may be different from yours. 

 

1.  You will need an instance variable to store the map of the maze.  Possible choices for the entries of this array or ArrayList include: char, String, int, and boolean.  Choose whichever one makes the most sense to you and is easiest to work with.

 

2.  You will need one or more Maze constructors.  For convenience, you might want to have a constant that can be used to create the example maze from the book.  For simplicity you only have to construct regular, rectangular mazes where every row has the same number of columns.  The interior of the maze may have any configuration.

 

3.  Override the toString method so that it returns a string representation of the maze.  You can use the format from the book, asterisks (*) and blanks (" "), or come up with your own.  toString DOES NOT print to the terminal window!  It just returns a string.  Some Tester or other classing calling the method can decide what to do with the String it returns.

 

4.  [Optional, but very helpful] A method called showAt() that takes a position in the maze and returns the same thing as toString(), but also shows a mark indicating something (like our robot) at the specified position.  Try to use the same code for toString() and showAt(), e.g. figure out how to have one call the other.

 

Robot Superclass

Each robot should keep track of its location in the maze (like chess pieces on a board).  It should also have a move() method that each subclass overrides.  The move() method takes a single parameter which is a maze.  A robot moves one unit in one of four possible directions: left, right, up, down (NOT diagonally) provide there isn't a wall.  Robots can't go through (or into) walls.

 

In addition to the move method and constructor(s), the class should have a toString() method that overrides the Object version of that method. toString() takes no parameters and returns a concise description of the robot as a String.  Specifically, it should indicate the robot's location.  See section 10.8 of your book for ideas.

Subclasses of Robot

Some of the subclasses will require additional instance variables.  All will override the move() method inherited from the Robot superclass.  Don't forget to create constructors for each subclass just like we did for chess pieces.  If a subclass has additional instance variables, initialize them in the constructor for that class AFTER calling the superclass constructor.  They may also need to override the toString() method.  See Advanced Topic 10.4 (on the book's web site) for ideas on clean ways to deal with this issue.

 

MemoryRobot is NOT allowed to copy the entire maze it gets as a parameter to the move method.  This requires cloning a Maze object, something we don't want to get into.  Also, it's cheating!  MemoryRobot CAN remember any position it previously visited, and any possible position adjacent to a position it occupied.  For example if the robot starts at row 4 and column 5, the first time it sees the maze it can record information about positions: (4,5), (3,5), (4,6), (5,5), and (4,4).  If it moves to position (3,5) it can then record information about (2,5), (3,6), and (3,4).  For convenience MemoryRobot is allowed to know the size of the maze it's in.  It doesn't learn this until the first time it is asked to move.  Assume that the maze never changes.

 

For RightHandRuleRobot, first assume the robot is always placed in the maze with a wall on its right.  After you get that working see if you can figure out how to relax that assumption.  Specifically, what should it do in when it starts away from a right hand wall?  I leave that up to you, but try not to rewrite the same code you have somewhere else.

 

For any other suggestions please ask me outside of class AFTER you have thought about it on your own for some time.  Please do not consult your friends about your project design except for very general questions.  I remind you that this is clearly spelled out in the collaboration policy.

 

Extra Credit

á      Add a method to the maze class that reads in and creates a maze from a file.

á      Implement another kind of robot.

Strategy and Hints

I recommend working on the classes in the following order:

1.    Maze

2.    Robot

3.    RandomRobot

4.    RightHandRuleRobot

5.    MemoryRobot

 

RightHandRule is a little harder than RandomRobot.  MemoryRobot is much more difficult, so please don't leave it for the last minute. 

 

Start early and try to make a little progress each day.  Test early and often.  Sections 2.8, 3.6, 5.5, 6.6--6.7, and 7.8 of your book discuss different aspects of testing.  You can use BlueJ to test constructors and simple methods interactively.  Feel free to use the logging capabilities described in Advanced Topic 5.6, the BlueJ debugger (see Lab 7), etc. to help you find errors in your classes.  Make use of the online documentation, the Olin lab TAs, your fellow classmates (to the extent allowed by the Collaboration Policy), and me early and often.  Don't put off starting the project until a day or two before it's due and expect to produce a quality piece of work.

 

Style and Documentation

All constructors, methods, and public instance variables should be commented using @param and @return tags to facilitate the generation of .html documentation similar to the Java Class Libraries on the Web via the Javadoc utility.  BlueJ automatically generates this documentation for your class when you switch from "Implementation" to "Interface" in the class editor window.  We've discussed the use of these tags in class and additional information is in section 3.3 of your textbook. 

 

Your code should adhere to the stylistic guidelines we have been discussing and which are in Appendix A of your textbook as much as possible.  In particular group different constructors, instance variables, and similar methods together.  Use meaningful variable names and internally comment your code liberally (with // or /*   */ pairs).

 

The graders will be instructed to determine approximately 10-15% of your project grade based on style, readability, and documentation.  Please use indentation, white space, meaningful variable names, and other stylistic techniques to make your code easier to read (and grade).  Define and use public constants instead of using so-called "magic numbers" in your code.

 

Project Submission

You will again submit your projects electronically.  To do so

1.    Connect to the Academics volume of the server called fileserver1.  From a Mac choose "Connect to Server ..." from the "Go" menu in the Finder, type afp://fileserver1 in the dialog box, and select Academics from the volume list.  From Windows machine open Windows Explorer, select "Map Network Drive" from the tools menu, pick a free drive letter and type \\fileserver1\Academics or just type it directly into the address filed.  When prompted for your user name and password, type COLBY\username, where username is your Colby username and enter your password.  These instructions are adapted from http://www.colby.edu/administration_cs/its/support/fileserver1.cfm. 

2.    On the Academics volume inside of the COMP/CS151 folder/directory you will see a folder with your Colby e-mail/login name and within that a private folder.  Copy the BlueJ project folder containing your project 6 solution to your private folder.  Change its name to project6 and delete all .class files and any test classes you created during development. Include a brief readme.txt file that explains whatever you think is necessary, including any extra credit attempted. DO NOT submit a class that doesn't compile!  If you can't get something working comment it out (/*  */) so the grader can possibly give you partial credit for your efforts.  DO NOT submit your project late!  As the syllabus states, late projects are graded at my discretion.

 

Acknowledgements

As indicated above, this assignment is based on Programming Project 10.1 from our text book.