-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
62 lines (53 loc) · 1.18 KB
/
Copy pathNode.java
File metadata and controls
62 lines (53 loc) · 1.18 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
public class Node {
/*
Node position
*/
int x;
int y;
/*
Integer to store data about or node in. If it has been visited, or where it has passages to
adjacent nodes.
*/
int data;
public Node(int x, int y){
this.x = x;
this.y = y;
data = 0;
}
/*
Add passage:
1st-bit set to 1 = have passage to north
2nd-bit set to 1 = have passage east
4th-bit set to 1 = have passage south
8th-bit set to 1 = have passage west
*/
public void addPassage(int dir){
data = data | dir;
}
/*
Set 16th-bit to 1
*/
public void setVisited(){
data = data | 16;
}
/*
Check if 16th-bit is set to 1
*/
public boolean isVisited(){
return (data & 16) == 16;
}
/*
(When drawing the walls we only need to consider the south and east wall
since these also will function as north and west wall for adjacent nodes.)
Check if 4th-bit is set to 1
*/
public boolean hasSouthWall(){
return (data & 4) != 4;
}
/*
Check if 2nd-bit is set to 1
*/
public boolean hasEastWall(){
return (data & 2) != 2;
}
}