-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathALifeSim.java
More file actions
49 lines (36 loc) · 1.53 KB
/
ALifeSim.java
File metadata and controls
49 lines (36 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
import java.io.PrintWriter;
/**
* The driver class.
* Runs different experiments and
* prints the results.
*/
public class ALifeSim {
//main----------------------------------------
public static void main(String[] args) throws Exception {
PrintWriter pen = new PrintWriter("testing/pop100coop33.txt");
if (args.length != 4) {
throw new Error("Invalid number of arguments");
}
int iterations = Integer.parseInt(args[0]);
int cooperators = Integer.parseInt(args[1]);
int defectors = Integer.parseInt(args[2]);
int partialCooperators = Integer.parseInt(args[3]);
Pair<String, Integer>[] startingNumbers = (Pair<String, Integer>[]) (new Pair[3]);
startingNumbers[0] = new Pair<String, Integer>("Cooperator", cooperators);
startingNumbers[1] = new Pair<String, Integer>("Defector", defectors);
startingNumbers[2] = new Pair<String, Integer>("PartialCooperator", partialCooperators);
Population pop = new Population(startingNumbers);
for (int j = 0; j < 10; j++) {
for (int i = 0; i < iterations; i++) {
pop.update();
}
Pair<String, Integer>[] finalNumbers = pop.getPopulationCounts();
pen.println("After " + iterations + " ticks:");
pen.println("Cooperators = " + finalNumbers[0].getRight());
pen.println("Defectors = " + finalNumbers[1].getRight());
pen.println("Partial Cooperators = " + finalNumbers[2].getRight());
pen.println("\nMean Cooperation Probability = " + pop.calculateCooperationMean());
}
pen.close();
}
}