/**
 * Class with methods for simulating roulette games.
 *   @author Dave Reed
 *   @version 2/15/13
 */
public class RouletteTester {
    public final static int SPINS_PER_ROUND = 100;
    public final static int NUM_OF_ROUNDS = 10000;
    
    /**
     * Simulates a round of bets.
     *   @param betType the type of bet ("red", "black", "odd", "even", or "1".."36")
     *   @param betAmount the amount of each bet in the round
     *   @return the number of credits won or lost during the round
     */
    public static int playRound(String betType, int betAmount) {
        int startAmount = betAmount * RouletteTester.SPINS_PER_ROUND;
        
        RouletteGame game = new RouletteGame();
        game.addCredits(startAmount);
        for (int roundNum = 0; roundNum < RouletteTester.SPINS_PER_ROUND; roundNum++) {
            if (game.checkCredits() > 0) {
                int nextBet = Math.min(betAmount, game.checkCredits());
                game.makeBet(nextBet, betType);
            }
        }
        return game.checkCredits() - startAmount;
    }

    /**
     * Simulates a number of rounds of betting and displays statistics.
     *   @param numRounds the number of rounds to be played
     *   @param spinsPerRound the number of spins/bets in each round
     *   @param betType the type of bet ("red", "black", "odd", "even", or "1".."36")
     */
    public static void playStats(String betType, int betAmount) {
        int numLosses = 0;
        int amountLost = 0;
        for (int roundNum = 0; roundNum < RouletteTester.NUM_OF_ROUNDS; roundNum++) {
            int result = RouletteTester.playRound(betType, betAmount);
            if (result < 0) {
                numLosses++;
            }
            amountLost -= result;
        }
        
        System.out.println(RouletteTester.NUM_OF_ROUNDS + " rounds, with " + 
                           RouletteTester.SPINS_PER_ROUND + " bets per round on " + 
                           betType + ":");
        double lossPercent = 100.0*numLosses / RouletteTester.NUM_OF_ROUNDS;
        System.out.println("    Loss perentage = " + lossPercent + " %");
        double avgLoss = (double)amountLost / RouletteTester.NUM_OF_ROUNDS;
        System.out.println("    Avg loss per game = " + avgLoss);
    }
}
