-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCell.java
More file actions
47 lines (46 loc) · 971 Bytes
/
Cell.java
File metadata and controls
47 lines (46 loc) · 971 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
35
36
37
38
39
40
41
42
43
44
45
46
47
public class Cell implements Comparable<Cell>{
private int x,y;
private int f,g,h;
private Cell parent;
public Cell(int x, int y){
this.x=x;
this.y=y;
f = 0;
g = 0;
h = 0;
}
public Cell(int x, int y, Cell parent){
this.x=x;
this.y=y;
this.parent = parent;
}
public Cell(int x, int y, int goalX, int goalY, Cell parent){
this.x=x;
this.y=y;
this.parent=parent;
h = Math.abs(goalX-x)+Math.abs(goalY-y);
g = parent.getG()+1;
f = g+h;
}
public int getG(){
return g;
}
public int getF(){
return f;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public int compareTo(Cell other){
return f-other.getF();
}
public Cell getParent(){
return parent;
}
public boolean hasParent(){
return parent!=null;
}
}