Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
feval(@assignin,'caller','score',500);
pwidth=50; % Total size +/- 50 for 101 Paddle
bwidth=10; % Radius of ball
vup=10; % Sub-sampling ball movements for Interactive
spfx=1.08; % Speed increase factor
spfy=1.04; % to Avoid fixed Paddle solution
negVmax=-200;
posVmax=210;
mov_step=25; % Paddle Quantized Movement (1/4 Paddle)
maxLives=4;
maxHits=100; % Return Mission Complete
% Initial Start
paddle=500; % position y % min max paddle [50 950]
ball=[500 500 30 20]; % x y vx vy Treated as a Point
lives=0; % Lives
hits=0;
entry=0;
while lives<maxLives && hits<maxHits
[curdir]=PONG_002_solver(paddle,ball); % FUNCTION CALL
if abs(curdir)>1,curdir=0;end % Max 1 / -1 of scalar allowed
curmov=mov_step*curdir;
if entry==0 % Initialize movement history vector
curdirvec=curdir;
entry=1;
else
curdirvec=[curdirvec curdir]; % Saving moves for file create
end
% Paddle Move
paddle=max(pwidth,min(1000-pwidth,paddle+curmov)); % [50 : 950] limits
% Ball Move
for j=1:vup
% ball=[500 500 1 1]; % x y vx vy Treated as a Point
if ball(1)+ball(3)/vup<=0 % Check if Point is Over
% Find x=0 crossing and check if paddle is within
% [paddle-pwidth-bwidth,paddle+pwidth+bwidth] pwidth=50;
% set speed scalar
xc=ball(2)-ball(1)*ball(4)/ball(3);
if xc>=1000
xc=1000-(xc-1000);
else
xc=abs(xc);
end
paddlemax= paddle+pwidth+bwidth;
paddlemin= paddle-pwidth-bwidth;
if xc>paddlemax || xc<paddlemin % Swing and a Miss
lives=lives+1;
fprintf('Oops %i\n',lives);
if lives>=maxLives,break;end
%paddle=500; % position y % min max paddle [50 950]
% Reset Ball Keep deterministic but different
ball=[500-100*lives 500 30+11*lives 20-3*lives];
break;
end
% Ball returned
hits=hits+1;
ball(1:2)=ball(1:2)+ball(3:4)/vup;
ball(1)=-ball(1);
ball(3)=-spfx*ball(3);
if ball(2)<0
ball(2)=-ball(2);
ball(4)=-spfy*ball(4);
elseif ball(2)>1000
ball(2)=2000-ball(2);
ball(4)=-spfy*ball(4);
else
ball(4)=spfy*ball(4);
end
ball(3)=max(negVmax,min(posVmax,ball(3)));
ball(4)=max(negVmax,min(posVmax,ball(4)));
else % Wall bounces
ball(1:2)=ball(1:2)+ball(3:4)/vup;
if ball(1)>=2000 % To the right
ball(1)=2000-(ball(1)-2000);
ball(3)=-ball(3);
if ball(2)>=1000 % TR
ball(2)=1000-(ball(2)-1000);
ball(4)=-ball(4);
elseif ball(2)<=0 % BR
ball(2)=-ball(2); % abs
ball(4)=-ball(4);
end
else % Middle
if ball(2)>=1000 % TM
ball(2)=1000-(ball(2)-1000);
ball(4)=-ball(4);
elseif ball(2)<=0 % BM
ball(2)=-ball(2); % abs
ball(4)=-ball(4);
end
end
end % Ball Pass / New Position
end % j vup
end % while Alive and Hits < Total Success
%fprintf('%i ',curdirvec);fprintf('\n'); % Moves
fprintf('Hits %i\n',hits)
fprintf('Lives %i\n',lives)
score= max(0,maxHits-5*hits+100*lives); %
fprintf('Score %i\n',score)
% Passing Score is 15 hits to Score 425 or Less
assert(score<=425,sprintf('Score %i\n',score))
feval( @assignin,'caller','score',floor(min( 500,score )) );
Oops 1
Oops 2
Oops 3
Oops 4
Hits 65
Lives 4
Score 175
|
Find the peak 3n+1 sequence value
1108 Solvers
185 Solvers
180 Solvers
206 Solvers
Piecewise linear interpolation
299 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!