Cody

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

Solution 1499135

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.00 PY:500.00 VX:40.00 VY:60.00 t1:37.50 t2:45.45 y1:750.00 y2:386.36 paddle: 500.00 newpos:700.00 pdir:1.00 PX:540.00 PY:560.00 VX:40.00 VY:60.00 t1:36.50 t2:45.45 y1:750.00 y2:386.36 paddle: 550.00 newpos:700.00 pdir:1.00 PX:580.00 PY:620.00 VX:40.00 VY:60.00 t1:35.50 t2:45.45 y1:750.00 y2:386.36 paddle: 600.00 newpos:700.00 pdir:1.00 PX:620.00 PY:680.00 VX:40.00 VY:60.00 t1:34.50 t2:45.45 y1:750.00 y2:386.36 paddle: 650.00 newpos:700.00 pdir:1.00 PX:660.00 PY:740.00 VX:40.00 VY:60.00 t1:33.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:700.00 PY:800.00 VX:40.00 VY:60.00 t1:32.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:740.00 PY:860.00 VX:40.00 VY:60.00 t1:31.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:780.00 PY:920.00 VX:40.00 VY:60.00 t1:30.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:820.00 PY:980.00 VX:40.00 VY:60.00 t1:29.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:860.00 PY:960.00 VX:40.00 VY:-60.00 t1:28.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:900.00 PY:900.00 VX:40.00 VY:-60.00 t1:27.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:940.00 PY:840.00 VX:40.00 VY:-60.00 t1:26.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:980.00 PY:780.00 VX:40.00 VY:-60.00 t1:25.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:980.00 PY:720.00 VX:-40.00 VY:-60.00 t1:24.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:940.00 PY:660.00 VX:-40.00 VY:-60.00 t1:23.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:900.00 PY:600.00 VX:-40.00 VY:-60.00 t1:22.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:860.00 PY:540.00 VX:-40.00 VY:-60.00 t1:21.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:820.00 PY:480.00 VX:-40.00 VY:-60.00 t1:20.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:780.00 PY:420.00 VX:-40.00 VY:-60.00 t1:19.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:740.00 PY:360.00 VX:-40.00 VY:-60.00 t1:18.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:700.00 PY:300.00 VX:-40.00 VY:-60.00 t1:17.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:660.00 PY:240.00 VX:-40.00 VY:-60.00 t1:16.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:620.00 PY:180.00 VX:-40.00 VY:-60.00 t1:15.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:580.00 PY:120.00 VX:-40.00 VY:-60.00 t1:14.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:540.00 PY:60.00 VX:-40.00 VY:-60.00 t1:13.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:500.00 PY:-0.00 VX:-40.00 VY:60.00 t1:12.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:460.00 PY:60.00 VX:-40.00 VY:60.00 t1:11.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:420.00 PY:120.00 VX:-40.00 VY:60.00 t1:10.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:380.00 PY:180.00 VX:-40.00 VY:60.00 t1:9.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:340.00 PY:240.00 VX:-40.00 VY:60.00 t1:8.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:300.00 PY:300.00 VX:-40.00 VY:60.00 t1:7.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:260.00 PY:360.00 VX:-40.00 VY:60.00 t1:6.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:220.00 PY:420.00 VX:-40.00 VY:60.00 t1:5.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:180.00 PY:480.00 VX:-40.00 VY:60.00 t1:4.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:140.00 PY:540.00 VX:-40.00 VY:60.00 t1:3.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:100.00 PY:600.00 VX:-40.00 VY:60.00 t1:2.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:60.00 PY:660.00 VX:-40.00 VY:60.00 t1:1.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:20.00 PY:720.00 VX:-40.00 VY:60.00 t1:0.50 t2:45.45 y1:750.00 y2:386.36 paddle: 700.00 newpos:700.00 pdir:0.00 PX:22.00 PY:781.50 VX:44.00 VY:63.00 t1:44.95 t2:41.32 y1:386.36 y2:347.11 paddle: 700.00 newpos:336.36 pdir:-1.00 PX:66.00 PY:844.50 VX:44.00 VY:63.00 t1:43.95 t2:41.32 y1:386.36 y2:347.11 paddle: 650.00 newpos:336.36 pdir:-1.00 PX:110.00 PY:907.50 VX:44.00 VY:63.00 t1:42.95 t2:41.32 y1:386.36 y2:347.11 paddle: 600.00 newpos:336.36 pdir:-1.00 PX:154.00 PY:970.50 VX:44.00 VY:63.00 t1:41.95 t2:41.32 y1:386.36 y2:347.11 paddle: 550.00 newpos:336.36 pdir:-1.00 PX:198.00 PY:966.50 VX:44.00 VY:-63.00 t1:40.95 t2:41.32 y1:386.36 y2:347.11 paddle: 500.00 newpos:336.36 pdir:-1.00 PX:242.00 PY:903.50 VX:44.00 VY:-63.00 t1:39.95 t2:41.32 y1:386.36 y2:347.11 paddle: 450.00 newpos:336.36 pdir:-1.00 PX:286.00 PY:840.50 VX:44.00 VY:-63.00 t1:38.95 t2:41.32 y1:386.36 y2:347.11 paddle: 400.00 newpos:336.36 pdir:-1.00 PX:330.00 PY:777.50 VX:44.00 VY:-63.00 t1:37.95 t2:41.32 y1:386.36 y2:347.11 paddle: 350.00 newpos:336.36 pdir:-0.27 PX:374.00 PY:714.50 VX:44.00 VY:-63.00 t1:36.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:418.00 PY:651.50 VX:44.00 VY:-63.00 t1:35.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:462.00 PY:588.50 VX:44.00 VY:-63.00 t1:34.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:506.00 PY:525.50 VX:44.00 VY:-63.00 t1:33.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:550.00 PY:462.50 VX:44.00 VY:-63.00 t1:32.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:594.00 PY:399.50 VX:44.00 VY:-63.00 t1:31.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:638.00 PY:336.50 VX:44.00 VY:-63.00 t1:30.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:682.00 PY:273.50 VX:44.00 VY:-63.00 t1:29.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:726.00 PY:210.50 VX:44.00 VY:-63.00 t1:28.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:770.00 PY:147.50 VX:44.00 VY:-63.00 t1:27.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:814.00 PY:84.50 VX:44.00 VY:-63.00 t1:26.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:858.00 PY:21.50 VX:44.00 VY:-63.00 t1:25.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:902.00 PY:41.50 VX:44.00 VY:63.00 t1:24.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:946.00 PY:104.50 VX:44.00 VY:63.00 t1:23.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:990.00 PY:167.50 VX:44.00 VY:63.00 t1:22.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:966.00 PY:230.50 VX:-44.00 VY:63.00 t1:21.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:922.00 PY:293.50 VX:-44.00 VY:63.00 t1:20.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:878.00 PY:356.50 VX:-44.00 VY:63.00 t1:19.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:834.00 PY:419.50 VX:-44.00 VY:63.00 t1:18.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:790.00 PY:482.50 VX:-44.00 VY:63.00 t1:17.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:746.00 PY:545.50 VX:-44.00 VY:63.00 t1:16.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:702.00 PY:608.50 VX:-44.00 VY:63.00 t1:15.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:658.00 PY:671.50 VX:-44.00 VY:63.00 t1:14.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:614.00 PY:734.50 VX:-44.00 VY:63.00 t1:13.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:570.00 PY:797.50 VX:-44.00 VY:63.00 t1:12.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:526.00 PY:860.50 VX:-44.00 VY:63.00 t1:11.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:482.00 PY:923.50 VX:-44.00 VY:63.00 t1:10.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:438.00 PY:986.50 VX:-44.00 VY:63.00 t1:9.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:394.00 PY:950.50 VX:-44.00 VY:-63.00 t1:8.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:350.00 PY:887.50 VX:-44.00 VY:-63.00 t1:7.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:306.00 PY:824.50 VX:-44.00 VY:-63.00 t1:6.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:262.00 PY:761.50 VX:-44.00 VY:-63.00 t1:5.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:218.00 PY:698.50 VX:-44.00 VY:-63.00 t1:4.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:174.00 PY:635.50 VX:-44.00 VY:-63.00 t1:3.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:130.00 PY:572.50 VX:-44.00 VY:-63.00 t1:2.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:86.00 PY:509.50 VX:-44.00 VY:-63.00 t1:1.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:0.00 PX:42.00 PY:446.50 VX:-44.00 VY:-63.00 t1:0.95 t2:41.32 y1:386.36 y2:347.11 paddle: 336.36 newpos:336.36 pdir:-0.00 PX:2.00 PY:383.50 VX:48.40 VY:-66.15 t1:41.28 t2:37.57 y1:347.24 y2:956.46 paddle: 336.36 newpos:397.24 pdir:1.00 PX:50.40 PY:317.35 VX:48.40 VY:-66.15 t1:40.28 t2:37.57 y1:347.24 y2:956.46 paddle: 386.36 newpos:397.24 pdir:0.22 PX:98.80 PY:251.20 VX:48.40 VY:-66.15 t1:39.28 t2:37.57 y1:347.24 y2:956.46 paddle: 397.24 newpos:397.24 pdir:0.00 PX:147.20 PY:185.05 VX:48.40 VY:-6...