-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
65 lines (52 loc) · 1.33 KB
/
Game.java
File metadata and controls
65 lines (52 loc) · 1.33 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
package kuudos;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Queue;
public abstract class Game {
private Queue<Node> queue = new LinkedList<Node>();
private Set<Node> queueSet = new HashSet<Node>();
private char[] sybmols;
public void solve() {
while (queue.peek() != null) {
Node node = queue.poll();
node.update(this);
}
}
public abstract void initialize();
public void enqueueNode(Node node) {
if (!queueSet.contains(node)) {
queue.offer(node);
queueSet.add(node);
}
}
public static class Node {
private List<Node> parents;
private List<Node> children;
private Set<Character> yes;
private Set<Character> no;
public Node(int num) {
parents = new ArrayList<Node>();
children = new ArrayList<Node>();
yes = new HashSet<Character>();
no = new HashSet<Character>();
}
public void attachToChild(Node child) {
this.addChild(child);
child.addParent(this);
}
public void addParent(Node parent) {
parents.add(parent);
}
public void addChild(Node child) {
children.add(child);
}
public void update(Game game) {
for (Node child : children) {
game.enqueueNode(child);
}
}
}
}