//roulette simulation
//martingale betting system
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

bool spinWheel();

int main()
{
    int initcash = 40960;
    int cash = initcash;
    int baseBet = 10;
    int currBet = baseBet;
    int winorlose = 10;
    int highestCashOnHand = 0;
    int wins = 0;
    int losses = 0;
    int totCredit = 0;
    int totChange = 0;
    int totDebt = 0;
    
	/*for(int i = 10; i < 100000; i *= 2)
	{
		cout << i << endl; // determines optimal initial cash in hand
	}
	cout << endl;*/

	srand ( time(0));
	for (int runthismanytime = 0; runthismanytime < 20; runthismanytime++) //this many different people
	{
		totChange = 0;
		totDebt = 0;
		totCredit = 0;
		for(int cc = 0; cc<100; cc++)//Each day, visit the casino for 100 days
		{
			cash = initcash;
			currBet = baseBet;

		   	for(int count = 0; count < 30; count++ )//Each day you visit the casino, play 30 roulette games
		    	{        
				winorlose = spinWheel();
				if(winorlose) //won
				{
					cash += currBet; //win your bet
					currBet = baseBet; //reset bet back to minimum
				}
				else //lost
				{
					cash -= currBet; //lose your bet
					currBet *= 2; //double current bet
				}	
				if(cash < 10)
					count = 300; //break out of loop
			}

			if(cash > initcash)
				totCredit+= (cash - initcash);
			else
				totDebt+= (initcash - cash);
		}
		totChange = totCredit - totDebt;
		cout << "Profit: " << totChange << endl;
	}
        return 0;
}

bool spinWheel()
{
//38 possibilities
//18 are red, 18 black, two neither
//assume you have an 18 in 38 chance of winning

    int spunwhat = rand() % 38; // outputs number between 00 and 36
    if(spunwhat > 18 && spunwhat < 37)
	return true; //win (returns 18 out of 38 wins)

    return false;   //false  (returns 19 out of 38 as losses)
}




