The house always wins : Monte Carlo Simulation
Now, let’s simulate different scenarios in Python to visualize the different outcomes if the player kept betting continuously.

1.Import the required libraries

#Import libraries

import random

import matplotlib.pyplot as plt

2.We need a dice simulator which throws a value from 1–100 with uniform probability distribution. Let’s create a function in Python which returns ‘True’ if the player wins and ‘False’ if the Casino wins.

#Create function for simulating die roll

#The die can take values from 1 to 100. If the number is between 1 #and 51, the house wins.

#If the number is between 52 and 100, the player wins. def rolldice():



dice = random.randint(1,100)



if dice <=51:

return False

elif dice >51 & dice <=100:

return True

3.Create a function that simulates the bets. We need to provide three arguments for the function :

i. Total funds : The money the player is starting with ($10,000)

ii. Wager Amount : The amount the player bets in each game ($100)

iii. Total plays : The number of times the player plays the game (This value is changed for creating different scenarios)

#Define a function for the play which takes 3 arguments :

#1. total_funds = total money in hand the player is starting with

#2. wager_amount = the betting amount each time the player plays

#3. total_plays = the number of times the player bets on this game def play(total_funds, wager_amount, total_plays):



#Create empty lists for :

# 1.Play_number and

# 2.Funds available

# 3.Final Fund

Play_num = []

Funds = [] #Start with play number 1

play = 1

#If number of plays is less than the max number of plays we have set

while play < total_plays:

#If we win

if rolldice():

#Add the money to our funds

total_funds = total_funds + wager_amount

#Append the play number

Play_num.append(play)

#Append the new fund amount

Funds.append(total_funds)

#If the house wins

else:

#Add the money to our funds

total_funds = total_funds - wager_amount

#Append the play number

Play_num.append(play)

#Append the new fund amount

Funds.append(total_funds)



#Increase the play number by 1

play = play + 1

#Line plot of funds over time

plt.plot(Play_num,Funds)

Final_funds.append(Funds[-1])

return(Final_funds)

4. Finally, run a loop to call the above functions and simulate the game for multiple scenarios. To be confident of the end results of our game, each scenario will be simulated 100 times.

#Call the function to simulate the plays and calculate the remaining #funds of the player after all the bets

#Intialize the scenario number to 1

x=1

#Create a list for calculating final funds

Final_funds= [] while x<=100:

ending_fund = play(10000,100,5)

x=x+1 #Plot the line plot of "Account Value" vs "The number of plays"

plt.ylabel('Player Money in $')

plt.xlabel('Number of bets')

plt.show() #Print the money the player ends with

print("The player starts the game with $10,000 and ends with $" + str(sum(ending_fund)/len(ending_fund)))

5. Let’s visualize 7 different scenarios using the following graphs. In each scenario Jack bets n number of times.

For generating multiple scenarios, use the above block of code (#4), but only modify the highlighted code (shown below) to tweak the number of bets the player makes.

ending_fund = play(10000,100,5)

x-axis : The number of bets Jack makes

y-axis : Jack’s account balance after each bet

Each graph shows Jack’s account balance as he continues to play the game. Also, to find out Jack’s ending balance, we would be averaging out the balance from the 100 different simulations.

The aim of this experiment is to answer a simple question- “if a person starts with $10,000 and plays this game n number of times (and places a bet of $100 in each game), on an average, how much money would the player end up with ?”

Scenario 1 -> No. of bets : 5

Scenario 2 -> No. of bets : 10

Scenario 3 -> No. of bets : 50

Scenario 4 -> No. of bets: 100

Scenario 5 -> No. of bets : 500

Scenario 6 -> No. of bets : 1000

Scenario 7 -> No. of bets : 10000

From the simulation experiment, we can observe that Jack has a better chance of making a profit (or minimize loss), if he places fewer bets.

It can also be observed that the amount lost in every scenario is approximately 2% of the betting amount (same as the house edge). For example, in our final scenario — Jack made 10,000 bets, each for $100. So we would expect Jack to lose approximately (10,000)*(0.02*100), which amounts to $20,000.

Moreover, in the last scenario when he plays 10,000 times, the funds have become negative, i.e Jack has lost more money than what he started with (In real life, it means Jack lost all his money).

In short, THE HOUSE ALWAYS WINS !
['Rohan Joseph']
['Machine Learning', 'Deep Learning', 'Visualization', 'Data Science', 'Data']