-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
34 lines (32 loc) · 870 Bytes
/
Node.java
File metadata and controls
34 lines (32 loc) · 870 Bytes
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
public class Node implements Denumerable, Comparable<Node>{
Node parent;
int[][] state;
int zerox;
int zeroy;
int g; //how deep (sum of edge, or the total number of moves in this case)
int h; //heuristic cost
int pos;
boolean inFrontier;
public Node(int[][] b, int x, int y, Node parent) {
this.state = b;
this.zerox = x;
this.zeroy = y;
this.parent = parent;
}
public String toString() {
return "( " +zerox + ", " +zeroy +" ) H: " + h + " G: " + g + " F: "+(h+g);
}
public int compareTo(Node n) {
int nf = n.g + n.h;
int f = g + h;
if(nf == f) return 0;
else if(f>nf) return 1;
else return -1;
}
public int getNumber() {
return pos;
}
public void setNumber(int x) {
pos = x;
}
}