diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | pw.rb | 25 | ||||
| -rw-r--r-- | pw0.rb | 68 | ||||
| -rw-r--r-- | test.sh | 20 |
5 files changed, 130 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62fa9d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +pw.*.rb +pw.*.*.rb diff --git a/README.md b/README.md new file mode 100644 index 0000000..c5f203b --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Pong Wars Quine + +It is quine-line program of Pong Wars. + +Start the game: + +``` +$ ruby pw.rb +``` + +Output only `N`th step: + +``` +$ ruby pw.rb N +``` @@ -0,0 +1,25 @@ +eval(s=(%w@q=$*[0]&.to_i;z="eval(s=(%w#{64.chr}#{s}##{s*9}#{64.chr}.join))";h=25 +; w=80;px=2;py=h/2;vx=0.5;vy=-0.5;qx=w-3; +q y=h/2;ux=-0.5;uy=0.5;b=Array.new(h*w){| +i |y=i/w;x=i%w;(x==0||x==w-1||y==0||y==h- +1 )?2:(w/2<x)?1:0};f=->(x,y,vx,vy,c){sx=v +x ;sy=vy;8.times{|i|t=i*Math::PI/4;cos=Ma +t h.cos(t);sin=Math.sin(t);nx=x+cos/2;ny= +y +sin/2;k=ny.to_i*w+nx.to_i;if(0<=nx&&nx +< w&&0<=ny&&ny<h&&b[k]!=c);b[k]==2?0:b[k] += c;(sin.abs<cos.abs)?sx*=-1:sy*=-1;end}; +[ sx,sy]};g=->(x,y,vx,vy){[(x+vx<0||w<=x+ +v x )?-vx:vx,(y+vy<0||h<=y+vy)?-vy:vy]};j=0 +; loop{j+=1;(vx,vy=f[px,py,vx,vy,0]); (vx +, vy=g[px,py,vx,vy]);px+=vx;py+=vy;(ux,uy += f[qx,qy,ux,uy,1]);(ux,uy=g[qx,qy,ux,uy] +) ;qx+=ux;qy+=uy;q&&((q<j)?(break):(q!=j) +? (next):0);q||(print"\e[H\e[2J");c=[];h. +t imes{|y|w.times{|x|c<<!(b[y*w+x]==0&&[p +x .to_i,py.to_i]!=[x,y]||[qx.to_i,qy.to_i +] ==[x,y])};};t=c.count(!!0);i=0;h.times{ +| y|w.times{|x|print((y==h-1&&x>=w-8)?"#{ +6 4.chr}.join))"[8+x-w]:c[y*w+x]?[z[i],i+ += 1][0]:32.chr)};puts;};sleep(0.05);}#q=$ +* [0]&.to_i;z="eval(s=(%w#{64.chr}#{s}##{ +s*9}#{64.chr}.join))";h=25;w=80;px=2;py=h/2;vx=0.5;vy=-0.5;qx=w-3;qy=h/2@.join)) @@ -0,0 +1,68 @@ +eval(s=(%w@ + q=$*[0]&.to_i; + + z="eval(s=(%w#{64.chr}#{s}##{s*9}#{64.chr}.join))"; + + h=25;w=80; + px=2;py=h/2; + vx=0.5;vy=-0.5; + qx=w-3;qy=h/2; + ux=-0.5;uy=0.5; + + b=Array.new(h*w){|i| + y=i/w; + x=i%w; + (x==0||x==w-1||y==0||y==h-1)?2:(w/2<x)?1:0 + }; + + f=->(x,y,vx,vy,c){ + sx=vx;sy=vy; + 8.times{|i| + t=i*Math::PI/4; + cos=Math.cos(t); + sin=Math.sin(t); + nx=x+cos/2; + ny=y+sin/2; + k=ny.to_i*w+nx.to_i; + if(0<=nx&&nx<w&&0<=ny&&ny<h&&b[k]!=c); + b[k]==2?0:b[k]=c; + (sin.abs<cos.abs)?sx*=-1:sy*=-1; + end + }; + [sx,sy] + }; + g=->(x,y,vx,vy){ + [(x+vx<0||w<=x+vx)?-vx:vx,(y+vy<0||h<=y+vy)?-vy:vy] + }; + + j=0; + loop{ + j+=1; + (vx,vy=f[px,py,vx,vy,0]); + (vx,vy=g[px,py,vx,vy]); + px+=vx; + py+=vy; + (ux,uy=f[qx,qy,ux,uy,1]); + (ux,uy=g[qx,qy,ux,uy]); + qx+=ux; + qy+=uy; + q&&((q<j)?(break):(q!=j)?(next):0); + q||(print"\e[H\e[2J"); + c=[]; + h.times{|y| + w.times{|x| + c<<!(b[y*w+x]==0&&[px.to_i,py.to_i]!=[x,y]||[qx.to_i,qy.to_i]==[x,y]) + }; + }; + t=c.count(!!0); + i=0; + h.times{|y| + w.times{|x| + print((y==h-1&&x>=w-8)?"#{64.chr}.join))"[8+x-w]:c[y*w+x]?[z[i],i+=1][0]:32.chr) + }; + puts; + }; + sleep(0.05); + } + +@.join)) @@ -0,0 +1,20 @@ +set -eu + +rm -f pw.*.rb pw.*.*.rb + +for i in {1..5}; do + ruby pw.rb $i > pw.$i.rb +done + +for i in {1..5}; do + for j in {1..5}; do + ruby pw.$i.rb $j > pw.$i.$j.rb + done +done + +for i in {1..5}; do + for j in {1..5}; do + diff pw.$i.rb pw.$j.$i.rb + done +done +echo "okay" |
