-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.java
65 lines (54 loc) · 1.75 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
import java.util.ArrayList;
public class Node {
Cat data;
Node parent;
ArrayList<Cat> children;
public double fofN = 0;
public Node(Cat x, Node p, double f) {
data = x;
parent = p;
children = validMoves(x);
fofN = f;
}
//Adds all moves on gameboard to array
public ArrayList<Cat> validMoves(Cat parent) {
ArrayList<Cat> goodMoves = new ArrayList<>();
Cat temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveDLeft();
if (temp != null) {
goodMoves.add(temp);
}
temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveDRight();
if (temp != null) goodMoves.add(temp);
temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveLDown();
if (temp != null) goodMoves.add(temp);
temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveLUp();
if (temp != null) goodMoves.add(temp);
temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveRDown();
if (temp != null) goodMoves.add(temp);
temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveRUp();
if (temp != null) goodMoves.add(temp);
temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveULeft();
if (temp != null) goodMoves.add(temp);
temp = new Cat(parent.Xcor, parent.Ycor);
temp = temp.moveURight();
if (temp != null) goodMoves.add(temp);
return goodMoves;
}
//Finds depth of node
public int depthOfNode() {
int depth = 0;
Node c = this;
while (c.parent != null) {//if the parent is null top of the node
depth++;
c = c.parent;
}
return depth;
}
}