-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchableMaze.java
More file actions
38 lines (30 loc) · 1.01 KB
/
SearchableMaze.java
File metadata and controls
38 lines (30 loc) · 1.01 KB
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
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
public class SearchableMaze extends Maze{
private Tracker tracker;
public SearchableMaze(File lbr) throws Exception {
super(lbr);
}
public SearchableMaze(File lbr, Tracker tr) throws Exception {
super(lbr);
tracker=tr;
}
public MazePosition entrance(){
return super.arrl.get(0);
}
public boolean atExit(MazePosition mp){
return mp.equals(super.arrl.get(super.arrl.size()-1));
}
public MazePosition[] next(MazePosition from){
ArrayList<MazePosition> mpa=new ArrayList<MazePosition>();
Iterator<MazePosition> it=super.arrl.listIterator();
while(it.hasNext()) {
MazePosition check = it.next();
if((check.getColumn()==from.getColumn() && (check.getRow()-1==from.getRow() || check.getRow()+1==from.getRow())) || (check.getRow()==from.getRow() && (check.getColumn()-1==from.getColumn() || check.getColumn()+1==from.getColumn()))){
mpa.add(check);
}
}
return mpa.toArray(new MazePosition[mpa.size()]);
}
}