CSE 115 - Fall 2008 - Banner
UB -
University at Buffalo, The State University of New York Computer Science and Engineering
  • CSE 115 - Fall 2008
CSE 115 - Fall 2008 - Navigation
CSE 115 - Fall 2008 - Lab 9

Lab 9
Last modified: November 10 2008 10:14:23 AM

- - Lab 8

Introduction.

In this lab, you will be navigating an agent through a maze. The navigation will be accomplished in two ways. First, the user can control the agent by pressing keys for up, down, left and right. Second, the user will be able to enter a string of commands into a text area and the agent will follow those commands.

Objectives

We will concentrate on the following idea that was discussed in class:

  • Strings, primitive types
  • Selection using if-statements
  • Loops (general and for-each)
  • Collections


Lab Tasks

Eclipse Project Setup

Check out the Lab 9 Skeleton from the repository. It is called Mazes. Note that for this assignment, there is a large amount of source code included in the package mazes. You should not modify this code in any way. Rather, you should write your code in the package named lab9. You are encouraged to look at the mazes code, but you should not modify it. Instead, it is probably best to look at the Javadocs for Lab 9 instead.

Attendance

Attendance will be taken for this lab and will count towards part of this lab's grade. That means, that on both weeks, attendance will be taken.

Design

You will need to design your solution using UML before you begin coding. You will also be required to submit a UML diagram named Lab9.grn with your final submission.


Assignment Description

General Description of Assignment

Who doesn't feel like they are a rat in a maze sometimes? In this lab, you will help control an agent trying to navigate a maze. The user of the program will be able to generate a random maze, create a maze agent, and then help the agent navigate the maze. The user can either navigate the agent by using a set of Up,Down,Left,Right buttons or by typing in a string of commands that the agent will execute.

Once again, you are free to look at the library code as much or as little as you'd like. However, there may very well be things in the code we simply haven't covered in class yet, or won't be covered in this course at all. You must not modify the library code in any way. Therefore, it is suggested that you begin by looking at the Javadocs for help on the project. When you have the project completed, feel free to look at the functionality of the library if you are interested. Or for an extra challenge, you can modify the library code in the extra credit portion discussed below.

Start to fill in the code

The first thing you should do is look at the code in the lab9 package. There is a file called App that has a main method. In order to get this program up and running, you need to create an instance of a mazes.gui.MazeGUI object. This object creates the GUI for the maze program. You will need to use its getColumn() method to get something that you can put on the content pane of your frame.

Once you do this, run the program to see what functionality is already there for you. Notice that the button for generating a random maze does work and creates random mazes for you. You do not have to change the functionality of this button.

However, none of the other buttons have any functionality, you will need to define how each of these elements behave when clicked.

Create a Top Level Object

Creating an instance of the MazeGUI object inside App was fine when we wanted to test things out, but now we want to give more functionality, so we need a top level object. Create a top level object and have your App create an instance of that. This object will create instances of your listeners and attach them to the MazeGUI using the appropriate methods. It will also facilitate communication between the maze itself and the other components of the system.

Create your listeners

Create classes that are listeners for each of the buttons on the screen. Use the appropriate methods to attach the listeners to the MazeGUI. For each of the listeners have it create a simple graphic at a random location and display it on the maze. This way, you can be sure that the listeners are connected properly. Once you have all the listeners connected properly, you can focus on what each of them should do. The order you complete the listeners in is totally up to you. Listed below are some suggestions and hints for each listener.

New Maze Navigator

For this button to work, you will need an object that represents your maze navigator. This object will have a graphical component, like your turtle from Lab 7 and it will be able to do things, mainly move up, down, left, and right within the maze. Creating a new maze navigator puts the navigator in the starting position of the maze.

Up, Down, Left, Right Buttons

These buttons move the navigator one space to the north, south, east or west. The navigator can not walk through walls of the maze. Note that you can ask the maze for a Cell at a given Position using the getCell method. Cells have the ability to tell whether or not they are allClear. You can use these abilities to help you move through the maze. It helps to think of the maze as a grid of Cells, each in a row or column and movement is a movement within these rows and columns. For example, when you go up, you are going up one row.

When the navigator makes it to the finish - something should happen indicating that the user solved the maze (one possibility is to look at JOptionPane). You can then either send the navigator back to the start or create a new maze for the user and then send the navigator back to start, or offer the user a choice of those options (this last bit is extra credit).

*** Optional and extra credit - leave a trail behind you as you walk the maze so that you can see where you have been.

Walk inputted Path

This button takes the text from the text field and uses the text to control the navigator. Once again, the navigator can not walk through walls, so any input from the text field that tries to get the navigator to do so should be ignored. The language for the navigator is as follows:

N - move one space to the north
S - move one space to the south
E - move one space to the east
W - move one space to the west

For example, the string "NNEWSS" would move the navigator one space to the north, then again another space to the north, then a space to the east, then a space to the west, then a space to the south, then another space to the south. If at any point the navigator could not move, it should simply ignore the command and go on to the next one.

****Optional, add distance after the commands, so for example "N4S23E1" moves the navigator 4 to the north, 23 to the south, and then 1 east. Again, ignoring any commands that it can not do.

Extra Credit - Maze solver

This part of the assignment is absolute extra credit. Help for your implementation can be received during office hours, but will not be discussed in recitation or lecture. This extra credit is non-trivial and should only be attempted after the other parts of the lab are complete. If you attempt to do the extra credit, you will need to copy your project and rename it Lab9ExtraCredit. You will submit both a Lab9.jar and a Lab9ExtraCredit.jar if you choose to take on this task. Submission of the Lab9.jar must be submitted by the due date given below, but Lab9ExtraCredit.jar can be submitted up until 11:59:59pm on the day of the final exam.

Create another button on the GUI that when clicked will have the maze navigator solve the maze - that is, it will walk the maze on its own and find the solution. As an extra extra bonus, have the navigator color in the solution path so that the user can see it clearly on the screen.


Due dates

Note that Lab 8 and Lab 9 are due to be turned in on the same day. However, Lab 8 will be discussed during the week of 11/3 in recitation, and Lab 9 will be discussed during the weeks of 11/10 and 11/17. Therefore, the assumption is that you have completed Lab 8 (or at least a significant amount of the functionality of Lab 8) in 1 week and then will be prepared to work on Lab 9 starting the next week. This is not an invitation to wait until the last minute to start work on both assignments because it is guaranteed that you will not finish them if you wait to begin.

The Lab9.jar must be submitted using the electronic submission command by the end of the day Sunday, November 23rd (11:59:59pm). Note that your submission must include your Java source code files as well as a file that contains your UML diagram.


CSE 115 - Fall 2008 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@cse.buffalo.edu | 130 Bell Hall | (716)645-3180 x 161