-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.java
111 lines (108 loc) · 2.15 KB
/
Node.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.LinkedList;
import java.util.Stack;
public class Node {
private Board board;
private int distance;
private float f_grade;
private LinkedList<Node> neighbors;
private Node father;
private String move;
public Node(int _distance)
{
board = new Board();
distance=_distance;
f_grade = calcGrade();
neighbors = new LinkedList<Node>();
father=null;
setMove(null);
}
public void add_n(Node neighbor)
{
neighbors.add(neighbor);
}
public void add_ns(LinkedList<Node> _neighbors)
{
neighbors.addAll(_neighbors);
}
public LinkedList<Node> getNeighbors() {
return neighbors;
}
public void setNeighbors(LinkedList<Node> neighbors) {
this.neighbors = neighbors;
}
public float calcGrade()
{
f_grade=board.h()+distance;
return board.h()+distance;
}
public Board getBoard() {
return board;
}
public void setBoard(Board board) {
this.board = board;
}
public int getDistance() {
return distance;
}
public void setDistance(int distance) {
this.distance = distance;
this.calcGrade();
}
public float getF_grade() {
return f_grade;
}
public void setF_grade(float f_grade) {
this.f_grade = f_grade;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((board == null) ? 0 : board.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Node other = (Node) obj;
if (board == null) {
if (other.board != null)
return false;
} else if (!board.equals(other.board))
return false;
return true;
}
boolean is_traget()
{
return board.isTargetBoard();
}
public Node getFather() {
return father;
}
public void setFather(Node father) {
this.father = father;
}
public Stack trackBack()
{
int counter =0;
Stack moveStack=new Stack<String>();
Node current = this;
while(current!=null)
{
if(current.getMove()!=null)
moveStack.push(current.getMove());
current = current.getFather();
counter++;
}
return moveStack;
}
public String getMove() {
return move;
}
public void setMove(String move) {
this.move = move;
}
}