-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maze.java
125 lines (91 loc) · 3.58 KB
/
Maze.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Name:
// USC loginid:
// CS 455 PA3
// Spring 2017
import java.util.LinkedList;
/**
Maze class
Stores information about a maze and can find a path through the maze
(if there is one).
Assumptions about structure of the maze, as given in mazeData, startLoc, and endLoc
(parameters to constructor), and the path:
-- no outer walls given in mazeData -- search assumes there is a virtual
border around the maze (i.e., the maze path can't go outside of the maze
boundaries)
-- start location for a path is maze coordinate startLoc
-- exit location is maze coordinate exitLoc
-- mazeData input is a 2D array of booleans, where true means there is a wall
at that location, and false means there isn't (see public FREE / WALL
constants below)
-- in mazeData the first index indicates the row. e.g., mazeData[row][col]
-- only travel in 4 compass directions (no diagonal paths)
-- can't travel through walls
*/
public class Maze {
public static final boolean FREE = false;
public static final boolean WALL = true;
/**
Constructs a maze.
@param mazeData the maze to search. See general Maze comments above for what
goes in this array.
@param startLoc the location in maze to start the search (not necessarily on an edge)
@param exitLoc the "exit" location of the maze (not necessarily on an edge)
PRE: 0 <= startLoc.getRow() < mazeData.length and 0 <= startLoc.getCol() < mazeData[0].length
and 0 <= endLoc.getRow() < mazeData.length and 0 <= endLoc.getCol() < mazeData[0].length
*/
public Maze(boolean[][] mazeData, MazeCoord startLoc, MazeCoord exitLoc) {
}
/**
Returns the number of rows in the maze
@return number of rows
*/
public int numRows() {
return 0; // DUMMY CODE TO GET IT TO COMPILE
}
/**
Returns the number of columns in the maze
@return number of columns
*/
public int numCols() {
return 0; // DUMMY CODE TO GET IT TO COMPILE
}
/**
Returns true iff there is a wall at this location
@param loc the location in maze coordinates
@return whether there is a wall here
PRE: 0 <= loc.getRow() < numRows() and 0 <= loc.getCol() < numCols()
*/
public boolean hasWallAt(MazeCoord loc) {
return false; // DUMMY CODE TO GET IT TO COMPILE
}
/**
Returns the entry location of this maze.
*/
public MazeCoord getEntryLoc() {
return new MazeCoord(0,0); // DUMMY CODE TO GET IT TO COMPILE
}
/**
Returns the exit location of this maze.
*/
public MazeCoord getExitLoc() {
return new MazeCoord(0,0); // DUMMY CODE TO GET IT TO COMPILE
}
/**
Returns the path through the maze. First element is start location, and
last element is exit location. If there was not path, or if this is called
before a call to search, returns empty list.
@return the maze path
*/
public LinkedList<MazeCoord> getPath() {
return new LinkedList<MazeCoord>(); // DUMMY CODE TO GET IT TO COMPILE
}
/**
Find a path from start location to the exit location (see Maze
constructor parameters, startLoc and exitLoc) if there is one.
Client can access the path found via getPath method.
@return whether a path was found.
*/
public boolean search() {
return false; // DUMMY CODE TO GET IT TO COMPILE
}
}