-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.java
More file actions
39 lines (33 loc) · 781 Bytes
/
Copy pathState.java
File metadata and controls
39 lines (33 loc) · 781 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
package uk.ac.hw.macs.search;
/**
* Represents a state in the search space. You need to include a method for determining whether a state is a
* goal state, and one for computing the heuristic value.
*/
public interface State {
public int x;
public int y;
public static int Goalx;
public static int Goaly;
public State (int x, int y, boolean goal) {
this.x = x;
this.y = y;
if (x == Goalx && y == Goaly){
this.goal = true;
}
}
public boolean isGoal(int x, int y){
this.x = x;
this.y = y;
if (x == Goalx && y == Goaly){
return true;
} else {
return false;
}
}
public int getHeuristic(int x, int y){
this.x = x;
this.y = y;
int h = Math.abs(Goalx - x) + Math.abs(Goaly - y);
return h;
};
}