%drunkensailor %Darvell Powell %Clear data and command window, standard procedure... clear %Constant Probability p=input('Please enter a probability from 0.00 to 1.00 '); %0.50 while p>1.00 p=input('please enter a probability frop 0.00 to 1.00 '); end %Number of steps nessesary n=20; %Range for planks (y values) ya=[0:n:n]; %Length of (steps) %inital position of sailor is %(5,-3) x = 5; y = -2; steps = 0; dead = 0; %setup parameters for our movie.. reruns=1; % number of times movie is to play fps=2; % frames per second nframes = 15; % number of frames in the movie Frames = moviein(nframes); % initialize the matrix 'Frames' %movement of sailor while steps < n steps = steps + 1 r = rand; r = r + p; if r >= 0.75 % 60% chance of going straight y = y + 2; elseif r <= 0.45 % 20% chance of going right y = y + 2; x = x + 2; else y = y + 2; x = x - 2; end if x>11 disp('o help me i am dying, i need 20 pts on this assignment') break else if x<-1 disp('o help me please, i need 20 pts on this assignment') break else if y>=20 disp('success, congrats you made it but dont drink next time cuz you might not get lucky! for now you get 20 pts') load handel sound(y,Fs) break end disp('success') end end %First plank xa=[-1,-1]; %Second Plank xb=[1,1]; %Third Plank xc=[3,3]; %Fourth Plank xd=[5,5]; %Fifth Plank xe=[7,7]; %Sixth Plank xf=[9,9]; %Seventh Plank xg=[11,11]; %Plot the planks plot(xa,ya,'g',xb,ya,'g',xc,ya,'g',xd,ya,'k',xe,ya,'g',xf,ya,'g',xg,ya,'g'); axis([xa(1)-2, xg(1)+2, ya(1)-3, n+2]); hold on plot(x,y,'*'); Frames(:,steps)=getframe; hold off end %Playback our creation movie(Frames,reruns,fps)