 /**
 * Class with methods for simulating roulette games.
 *   @author Dave Reed
 *   @version 9/15/15
 */
public class RouletteTester {
    public final static int NUM_OF_ROUNDS = 100000;
    public final static int START_AMOUNT = 100;
    public final static int BET_AMOUNT = 1;
    
    /**
     * Simulates a round of bets using a uniform betting strategy.
     *   @param betType the type of bet ("red", "black", "odd", "even", or "1".."36")
     *   @param betsPerRound the number of bets to be carried out in this round
     *   @return the number of credits won or lost during the round
     */
    public static int playRound(String betType, int betsPerRound) {
        RouletteGame game = new RouletteGame();
        game.addCredits(RouletteTester.START_AMOUNT);
        for (int betNum = 0; betNum < betsPerRound; betNum++) {
            if (game.checkCredits() > 0) {
                int nextBet = Math.min(RouletteTester.BET_AMOUNT, game.checkCredits());
                game.makeBet(nextBet, betType);
            }
        }
        return game.checkCredits() - RouletteTester.START_AMOUNT;
    }

    /**
     * Simulates a number of rounds of betting and displays statistics.
     *   @param betType the type of bet ("red", "black", "odd", "even", or "1".."36")
     *   @param betsPerRound the number of bets in each round
     */
    public static void playStats(String betType, int betsPerRound) {
        int numLost = 0;
        int amountLost = 0;
        int maxLost = 0;
        int result;
        for (int roundNum = 0; roundNum < RouletteTester.NUM_OF_ROUNDS; roundNum++) {
            result = RouletteTester.playRound(betType, betsPerRound);            
            if (result < 0) {
                numLost++;
                if (-result > maxLost) {
                    maxLost = -result;
                }
            }
            amountLost -= result;
        }
        
        System.out.println(RouletteTester.NUM_OF_ROUNDS + " rounds, with " + 
                           betsPerRound + " bets per round on " + betType + ":");
        double percent = 100.0*numLost / RouletteTester.NUM_OF_ROUNDS;
        System.out.println("    Loss percentage = " + percent + " %");
        double avgLost = (double)amountLost / RouletteTester.NUM_OF_ROUNDS;
        System.out.println("    Avg lost per round = " + avgLost);
        System.out.println("    Maximum lost = " + maxLost);
    }
}
