/**
 * Calculates the probability of victory for Thor.
 * 
 * Thor has nine 4-sided dice and Zeus has six 6-sided dice. They roll their dice and add 
 * up the numbers. The highest total wins. 
 * 
 * @author Drue Coles
 */
public class ThorVsZeus {

    public static void main(String[] args) {
        CupOfDice thorCup = new CupOfDice(9, 4); // nine 4-sided dice
        CupOfDice zeusCup = new CupOfDice(6); // six 6-sided dice
        
        // Monte Carlo simulation
        final int games = 1_000_000;
        int thorWins = 0;
        for (int i = 0; i < games; i++) {
            int thorSum = sum(thorCup.roll());
            int zeusSum = sum(zeusCup.roll());
            if (thorSum > zeusSum) {
                thorWins++;
            }
        }
        
        // Display probability with 2 digits of precision.
        double prob = (double) thorWins / games * 100.0;
        System.out.printf("Thor beats Zeus with probability %.2f%% %n", prob);
    }
    
    /**
     * Returns the sum of integers in a given array.
     */
    private static int sum(int[] a) {
        int sum = 0;
        for (int i : a) {
            sum += i;
        }
        return sum;
    }
}