-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCAreaMap.java
More file actions
106 lines (95 loc) · 3.28 KB
/
CAreaMap.java
File metadata and controls
106 lines (95 loc) · 3.28 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
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
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
/**
*
* @author Zafrir
*/
public class CAreaMap {
private int algo;
private int n;
private Node start;
private Node finish;
private char[][] mat;
public CAreaMap() throws FileNotFoundException, IOException {
FileReader fr = new FileReader("input.txt");
BufferedReader br = new BufferedReader(fr);
algo = Integer.parseInt(br.readLine());
n = Integer.parseInt(br.readLine());
mat = new char[n][n];
String startFinish[] = br.readLine().replace(")", "").replace("(", "").split(",");
start = new Node((Integer.parseInt(startFinish[0])), (Integer.parseInt(startFinish[1])), null, 'S');
finish = new Node((Integer.parseInt(startFinish[2])), (Integer.parseInt(startFinish[3])), null, 'G');
String line;
for (int i = 0; i < n; i++) {
line = br.readLine();
for (int j = 0; j < n; j++) {
mat[i][j] = line.charAt(j);
}
}
switch(algo){
case 1:
BFS bfs=new BFS(this);
break;
case 2:
DFID dfid=new DFID(this);
break;
case 3:
AStar astar=new AStar(this);
break;
case 4:
IDAStar idastar=new IDAStar(this);
break;
case 5:
DFBnB dfbnb=new DFBnB(this);
break;
}
}
public int getAlgoNumber() {
return algo;
}
public int getMatSize() {
return n;
}
public Node getStartPoint() {
return start;
}
public Node getFinishPoint() {
return finish;
}
public char[][] getMat() {
return mat;
}
public ArrayList getAllSons(Node vertex) {
ArrayList<Node> sons = new ArrayList();
int x = vertex.getX();
int y = vertex.getY();
if ((x + 1) < n && y < n && mat[y][x + 1] != 'X') {
sons.add(new Node(x + 1, y, null, mat[y][x + 1]));
}
if ((x + 1) < n && (y + 1) < n && mat[y + 1][x + 1] != 'X') {
sons.add(new Node(x + 1, y + 1, null, mat[y + 1][x + 1]));
}
if (x < n && (y + 1) < n && mat[y + 1][x] != 'X') {
sons.add(new Node(x, y + 1, null, mat[y + 1][x]));
}
if ((x - 1) >= 0 && (y + 1) < n && mat[y + 1][x - 1] != 'X') {
sons.add(new Node(x - 1, y + 1, null, mat[y + 1][x - 1]));
}
if ((x - 1) >= 0 && y >= 0 && mat[y][x - 1] != 'X') {
sons.add(new Node(x - 1, y, null, mat[y][x - 1]));
}
if ((x - 1) >= 0 && (y - 1) >= 0 && mat[y - 1][x - 1] != 'X') {
sons.add(new Node(x - 1, y - 1, null, mat[y - 1][x - 1]));
}
if (x >= 0 && (y - 1) >= 0 && mat[y - 1][x] != 'X') {
sons.add(new Node(x, y - 1, null, mat[y - 1][x]));
}
if ((x + 1) < n && (y - 1) >= 0 && mat[y - 1][x + 1] != 'X') {
sons.add(new Node(x + 1, y - 1, null, mat[y - 1][x + 1]));
}
return sons;
}
}