-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearch.java
More file actions
74 lines (66 loc) · 1.82 KB
/
Search.java
File metadata and controls
74 lines (66 loc) · 1.82 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
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Search {
protected ArrayList<String> maze = new ArrayList<String>();
protected int[][] visited;
int mazeRBound = 0,mazeBBound = 0,goalRow, goalCol;
protected int pathCost = 0;
Node startNode;
protected int nodesExpanded = 0;
protected int maxDepth = 0;
protected int maxFrontierSize = 0;
public Search() {
super();
}
protected void printMaze() {
for(int i=0;i<maze.size();i++)
System.out.println(maze.get(i));
}
protected void findPath(Node node) {
pathCost++;
//System.out.println(node.xPos+":"+node.yPos);
if(node.parent==null)
return;
else{
insertDot(node);
findPath(node.parent);
}
}
protected void readInput() throws IOException {
int startRow=0, startCol=0;
BufferedReader br = new BufferedReader(new FileReader("E:/Fall 2013/AI/Assignments/1/Input/bigMaze.lay"));
int i=-1;
String str;
while(((str = br.readLine())!=null)){
//System.out.println(str);
i++;
if(str.contains("P")){
startCol = str.indexOf('P');
startRow = i;
}
if(str.contains(".")){
goalCol=str.indexOf('.');
goalRow=i;
}
maze.add(str);
}
startNode = new Node(startCol, startRow, null,0);
mazeBBound = maze.size();
mazeRBound = maze.get(0).length();
visited = new int[mazeRBound][];
for(int j=0;j<mazeRBound;j++){
visited[j]=new int[mazeBBound];
}
visited[startCol][startRow]=1;
//System.out.println(startRow+":"+startCol+":"+maze.size()+":"+mazeRBound+":"+maze.get(mazeBBound-1).charAt(mazeRBound-1));
br.close();
}
public void insertDot(Node node) {
char[] str = maze.get(node.yPos).toCharArray();
//System.out.println(node.xPos+":::"+str.length+"::"+maze.get(node.yPos));
str[node.xPos]='.';
maze.set(node.yPos, new String(str));
}
}