Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use this link to to get the assignment instructions https://www.cs.colostate.edu/~cs163/.Spring18/assignments/P6/doc/P6.php Description This assignment features Chihiro from the Miyazaki film Spirited Away , the best

Please use this link to to get the assignment instructions

https://www.cs.colostate.edu/~cs163/.Spring18/assignments/P6/doc/P6.php

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!

Getting Started

The setup for this assignment is complex enough that you may not want to do it on your own, so we have dedicated some time during Lab 9 for our TAs to help you to get started. P6 requires an additional Java file for the graphical user interface, in addition to several image and maze files. As usual, use Eclipse to create a P6 project and associated P6 class in P6.java. Copy the image files and maze files into workspace/P6/, and the Maze.java source file to workspace/P6/src/.

Chihiro.png

Haku.png

Yubaba.png

Success.png

Maze1.txt

Maze2.txt

Maze3.txt

Maze4.txt

Maze5.txt

Maze6.txt

HardMaze.txt

Maze.java

A tree view of the P6 directory should look like this: P6/ ??? Chihiro.png ??? Haku.png ??? Yubaba.png ??? Success.png ??? Maze1.txt ??? Maze2.txt ??? Maze3.txt ??? Maze4.txt ??? Maze5.txt ??? Maze6.txt ??? HardMaze.txt ??? bin/ ??? src/ ??? Maze.java

Copy the following code into P6.java:

public class P6 { // Class variables public static Maze maze; public static int mazeWidth; public static int mazeHeight; public static void main(String[] args) { // Create maze String fileName = args[0]; System.err.println("Maze name: " + fileName); // Get dimensions maze = new Maze(fileName); mazeWidth = maze.getWidth(); mazeHeight = maze.getHeight(); System.err.println("Maze width: " + mazeWidth); System.err.println("Maze height: " + mazeHeight); // Add code to move around maze } } 

Once all files are in place, follow these steps:

Modify the run configuration to pass Maze1.txt to the program.

Test your program by calling maze.moveRight() to make the student move right one square.

Exercise 1: The maze object has similar methods to move down, left, and up, try calling each of them.

Exercise 2: Try writing a for or while loop to move Chihiro from left to right across the top row.

Exercise 3: Run Chihiro around the outside of the Maze, in a clockwise direction.

Exercise 4: Run Maze5.txt and see what happens when you run into Yubaba. Note: In order to detect Yubaba, you must check the return value from the move methods.

Instructions

In Lab 9 you should have started on P6.java, if not please follow the directions above. 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 getWidth(); public int getHeight(); // Get location of Chihiro public int getColumn(); public int getRow(); // Commands to move Chihiro public boolean moveRight(); public boolean moveLeft(); public boolean moveDown(); public boolean moveUp(); 

Algorithm

The mazes can be of any size.

Chihiro always starts in the top left corner.

Haku can be anywhere, as specified by the maze file.

Yubabas can be anywhere, as specified by the maze file.

If you follow the rules, Chihiro will never meet Yubaba, and will find Haku.

Row and column numbers are zero based, so the first row and column is index 0.

Here is the exact algorithm for finding Haku:

On even rows, Chihiro moves from left to right.

On odd rows, Chihiro moves from right to left.

When Chihiro reaches the right side on an even row, she moves down.

When Chihiro reaches the left side on an odd row, she moves down.

When Chihiro successfully moves, the Maze move methods return true.

When Chihiro would run into Yubaba, the Maze move methods return false.

When the move method returns false, you must make Chihiro evade Yubaba.

Evasive action when moving right means move down, right, right, then up.

Evasive action when moving left means move down, left, left, then up.

Hint: You can use an outer loop to run through all rows.

Hint: You can use an inner loop to move from left to right.

Hint: You can use a separate inner loop to move from right to left.

Hint: You can decide between the loops by checking the row modulo 2.

Hint: Always move down after completing a loop.

If Chihiro goes outside the maze, the maze will print an error and exit.

Chihiro cannot run into Yubaba, the maze will not allow her to.

When Chihiro finds Haku, the maze will print congratulations and exit.

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 1.0 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. You can modify this time in the Maze.java file. Any other changes to the graphical user interface in Maze.java will void your warranty! 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. This is also used to test your code. For example, here is the output of Chihiro moving right along the top row then down to the second row.

Maze name: Maze5.txt Maze width: 8 Maze height: 5 Moved to row 0, column 1 Moved to row 0, column 2 Moved to row 1, column 2 Moved to row 1, column 3 Moved to row 1, column 4 Moved to row 0, column 4 Moved to row 0, column 5 Moved to row 0, column 6 Moved to row 0, column 7 Chihiro found Haku, congratulations! 

Testing

You should test your code with the six 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 maze width, followed by an integer with the maze height. These values are followed by one line for each row of the maze, with one character per column. The value 'C' is Chihiro, 'H' is Haku, 'Y' is Yubaba, and '-' is empty.

5 6 C----H --Y--- ----Y- -Y---- ---Y-- 

Specifications

Your program must meet the following specifications:

Chihiro must follow the exact route specified.

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.8.

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions