CS 160, Fall 2013
Programming Assignment P4
Moving Chihiro in a Maze
Programming due Monday, Sep. 23 at noon; late deadline Sep. 23 at 10 p.m.
Moving in a Maze
This lab has the goal of teaching you how to:
- Read input from the user and perform error checking.
- Instantiate a Maze object and call its methods.
- Use control statements to manage movement in the Maze.
- See your code run in a visual environment.
Description
This assignment features Chihiro from
Spirited Away,
one of the finest animated films ever made.
The purpose of this program is to 1) display Chihiro in the maze, in a
location specified by the user, 2) determine whether the Chihiro is on the
edge of the maze, 3) move Chihiro to the top edge if she did not start
on an edge, and 4) move Chihiro in a counterclockwise direction around
the edge of the maze, making sure that Chihiro traverses every edge location
exactly once.
Instructions
In Recitation 5 you should have started on P4.java. If not, create a new project
and class called P4. Copy the file Maze.java into
the P4 source directory. Copy the file Chihiro.jpg
into the P4 directory.
If you were in R5, leave in the code you wrote in R5 that inputs and checks the initial
location of Chihiro, and instantiates the Maze object. Otherwise you must copy the
code from R5, which is found here. Remove any code
that moves Chihiro around in the maze. Add the following code:
- Determine if Chihiro is on the edge of the maze and store the result in
a boolean called onEdge.
- If Chihiro is not on the edge of the maze, use moveTo calls to move
Chihiro directly to the top edge, one square at a time.
- Save the location of Chihiro now that she is on the edge, this is the ending
position.
- Move Chihiro counterclockwise around the edge of the maze, one square at
a time, until she returns to the ending position.
Chihiro is programmed to wait 0.5 seconds each time you move her,
so you can issue moveTo calls back to back, and Chihiro should move at a
reasonable speed that allows you to see where she moves. In addition to checking
visually, the moveTo method will print where Chihiro moves, and you can use
this to debug your code. For example, if the Maze has 4 rows and 5 columns, and
starts in the third row and fourth column, you should see the following output:
Number of rows: 4
Number of columns: 5
Starting row: 2
Starting column: 3
Chihiro moved to 1,3
Chihiro moved to 0,3
Chihiro moved to 0,2
Chihiro moved to 0,1
Chihiro moved to 0,0
Chihiro moved to 1,0
Chihiro moved to 2,0
Chihiro moved to 3,0
Chihiro moved to 3,1
Chihiro moved to 3,2
Chihiro moved to 3,3
Chihiro moved to 3,4
Chihiro moved to 2,4
Chihiro moved to 1,4
Chihiro moved to 0,4
Chihiro moved to 0,3
NOTE: Row and column numbers are zero based, so the first column/row is
index 0, the second column/row is index 1, the third column/row is index 2,
and so on!
HINT: Try to implement the code so that there is only a single loop
to move Chihiro around. Our solution requires less than 40 lines for all
of the code that follows the Maze instantiation.
Testing
You should test your code with the following 9 test cases:
- Start Chihiro on each of the four edges of the maze, but not in a corner.
- Start Chihiro in the four corners of the maze.
- Start Chihiro anywhere in the middle of the maze.
In the case that Chihiro starts in the middle of the maze, make sure she
moves to the top edge before traversing the maze. The location where she
first reaches the top of the maze is the point to which she should return.
In the case that Chihiro starts on the edge, make sure she returns to that
same point. In all cases make sure Chihiro does exactly one loop around the
edge, in the counterclockwise direction. After all test cases are working
you should test your code again with a different size of maze. The Maze
object constrains the number of rows and columns as follows:
4 <= number of rows, number of columns <= 8
Specifications
Your program must meet the following specifications:
- Chihiro must follow the exact route specified.
- Chihiro can only move to a square adjacent to the current position.
- Chihiro cannot move diagonally or outside the maze.
- Your program must prompt for the initial position using the code from R5.
- Work on your own, as always.
- The name of the source code file must be exactly P4.java.
- Name the file exactly - upper and lower case matters!
- Assignments should be implemented using Eclipse.
- Assignments should be implemented using Java 1.5 or 1.6 or 1.7.
- Make sure your code runs on machines in the COMCS 120 lab.
- Submit your program to the Checkin tab as you were shown in the recitation.
- Read the syllabus for the late policy.
- We will be checking programs for plagiarism, so please don't copy from anyone else.
Grading Criteria
- 100 points for perfect submission.
- 0 points for no submission, will not compile, submitted class file, etc.
- Preliminary Tests
- compileTest: checks that program compiles. (10 points)
- test1: Chihiro starts somewhere on the top edge. (5 points)
- test2: Chihiro starts somewhere on the right edge. (5 points)
- test3: Chihiro starts somewhere on the bottom edge. (5 points)
- test4: Chihiro starts somewhere on the left edge. (5 points)
- test5: Chihiro starts in the top-left corner (5 points).
- test6: Chihiro starts in the top-right corner (5 points).
- test7: Chihiro starts in the bottom-left corner (5 points).
- test8: Chihiro starts in the bottom-right corner (5 points).
- test9: Chihiro starts somewhere in the middle. (10 points)
- Final Tests
- test10: Chihiro starts somewhere in the middle, on a maze with 7 rows and 4 columns. (10 points)
- test11: Chihiro starts somewhere in the middle, on a maze of an unspecified size. (10 points)
- test12: Chihiro starts on an unspecified edge, on a maze of an unspecified size. (10 points)
- test13: Chihiro starts in an unspecified corner, on a maze of an unspecified size. (10 points)
- Preliminary tests use a maze with 4 rows and 5 columns.
- Final grading includes the preliminary tests.
Submit your program to the Checkin tab on the course website, as you were shown in
the recitation, and read the syllabus for the late policy (if necessary).
© 2013 CS160 Colorado State University. All Rights Reserved.