-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusinessCycle.java
More file actions
65 lines (54 loc) · 2 KB
/
BusinessCycle.java
File metadata and controls
65 lines (54 loc) · 2 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
import java.util.*;
public class BusinessCycle extends Cycle {
Random rand;
int tick; // current tick, determines economic multiplier provided
// by cycle
int switchToRecession; // int at which economy enters recession
int length; // trough to trough tick length
double currentExtremity; // value between 0-1 on progress to next stage of cycle
double crashExtremity; // number between 12-24
double growthExtremity; // number between -1 and 8
boolean inRecession = false;
double growthFromStart;
public BusinessCycle(int length, int extremity) {
rand = new Random();
this.length = length;
tick = 0;
double switchDelta = 0.7;
switchToRecession = (int)(switchDelta * length);
// log("Length of cycle: " + length);
// log("Switch to recession: " + switchToRecession);
crashExtremity = 8 + rand.nextDouble() * 32;
// crashExtremity = rand.nextDouble() * (extremity + 1) * 4;
growthExtremity = rand.nextDouble() * (extremity + 1) * 1.5;
}
public void tick() {
tick++;
if(tick == switchToRecession && !inRecession) {
inRecession = true;
currentExtremity = 0;
}
if(!inRecession) {
currentExtremity += 1/(double)switchToRecession;
} else if(inRecession){
currentExtremity += 1/(double)(length - switchToRecession);
}
}
public boolean complete() {
return (length == tick);
}
public double multiplier() {
if(!inRecession) {
// growth multiplier
// log("Growth multiplier: " + currentExtremity * growthExtremity);
return currentExtremity * growthExtremity;
} else {
// recession multiplier
// log("Recession multiplier: " + currentExtremity * growthExtremity);
return (1-currentExtremity) * crashExtremity * -1;
}
}
public void log(String s) {
System.out.println(s);
}
}