-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAStarMap.java
More file actions
69 lines (44 loc) · 1.5 KB
/
Copy pathAStarMap.java
File metadata and controls
69 lines (44 loc) · 1.5 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
import java.util.ArrayList;
import java.util.Vector;
/* The map class, basically a regular grid where each node is an object
* of the node class.
*/
//Currently supports only 2D!!!
public class AStarMap {
private Vector <Vector<Node>> map;
public final int height, width;
public AStarMap( boolean[][] m, int height, int width ) {
map = new Vector < Vector <Node> > ();
for( int i = 0; i < height; i++) {
Vector <Node> row = new Vector <Node> ();
for( int j = 0; j < width; j++) {
Node n = new Node( i, j, m[i][j] );
row.add( n );
}
map.add( row );
}
this.height = height;
this.width = width;
}
// Obtain the neighbour nodes of a given node in the map.
public ArrayList<Node> getNeighbourNodes( Node n ) {
System.out.println(" NEIGHBOUR NODES FUNCTION ");
Vector <Integer> v = new Vector <Integer> (n.getVector());
ArrayList <Node> l= new ArrayList <Node> ();
System.out.println(" Element at 0: " + v.elementAt(0));
System.out.println(" Element at 1: " + v.elementAt(1));
for( int i = v.elementAt(0) - 1; i <= v.elementAt(0) + 1; i++ ) {
for( int j = v.elementAt(1) - 1; j <= v.elementAt(1) + 1; j++ ) {
if( i < 0 || j < 0 || i >= height || j >= width)
continue;
if( (i == v.elementAt(0)) && (j == v.elementAt(1)) )
continue;
Node temp = new Node( (map.elementAt(i)).elementAt(j) );
if( !temp.is_passable )
continue;
l.add(temp);
}
}
return l;
}
}