-
Notifications
You must be signed in to change notification settings - Fork 173
/
MazeData.java
52 lines (40 loc) · 1.36 KB
/
MazeData.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
public class MazeData {
public static final char ROAD = ' ';
public static final char WALL = '#';
private int N, M;
public char[][] maze;
public boolean[][] visited;
private int entranceX, entranceY;
private int exitX, exitY;
public MazeData(int N, int M){
if( N%2 == 0 || M%2 == 0)
throw new IllegalArgumentException("Our Maze Generalization Algorihtm requires the width and height of the maze are odd numbers");
this.N = N;
this.M = M;
maze = new char[N][M];
visited = new boolean[N][M];
for(int i = 0 ; i < N ; i ++)
for(int j = 0 ; j < M ; j ++){
if(i%2 == 1 && j%2 == 1)
maze[i][j] = ROAD;
else
maze[i][j] = WALL;
visited[i][j] = false;
}
entranceX = 1;
entranceY = 0;
exitX = N - 2;
exitY = M - 1;
maze[entranceX][entranceY] = ROAD;
maze[exitX][exitY] = ROAD;
}
public int N(){ return N; }
public int M(){ return M; }
public int getEntranceX(){ return entranceX; }
public int getEntranceY(){ return entranceY; }
public int getExitX(){ return exitX; }
public int getExitY(){ return exitY; }
public boolean inArea(int x, int y){
return x >= 0 && x < N && y >= 0 && y < M;
}
}