-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.java
61 lines (47 loc) · 1.19 KB
/
State.java
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
import java.util.ArrayList;
public class State {
private Point Square;
private State parent;
private int step;
private int h;
private int g;
public State(State par, Point sq, Point goal) {
this.parent = par;
this.Square = sq;
this.g = this.parent.getStep() + 1;
this.step = this.g;
// Admissible heuristic
this.h = dist(this.Square, goal);
// Non - Admissible heuristic
//this.h = 5 * dist(this.Square, goal);
}
public State(Point sq, Point goal, int st) {
this.parent = null;
this.Square = sq;
this.g = st;
this.step = this.g;
this.h = dist(this.Square, goal);
}
public int getH() {
return this.h;
}
public int getG() {
return this.g;
}
public int getStep() {
return this.step;
}
public void incStep() {
this.step += 1;
return;
}
public Point getSq() {
return this.Square;
}
public State getParent() {
return this.parent;
}
private static int dist(Point a, Point b) {
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
}
}