 /**
 * Class with methods for simulating roulette games.
 *   @author Dave Reed
 *   @version 2/4/17
 */
public class RouletteTester {
    public final static int DEFAULT_START = 100;
    public final static int DEFAULT_BET = 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.DEFAULT_START);
        int nextBet = RouletteTester.DEFAULT_BET;
        for (int betNum = 0; betNum < betsPerRound; betNum++) {
            game.makeBet(nextBet, betType);
        }
        return game.checkCredits() - RouletteTester.DEFAULT_START;
    }

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