Skip to main content
added 6 characters in body
Source Link
Rainbolt
  • 6.4k
  • 6
  • 33
  • 62

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";
    }
}

Probability Gambler

Determines each player's probability towards good and votes for the minority.

public 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";
    }
}

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";
    }
}
Source Link
Wasmoo
  • 644
  • 3
  • 5

Probability Gambler

Determines each player's probability towards good and votes for the minority.

public 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";
    }
}