-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMacSim.java
More file actions
130 lines (107 loc) · 3.22 KB
/
MacSim.java
File metadata and controls
130 lines (107 loc) · 3.22 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.util.*;
public class MacSim {
static int SUPPRESS = 2; // Debugging system controller. Has 5 states
// for 5 levels of Debugging detail and cycle style.
// 1: Verbose
// 2: Quarterly reviews
// 3: Yearly reviews and errors/ messages
// 4: Cycle completions
// 5: Quiet mode
static Random rand;
int simLength = 10000; // how long the simulation lasts for
boolean restart = false;
// App variables
InputManager input;
TickerController preController;
TickerController postController;
// Simulation variables
Country country;
long tick;
public static void main(String[] args) throws InterruptedException {
MacSim sim = new MacSim();
rand = new Random();
sim.startSimulation();
}
public void startSimulation() throws InterruptedException {
// Setup instant vars
log(4, "Starting Simulation...");
log(4, "");
reset(20);
while(tick < simLength) {
Thread.sleep(20);
sim();
}
}
Country createCountry(double rate) {
return new Country(15000, 500, rate, SUPPRESS);
}
void sim(Country country) {
tick++; // advance simulation by 1 tick
updatePreController();
logTick();
if(tick%100 == 0 && tick > 0) {
// One year
logYear();
} else if(tick%25 == 0 && tick > 25) {
// One quarter
logQuarter();
}
country.tick(tick);
updatePostController();
}
void logCycle() {
// log("\n\n\n");
// log(3, "Total GDP at start: " + country.startGdp);
// log(3, "Total GDP at finish: " + country.yGdp);
// log(3, "Total growth rate since start: " + country.getTotalGrowthRate());
// log(3, "Annualized growth since start: " + country.getAnnualizedGrowthRate());
// log(3, " or: " + (float)(int)(country.getAnnualizedGrowthRate() * 10000)/100.0 + "%");
// log(3, " \n ");
}
void logYear() {
log(4, " ");
log(4, " ");
log(4, "A year has passed");
log(4, "Year: " + tick/100);
log(4, " ");
}
void logQuarter() {
log(2, " ");
log(2, "A quarter has passed");
country.quarterlyReport();
}
void logTick() {
p(3, ".");
// p(2, "GDP change from last tick: " + 100 * country.dGdp);
}
void updatePreController() {
preController.tick(tick);
}
void updatePostController() {
postController.tick(tick);
}
void reset(double rate) {
country = createCountry(rate);
tick = 0;
preController = new TickerController();
postController = new TickerController();
}
// simloop scheduler
public void sim() {
if(tick > simLength) {
logCycle();
if(restart)
reset(20);
return;
}
sim(country);
}
public static void log(int logLevel, String s) {
if(logLevel < SUPPRESS) return;
System.out.println(s);
}
public static void p(int logLevel, String s) {
if(logLevel < SUPPRESS) return;
System.out.print(s);
}
}