-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
98 lines (90 loc) · 3.63 KB
/
Node.java
File metadata and controls
98 lines (90 loc) · 3.63 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
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
import sun.awt.image.ImageWatched;
import java.util.Hashtable;
import java.util.LinkedList;
public class Node {
LinkedList<Person> above;
Node parent;
Person val;
LinkedList<Person> children;
LinkedList<Node> ChildrenNodes;
int score;
int depth;
Boolean tested;
public Node(LinkedList<Person> above, Node parent, LinkedList<Person> children, Person val, int depth) {
this.above = above;
this.parent = parent;
this.children = new LinkedList<>();
this.children.addAll(children);
this.ChildrenNodes = new LinkedList<>();
this.tested = false;
this.val = val;
this.depth = depth;
}
public LinkedList<Person> getChildren(LinkedList<Person> contestants){
LinkedList<Person> children = new LinkedList<>();
children.addAll(contestants);
children.removeAll(above);
children.remove(val);
return children;
}
public Node addChildNode(LinkedList<Person> grandChildren, LinkedList<Person> toskip, LinkedList<Person> newabove){
//System.out.println("in new node depth:" +depth+", to pick" + grandChildren.toString());
Person newVal = grandChildren.getFirst();
return addChildNode(grandChildren, toskip, newabove, newVal);
}
public Node addChildNode(LinkedList<Person> grandChildren, LinkedList<Person> toskip, LinkedList<Person> newabove, Person val){
//System.out.println("in new node depth:" +depth+", to pick" + grandChildren.toString());
grandChildren.remove(val);
grandChildren.addAll(toskip);
for(int i =0; i<ChildrenNodes.size(); i++){
grandChildren.add(ChildrenNodes.get(i).val);
}
Node c = new Node(newabove,this, grandChildren, val, depth+1);
this.ChildrenNodes.add(c);
this.children.remove(c.val);
//System.out.println("val n: " + c.val);
//System.out.println("above n: " + c.above);
//System.out.println("children n: " + c.children);
return c;
}
public LinkedList<Person> getNewAbove(){
LinkedList<Person> newabove = new LinkedList<>();
newabove.addAll(above);
if(val != null){
newabove.add(val);
}
//System.out.println("newabove size " + newabove.size() +" depth" + depth);
return newabove;
}
public LinkedList<Person> getAvailChildren(LinkedList<Person> contestants, LinkedList<Person> toskip, LinkedList<Person> newabove, boolean noRepeat ){
//System.out.println("newA n: " + newabove);
//System.out.println("con n: " + contestants);
LinkedList<Person> grandChildren = new LinkedList<>();
//System.out.println("val n: " + val);
//System.out.println("above n: " + above);
//System.out.println("children n: " + children);
grandChildren.addAll(contestants);
//grandChildren.removeAll(newabove);
for(int i =0; i<newabove.size(); i++){
if(grandChildren.contains(newabove.get(i))) {
grandChildren.remove(newabove.get(i));
}
}
//System.out.println(grandChildren);
//System.out.println("...");
//System.out.println(ChildrenNodes);
if(noRepeat){
for(int i =0; i<ChildrenNodes.size(); i++){
grandChildren.remove(ChildrenNodes.get(i).val);
}
}
//System.out.println(grandChildren);
//grandChildren.removeAll(toskip);
for(int i=0; i<toskip.size(); i++){
if(grandChildren.contains(toskip.get(i))){
grandChildren.remove(toskip.get(i));
}
}
return grandChildren;
}
}