-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
64 lines (52 loc) · 1.17 KB
/
Copy pathNode.java
File metadata and controls
64 lines (52 loc) · 1.17 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
63
64
public class Node implements Comparable<Node> {
public BoardState state;
public Node parent;
public double utility;
public int depth;
Node(BoardState state)
{
this.state = state;
this.parent = null;
this.utility = 0.0;
this.depth = 0;
}
Node(BoardState state, Node parent, double utility, int depth)
{
this.state = state;
this.parent = parent;
this.utility = utility;
this.depth = depth;
}
@Override
public int hashCode()
{
return state.hashCode();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj instanceof BoardState) {
BoardState state = (BoardState)obj;
return state.equals(this.state);
}
return false;
}
@Override
public int compareTo(Node node)
{
return (int)Math.signum(this.utility - node.utility);
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(state);
sb.append(parent == null ? "Has no parent \n" : "Has parent \n");
sb.append("Utility = " + utility + "\n");
sb.append("Depth = " + depth + "\n");
return sb.toString();
}
}