 /**
 * Class with methods for simulating roulette games.
 *   @author Dave Reed
 *   @version 9/14/17
 */
public class RouletteStats {
    public final static int START_CREDITS = 100;
    public final static int BET_AMOUNT = 1;
    
    /**
     * Simulates a session of bets using a uniform betting strategy.
     *   @param betType the type of bet ("red", "black", "odd", "even", or "1".."36")
     *   @param numBets the number of bets to be carried out in this session
     *   @return the number of credits won or lost during the round
     */
    public static int playSession(String betType, int numBets) {
        RouletteGame game = new RouletteGame();
        game.addCredits(RouletteStats.START_CREDITS);
        int nextBet = RouletteStats.BET_AMOUNT;
        for (int betNum = 0; betNum < numBets; betNum++) {
            String result = game.makeBet(nextBet, betType);
            // System.out.println(result);
        }
        return game.checkCredits() - RouletteStats.START_CREDITS;
    }

    /**
     * Simulates a number of sessions of betting and displays statistics.
     *   @param betType the type of bet ("red", "black", "odd", "even", or "1".."36")
     *   @param numBets the number of bets in each session
     *   @param numSessions the number of sessions to simulate
     */
    public static void playManySessions(String betType, int numBets, int numSessions) {
        int numLosingSessions = 0;
        int totalAmountLost = 0;
        int maxAmountLost = 0;
        for (int sessionNum = 0; sessionNum < numSessions; sessionNum++) {
            int result = RouletteStats.playSession(betType, numBets);            
            if (result < 0) {
                numLosingSessions++;
                if (-result > maxAmountLost) {
                    maxAmountLost = -result;
                }
            }
            totalAmountLost -= result;
        }
        
        System.out.println(numSessions + " sessions, with " + 
                           numBets + " bets per session on " + betType + ":");
        double lossPercent = 100.0*numLosingSessions / numSessions;
        System.out.println("    Loss percentage = " + lossPercent + " %");
        double avgAmountLost = (double)totalAmountLost / numSessions;
        System.out.println("    Avg lost per session = " + avgAmountLost);
        System.out.println("    Maximum lost = " + maxAmountLost);
    }
}
