Cody

# Problem 1257. PONG 001: Player vs Wall, 4 Lives, Interactive download

Solution 1499133

Submitted on 21 Apr 2018 by Michael
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

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.10; % Speed increase factor spfy=1.05; % to Avoid fixed Paddle solution negVmax=-200; posVmax=210; mov_step=50; % Paddle Quantized Movement (1/2 Paddle) maxLives=4; maxHits=100; % Initial Start paddle=500; % position y % min max paddle [50 950] ball=[500 500 40 60]; % x y vx vy Treated as a Point lives=0; % Lives hits=0; entry=0; while lives<maxLives && hits<maxHits [curdir]=PONG_001_solver(paddle,ball); % FUNCTION CALL if abs(curdir)>1,curdir=0;end % Max 1 / -1 allowed curmov=mov_step*curdir; if entry==0 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 : Hopefully I got the Mirror solutions right 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 % draw ball %paddle=500; % position y % min max paddle [50 950] % Reset Ball Keep deterministic but different ball=[500-100*lives 500 40+11*lives 35-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)>=1000 % To the right ball(1)=1000-(ball(1)-1000); 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 10 hits to Score 450 or Less assert(score<=450,sprintf('Score %i\n',score)) feval( @assignin,'caller','score',floor(min( 500,score )) );

PX:500 PY:500 VX:40 VY:60 t1:37.50 t2:45.45 y1:750.00 y2:386.36 paddle: 500.00 newpos:700.00 pdir:1.00 PX:540 PY:560 VX:40 VY:60 t1:36.50 t2:45.45 y1:750.00 y2:386.36 paddle: 550.00 newpos:700.00 pdir:1.00 PX:580 PY:620 VX:40 VY:60 t1:35.50 t2:45.45 y1:750.00 y2:386.36 paddle: 600.00 newpos:700.00 pdir:1.00 PX:620 PY:680 VX:40 VY:60 t1:34.50 t2:45.45 y1:750.00 y2:386.36 paddle: 650.00 newpos:700.00 pdir:1.00 PX:660 PY:740 VX:40 VY:60 t1:33.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:700 PY:800 VX:40 VY:60 t1:32.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:740 PY:860 VX:40 VY:60 t1:31.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:780 PY:920 VX:40 VY:60 t1:30.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:820 PY:980 VX:40 VY:60 t1:29.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:860 PY:960 VX:40 VY:-60 t1:28.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:900 PY:900 VX:40 VY:-60 t1:27.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:940 PY:840 VX:40 VY:-60 t1:26.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:980 PY:780 VX:40 VY:-60 t1:25.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:980 PY:720 VX:-40 VY:-60 t1:24.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:940 PY:660 VX:-40 VY:-60 t1:23.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:900 PY:600 VX:-40 VY:-60 t1:22.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:860 PY:540 VX:-40 VY:-60 t1:21.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:820 PY:480 VX:-40 VY:-60 t1:20.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:780 PY:420 VX:-40 VY:-60 t1:19.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:740 PY:360 VX:-40 VY:-60 t1:18.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:700 PY:300 VX:-40 VY:-60 t1:17.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:660 PY:240 VX:-40 VY:-60 t1:16.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:620 PY:180 VX:-40 VY:-60 t1:15.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:580 PY:120 VX:-40 VY:-60 t1:14.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:540 PY:60 VX:-40 VY:-60 t1:13.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:500 PY:0 VX:-40 VY:60 t1:12.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:460 PY:60 VX:-40 VY:60 t1:11.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:420 PY:120 VX:-40 VY:60 t1:10.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:380 PY:180 VX:-40 VY:60 t1:9.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:340 PY:240 VX:-40 VY:60 t1:8.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:300 PY:300 VX:-40 VY:60 t1:7.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:260 PY:360 VX:-40 VY:60 t1:6.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:220 PY:420 VX:-40 VY:60 t1:5.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:180 PY:480 VX:-40 VY:60 t1:4.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:140 PY:540 VX:-40 VY:60 t1:3.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:100 PY:600 VX:-40 VY:60 t1:2.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:60 PY:660 VX:-40 VY:60 t1:1.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:20 PY:720 VX:-40 VY:60 t1:0.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:22 PY:7.815000e+02 VX:44 VY:63 t1:44.95 t2:41.32 y1:386.36 y2:347.11 paddle: 700.00 newpos:336.36 pdir:-1.00 PX:6.600000e+01 PY:8.445000e+02 VX:44 VY:63 t1:43.95 t2:41.32 y1:386.36 y2:347.11 paddle: 650.00 newpos:336.36 pdir:-1.00 PX:1.100000e+02 PY:9.075000e+02 VX:44 VY:63 t1:42.95 t2:41.32 y1:386.36 y2:347.11 paddle: 600.00 newpos:336.36 pdir:-1.00 PX:1.540000e+02 PY:9.705000e+02 VX:44 VY:63 t1:41.95 t2:41.32 y1:386.36 y2:347.11 paddle: 550.00 newpos:336.36 pdir:-1.00 PX:1.980000e+02 PY:9.665000e+02 VX:44 VY:-63 t1:40.95 t2:41.32 y1:386.36 y2:347.11 paddle: 500.00 newpos:336.36 pdir:-1.00 PX:2.420000e+02 PY:9.035000e+02 VX:44 VY:-63 t1:39.95 t2:41.32 y1:386.36 y2:347.11 paddle: 450.00 newpos:336.36 pdir:-1.00 PX:2.860000e+02 PY:8.405000e+02 VX:44 VY:-63 t1:38.95 t2:41.32 y1:386.36 y2:347.11 paddle: 400.00 newpos:336.36 pdir:-1.00 PX:3.300000e+02 PY:7.775000e+02 VX:44 VY:-63 t1:37.95 t2:41.32 y1:386.36 y2:347.11 paddle: 350.00 newpos:336.36 pdir:-0.27 PX:3.740000e+02 PY:7.145000e+02 VX:44 VY:-63 t1:36.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:4.180000e+02 PY:6.515000e+02 VX:44 VY:-63 t1:35.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:4.620000e+02 PY:5.885000e+02 VX:44 VY:-63 t1:34.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:5.060000e+02 PY:5.255000e+02 VX:44 VY:-63 t1:33.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:5.500000e+02 PY:4.625000e+02 VX:44 VY:-63 t1:32.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:5.940000e+02 PY:3.995000e+02 VX:44 VY:-63 t1:31.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:6.380000e+02 PY:3.365000e+02 VX:44 VY:-63 t1:30.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:6.820000e+02 PY:2.735000e+02 VX:44 VY:-63 t1:29.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:7.260000e+02 PY:2.105000e+02 VX:44 VY:-63 t1:28.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:7.700000e+02 PY:1.475000e+02 VX:44 VY:-63 t1:27.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:8.140000e+02 PY:8.450000e+01 VX:44 VY:-63 t1:26.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:8.580000e+02 PY:2.150000e+01 VX:44 VY:-63 t1:25.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:9.020000e+02 PY:4.150000e+01 VX:44 VY:63 t1:24.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:9.460000e+02 PY:1.045000e+02 VX:44 VY:63 t1:23.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:9.900000e+02 PY:1.675000e+02 VX:44 VY:63 t1:22.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:9.660000e+02 PY:2.305000e+02 VX:-44 VY:63 t1:21.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:9.220000e+02 PY:2.935000e+02 VX:-44 VY:63 t1:20.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:8.780000e+02 PY:3.565000e+02 VX:-44 VY:63 t1:19.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:8.340000e+02 PY:4.195000e+02 VX:-44 VY:63 t1:18.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:7.900000e+02 PY:4.825000e+02 VX:-44 VY:63 t1:17.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:7.460000e+02 PY:5.455000e+02 VX:-44 VY:63 t1:16.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:7.020000e+02 PY:6.085000e+02 VX:-44 VY:63 t1:15.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:6.580000e+02 PY:6.715000e+02 VX:-44 VY:63 t1:14.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:6.140000e+02 PY:7.345000e+02 VX:-44 VY:63 t1:13.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:5.700000e+02 PY:7.975000e+02 VX:-44 VY:63 t1:12.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:5.260000e+02 PY:8.605000e+02 VX:-44 VY:63 t1:11.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:4.820000e+02 PY:9.235000e+02 VX:-44 VY:63 t1:10.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:4.380000e+02 PY:9.865000e+02 VX:-44 VY:63 t1:9.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:3.940000e+02 PY:9.505000e+02 VX:-44 VY:-63 t1:8.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:3.500000e+02 PY:8.875000e+02 VX:-44 VY:-63 t1:7.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:3.060000e+02 PY:8.245000e+02 VX:-44 VY:-63 t1:6.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:2.620000e+02 PY:7.615000e+02 VX:-44 VY:-63 t1:5.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:2.180000e+02 PY:6.985000e+02 VX:-44 VY:-63 t1:4.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:1.740000e+02 PY:6.355000e+02 VX:-44 VY:-63 t1:3.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:1.300000e+02 PY:5.725000e+02 VX:-44 VY:-63 t1:2.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:8.600000e+01 PY:5.095000e+02 VX:-44 VY:-63 t1:1.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:4.200000e+01 PY:4.465000e+02 VX:-44 VY:-63 t1:0.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:2.000000e+00 PY:3.835000e+02 VX:4.840000e+01 VY:-6.615000e+01 t1:41.28 t2:37.57 y1:347.24 y2:956.46 paddle: 336.36 newpos:397.24 pdir:1.00 PX:5.040000e+01 PY:3.173500e+02 VX:4.840000e+01 VY:-6.615000e+01 t1:40.28 t2:37.57 y1:347.24 y2:956.46 paddle: 386.36 newpos:397.24 pdir:0.22 PX:9.880000e+01 PY:2.512000e+02 VX:4.840000e+01 VY:-6.615000e+01 t1:39.28 t2:37.57 y1:347.24 y2:956.46 paddle: 397.24 newpos:397.24 pdir:0.00 PX:1.472000e+02 PY:1.850500e+02 VX:4.840000e+01 VY:-6.615000e+01 t1:38.28 t2:37.57 y1:347.24 y2:956.46 paddle: 397.24 newpos:397.24 pdir:0.00 ...