/**
 * Class with static methods for simulating roulette games.
 *   @author Dave Reed
 *   @version 2/4/12
 */
public class RouletteTester {
    private int startAmount;
    private int betAmount;
    
    /**
     * Constructs a RouletteTester object.
     *   @param startAmt the initial number of credits for each round
     *   @param betAmt the default bet for each spin in a round
     */
    public RouletteTester(int startAmt, int betAmt) {
        this.startAmount = startAmt;
        this.betAmount = betAmt;
    }
    
    /**
     * Simulates a round of bets.
     *   @param spinsPerRound the number of spins/bets in the round
     *   @param betType the type of bet ("red", "black", "odd", "even", or "1".."36")
     *   @return the number of credits won or lost during the round
     */
    public int playRound(int spinsPerRound, String betType) {
        RouletteGame game = new RouletteGame();
        game.addCredits(this.startAmount);
        for (int roundNum = 0; roundNum < spinsPerRound; roundNum++) {
            int nextBet = Math.min(this.betAmount, game.checkCredits());
            game.makeBet(nextBet, betType);
        }
        return game.checkCredits() - this.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 void playStats(int numRounds, int spinsPerRound, String betType) {
        int numLosses = 0;
        int totalLosses = 0;
        for (int roundNum = 0; roundNum < numRounds; roundNum++) {
            int result = this.playRound(spinsPerRound, betType);
            if (result < 0) {
                numLosses++;
            }
            totalLosses -= result;
        }
        
        System.out.println(numRounds + " rounds, with " + spinsPerRound + 
                           " bets per round on " + betType + ":");
        double lossPercent = 100.0*numLosses / numRounds;
        System.out.println("    Loss perentage = " + lossPercent + " %");
        double avgLoss = (double)totalLosses / numRounds;
        System.out.println("    Avg loss per game = " + avgLoss);
    }
}
