-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
43 lines (37 loc) · 1.07 KB
/
Node.java
File metadata and controls
43 lines (37 loc) · 1.07 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
package com.company;
// represents a node in the search tree
public class Node {
public State state;
public Node parent;
public Board.Direction action;
public int pathCost;
public int heuristicVal;
public int gValue;
// constructs a node
public Node(State s, Node p, Board.Direction a, int hf){
this.state = s;
this.parent = p;
this.action = a;
if(hf==1) heuristicVal = s.getHeuristicValue();
else heuristicVal = s.getHeuristic2Value();
if(p!=null) this.gValue = 1 + p.getGValue();
else this.gValue = 0;
this.pathCost = heuristicVal + gValue;
}
// gets the path cost of this node
public int getPathCost() {
return pathCost;
}
// gets gValue of this node;
public int getGValue(){
return this.gValue;
}
// gets heuristicVal
public int getHeuristicVal(){
return heuristicVal;
}
// gets the state corresponding to this node
public State getState() {
return state;
}
}