%% Math 152: Random walk demo
% The "somewhat nerdy" Example 4.1 from notes.pdf
% Now with shields.

Xs = 2/3;  % Xavier's spell works
Ys = 1/2;  % Ydnew's spell works

P = zeros(10, 10);
P(5, 1) = Xs;
P(8, 1) = 1 - Xs;
P(6, 2) = Xs;
P(7, 2) = 1 - Xs;
P(7, 3) = Xs;
P(9, 3) = 1 - Xs;
P(8, 4) = Xs;
P(9, 4) = 1 - Xs;

P(1, 5) = Ys;
P(2, 5) = 1 - Ys;
P(2, 6) = Ys;
P(10, 6) = 1 - Ys;
P(3, 7) = Ys;
P(10, 7) = 1 - Ys;
P(3, 8) = Ys;
P(4, 8) = 1 - Ys;

P(9,9) = 1;
P(10,10) = 1;


%% check column sums
% sum(P, 1)
% 6*P        # (debugging trick)

x0 = zeros(10, 1);  x0(1) = 1;

%% short duel
x = P^5*x0
P_Y_wins = sum(x([5:8 10]))
P_Y_wins = 1 - x(9)

%% long duel
x = x0;
for n=1:50
  x = P*x
end
x
