Assignment: Escape the Obstacle Course

Complete the ObstacleCourse class so it finds a path to an exit. The exit need not be found in the shortest path. Any exit will do. There is an interface provided for you (in the zip file below) that will highlight all the key things your class must do. Your ObstacleCourse.java class implements interface ObstacleCourseInterface. Both are provided in the zipped (archived) Eclipse project below. This will ensure that all the methods and properties needed for the GUI will be implemented. Running ObstacleCourse.java should output the obstacle course before and after.

11 20
++ +++ +++++++++++++
+ + + ++ ++
+ +++++ ++
+ ++ ++++ + + ++
+ + + ++ +++ +
+ S + ++ + +
+++++ + + ++ +
+++++ +++ + + ++ +
+ + + + +
+++++ + ++ +
++++++++++++++++++++
Output when the escape attempt
begins at row 5, column 7
++ +++O+++++++++++++
+ O+ + ++ ++
+ OOO +++++ ++
+ OO++ ++++ + + ++
+ O+ + ++ +++ +
+ OOO SOO+ ++ + +
+++++O+ +O ++ +
+++++O+++O + + ++ +
+ OOOOO + + + +
+++++ + OO ++ +
++++++++++++++++++++ / 11 20
++ +++ +++++++++++++
+ + + ++ ++
+ +++++ ++
+ ++ ++++ + +S++
+ + + ++ +++ +
+ + ++ + +
+++++ + + ++ +
+++++ +++ + + ++ +
+ + + + +
+++++ + ++ +
++++++++++++++++++++
Output when the escape attempt
begins at row 3, column 17
++ +++ +++++++++++++
+ + + ++ ++
+ +++++ ++
+ ++ ++++ + + ++
+ + + ++ +++ +
+ + ++ + +
+++++ + + ++ +
+++++ +++ + + ++ +
+ + + + +
+++++ + ++ +
++++++++++++++++++++

Algorithm to escape from the starting point to the first exit found in the obstacle course (or return false if there is no escape)

publicclass ObstacleCourse implements ObstacleCourseInterface {

privatestaticfinalcharPART_OF_PATH = 'O';

privatestaticfinalcharTRIED = '.';

protectedchar[][] course;

privateintsRow;

privateintsCol;

privateintfoundRow;

privateintfoundCol;

// .... code removed to save space

/*

* THE RECURSIVE-BACKTRACKING method that exhaustively searches the maze for

* an exit. Return true to the caller if at the current level, it found an exit.

* This method returns false if it can't find an exit from the current position

*/

publicboolean findTheExit(int row, int col) {

// TODO: Complete this method

// Use the constant names

// PART_OF_PATH = 'O' and TRIED = '.';

boolean escaped = false;

if possible(row, col) {
set current location to TRIED;
if on the border, the mover is out so {

set escaped = true

set foundRow to the current row

set foundCol to the current col
}

else {
let escaped = (RP1) success of escaping below
if still not escaped
let escaped = (RP2) success of escaping right
if still not escaped
let escaped = (RP3) success of escaping above
if still not escaped
let escaped = (RP4) success of escaping left
}
if the mover was known to escape (escaped is true)
let current location = PART_OF_PATH
}
return escaped back to caller, often the same method
} // end findTheExit

publicboolean possible(int row, int col) {

returncourse[row][col] == ' ';

}

To complete this Homework (should take 0.5 to 1.0 hours):

  • Download the ObstacleCourse Assignment that stores an Eclipse project inObstacleCourseStart.zip
  • Import the zip file as an existing project into your workspace. It has all files and methods except eight methods in ObstacleCourse that need to be completed.
  • Select File > Import > Existing Projects into Workspace
  • Select archive File button and click the Browse button
  • Browse to wherever you downloaded the Java project in an archive file
  • Complete thismethod that is written as a stubat the bottom of ObstacleCourse.java:
  • publicbooleanfindTheExit(int row, int col)
  • Optional: Run the GUI
  • Submit your entire project to WebCat