CS 160, Spring 2015
Programming Assignment P6
Maze Program
Programming due Monday, Mar. 9 at 6:00pm; late deadline Mar. 9 at 11:59pm.
This lab has the goal of teaching you how to:
- Instantiate a Maze object and call its methods.
- See your code controlling a graphical user interface.
- Use control loops to manage movement in the Maze.
Description
This assignment features Chihiro from the Miyazaki film
Spirited Away,
the best animated film ever made. Chihiro is having trouble in the spirit world,
and needs the help of Haku. While looking for Haku in the maze, Chihiro needs
to stay away from the witch Yubaba. The goal of this program is to move Chihiro
around the maze according to a precise set of rules. If you follow the rules,
Chihiro will find Haku, and will never meet Yubaba. Note: You must follow
the exact path we specify to receive full credit on this program, finding Haku
is not enough!
Instructions
In Recitation 10 you should have started on P6.java. If not, follow the directions
here. Leave in the code you wrote that instantiates
the Maze object and retrieves the dimensions. Remove any code from the recitation
that moves Chihiro around in the maze. Then add code to implement the algorithm
shown below. This will require multiple control loops, which can be either while
or for statements. Here is a complete specification of the Maze methods you can call:
// Constructor, parameter is name of maze file
public Maze(String fileName);
// Get width and height of maze
public int getSize();
// Get location of Chihiro
public int getColumn();
public int getRow();
// Commands to move Chihiro
public void moveRight();
public void moveLeft();
public void moveDown();
public void moveUp();
// Returns true when Chihiro finds Haku, false otherwise
public boolean isDone()
Algorithm
- The mazes are square, but can be of any size.
- Chihiro can start anywhere, as specified by the maze.
- Haku can be anywhere, as specified by the maze.
- If you follow the rules, Chihiro will never encounter Yubaba.
- Row and column numbers are zero based, so the first row and column is index 0.
- Here is the exact algorithm for finding Haku, each step requires a loop:
- If Chihiro is not in the leftmost column, move her left until she is.
- If Chihiro is not in the bottom row, move her down until she is.
- Move Chihiro from the bottom left to the bottom right of the maze.
- Move Chihiro from the bottom right to the top right of the maze.
- Move Chihiro diagonally from top right to bottom left.
- When moving along the diagonal, move left then down, and repeat.
- Each time you move you must call the maze.isDone() method.
- If maze.isDone() returns true, your program must exit.
- If you go outside the maze, the maze will print an error and exit.
- If you go run into Yubaba, the maze will print an error and exit.
- When Chihiro finds Haku, you must immediately break out of all loops, and exit
the program.
- There are mazes that cannot be solved using the algorithm, but we will not test
your program with any of them.
The Maze is programmed to wait 0.5 seconds each time you move Chihiro,
so you can issue move calls back to back, and Chihiro will move at a
reasonable speed that allows you to see the moves. In addition to checking
visually, the move methods will print the row and column of Chihiro,
and you can use this to debug your code. For example, here is the output
of Chihiro moving to the leftmost column:
Maze name: maze.txt
Maze width: 6
Maze height: 6
Moved to row 2, column 3
Moved to row 2, column 2
Moved to row 2, column 1
Moved to row 2, column 0
Testing
You should test your code with the five Mazes provided, and you can also make your own mazes.
The format of a maze file is shown below. The first line is an integer specifying the size,
which is both the number of rows and columns, since the maze is square. This is followed by
one line for each row of the maze, with one character per column. The value 'C' is Chihiro,
'H' is Haku, and 'Y' is Yubaba.
6
--Y---
-Y----
----C-
----Y-
-H-Y--
------
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.
- Work on your own, as always.
- The name of the source code file must be exactly P6.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 correctly solves Maze1.txt (10 points)
- test2: Chihiro correctly solves Maze2.txt (10 points)
- test3: Chihiro correctly solves Maze3.txt (10 points)
- test4: Chihiro correctly solves Maze4.txt (10 points)
- test5: Chihiro correctly solves Maze5.txt (10 points)
- Preliminary tests use mazes of different sizes, so do not hard code width and height.
- Final Tests
- test6: We will test with a straightforward maze, not provided to you. (10 points)
- test7: We will test with a more complex maze, not provided to you. (10 points)
- test8: We will test with a small but devious maze, not provided to you. (10 points)
- test9: We will test with a large and devious maze, not provided to you. (10 points)
- 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).
© 2015 CS160 Colorado State University. All Rights Reserved.