#   gambler's ruin program
import sys, random
import matplotlib.pyplot as plt

def gamble(p1, g1_amt, g2_amt):
#
#   YOUR CODE GOES HERE
#     g1_seq (and g2_seq) is a list with holds the amount 
#     held by g1(g2) at the end of each step in the game
#     steps = total number of steps executed in gamble
#   Hint : Execute a while loop to play each game 
#     until one of the players wins (the other has zero) 
#   
    return g1_seq, g2_seq, steps

   
p  = float(input('Enter probability of gambler1 winning:  '))
if p<= 0.0 or p>=1 :
    print ('Probability entered =', p, ' prob must be between 0 and 1')
    sys.exit(0)
g1 = int(input('Enter bankroll for gambler1: '))
g2 = int(input('Enter bankroll for gambler2: '))
#   Execute gambler's game
#
g1_walk,g2_walk, num_steps = gamble(p, g1, g2) 
#
#   Plot Gambler 1 and 2 step sequences for game
#     on the same graph
#
x = range(num_steps+1)
plt.plot(x, g1_walk,'r-', label = 'Gambler1')
plt.plot(x, g2_walk,'b-', label = 'Gambler2')
plt.legend(loc= 'upper left')
plt.title(' Gambler\'s ruin: p='+ str(p)+ ', g1 = $'+ str(g1)+ ', g2 = \$= '+ str(g2))
plt.grid(True)  
plt.show()


