% gambler.m for Math 152
% Code for showing the time evolution of gambler's ruin.

clear all ; close all ;

D = 10 ;   % Total of gambler's stake plus the house's stake
d = 2 ;    % The gambler's initial stake.
w = 0.49 ; % The probablity of the gambler's winning each hand.
T =10 ;    % final time

P = zeros(D+1,D+1);
P(1,1) = 1; 
P(D+1,D+1) = 1; 
for j = [2:D]
     P(j+1,j) = w;    
     P(j-1,j) = 1-w;    
end

X= zeros(D+1,1) ;
X(d+1) = 1 ;

disp(['The gambler starts with ' ,  num2str(d)])
disp(['The house   starts with ' , num2str(D-d)])
disp(['The probablity that the gambler wins a hand is ' , num2str(w)])
disp(' ')

%disp('The probability transition matrix is'), P

for t= [0:T]
   disp( [ 'At time ' , num2str(t) , ', the gambler has probability distribution'] )
   disp( num2str(X', '%4.3f ') )
   disp(' ')
   X = P*X ;
end

