This repository has been archived by the owner on Apr 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGroupFund.java
89 lines (68 loc) · 2.43 KB
/
GroupFund.java
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
import java.util.*;
public class GroupFund {
public double balance;
public double kairoTotal;
public ArrayList<Proposal> proposalList = new ArrayList<>();
public ArrayList<Player> playerList = new ArrayList<>();
public GroupFund() {
}
// Appends proposal to the GroupFund list
public void addProposal(Proposal p) {
this.proposalList.add(p);
}
// Runs the updating of prices / Kair
public void runCycle() {
// Go through each Proposal
for (Proposal p : this.proposalList) {
// Have each player Support/Against the Proposal
// (Kairo is staked here and goes into the Proposal.)
for (Player player : this.playerList) {
player.reactProposal(p);
}
// Update the prices
p.update();
}
// Go through each Proposal and update the GroupFund balance
for (Proposal p : this.proposalList) {
double newBalance = p.price * p.balance;
this.balance += newBalance;
p.balance = 0;
}
// Redistribute Kairo:
// Iterate through each Proposal
for (int i = 0; i < this.proposalList.size(); i++) {
int supportCount = 0;
for (Player player : this.playerList) {
if (player.proposalSupport.get(i)) {
supportCount++;
}
}
double kairoToDistribute = (proposalList.get(i).kairoAgainst +
proposalList.get(i).kairoSupport);
proposalList.get(i).kairoSupport = 0;
proposalList.get(i).kairoAgainst = 0;
// If Proposal was a WINNER
if (proposalList.get(i).statusVar.toString().equals("WINNER")) {
// Determine amount to distribute (note that we're divvying up the KairoAGAINST)
kairoToDistribute = (kairoToDistribute / supportCount);
// Iterate through players
for (Player player : this.playerList) {
if (player.proposalSupport.get(i)) {
player.kairoBalance += kairoToDistribute;
}
}
}
// If Proposal was a LOSER
else {
// Determine amount to distribute (note that we're divvying up the KairoSUPPORT)
kairoToDistribute = (kairoToDistribute / (playerList.size() - supportCount));
// Iterate through players
for (Player player : this.playerList) {
if (! player.proposalSupport.get(i)) {
player.kairoBalance += kairoToDistribute;
}
}
}
}
}
}