Probability Gambler
Determines each player's probability towards good and votes for the minority.
public final class ProbabilityGambler extends Human {
@Override
public String takeSides(String history) throws Exception {
if (history.length() == 0) return "evil";
String[] rounds = history.split(",");
double players[] = new double[rounds[0].length()];
for (String round : rounds) {
for (int i = 0; i < players.length; i++) {
if (round.charAt(i) == '1') {
players[i] = players[i] + 1;
}
}
}
double expected = 0;
for (int i = 0; i < players.length; i++) {
expected += players[i]/rounds.length;
}
return 1-(int)Math.round(expected / players.length) == 1 ? "good" : "evil";
}
}