-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomaton.java
More file actions
71 lines (53 loc) · 1.53 KB
/
Copy pathAutomaton.java
File metadata and controls
71 lines (53 loc) · 1.53 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
import java.util.LinkedList;
public class Automaton{
private Rule rule;
private LinkedList<Generation> generations = new LinkedList<>();
private BoundaryConditions bc;
public Automaton(Rule rule, Generation init, BoundaryConditions bc) {
this.rule = rule;
generations.add(init);
this.bc = bc;
}
public Rule getRule() {
return rule;
}
public Generation getGeneration(int stepNum) throws InvalidStepNumException {
if(stepNum < 0) {
throw new InvalidStepNumException();
}
if(generations.size() - 1 < stepNum) {
evolve(stepNum - getTotalSteps());
return generations.get(getTotalSteps());
}
return generations.get(stepNum);
}
public BoundaryConditions getBoundaryConditions() {
return bc;
}
public void evolve (int numSteps) throws InvalidStepNumException {
if(numSteps < 0) {
throw new InvalidStepNumException();
} else {
for(int count = 0; count < numSteps; count++) {
generations.add(rule.evolve(generations.get(getTotalSteps()), bc));
}
}
}
public int getTotalSteps() {
return generations.size() - 1;
}
public String toString() {
return generations.get(getTotalSteps()).toString();
}
public String getHistory() {
String automaton = "";
for(int i = 0; i < generations.size(); i++) {
if(i < getTotalSteps()) {
automaton = automaton + generations.get(i).toString() + '\n';
} else {
automaton = automaton + generations.get(i).toString();
}
}
return automaton;
}
}