-
831f2c1a :Anonymous
2006-11-03 15:58
-
もっと短いPythonのテトリス — TRIVIAL TECHNOLOGIES 2.0
http://coreblog.org/ats/more-small-tetris
せっかくなのでコードものっけてみる。ライセンス不明。
import random,pygame;R=range;L=len;W=10;Q=H=20;P=pygame;G=255;v=lambda b:['0'*W
]*(H-L(b))+b;a=p=x=y=c=d=0;D=P.display;T=P.USEREVENT;m=lambda i,j:j-y in R(L(p)
)and i-x in R(L(p[0]))and'0'!=p[j-y][i-x]and`d+1`or b[j][i];S=D.set_mode((W*Q,H
*Q));k=lambda p,x,y:1-max(p[i][j]!='0'and(y+i>=H or x+j<0or x+j>=W or'0'!=b[i+y
][j+x])for j in R(L(p[0]))for i in R(L(p)));n=E=b=v([]);P.time.set_timer(T,100)
exec("while E!=P.QUIT:\n E=P.event.wait().type;K=P.key.get_pressed()\n if n:d="
"random.randrange(7);q='111';p=[['1'*4],['010',q],['110','011'],['011','110'],"
"[q,'100'],['11','11'],[q,'001']][d];x=W/2-L(p[0])/2;y=n=0\n if E==T:\n [P.dr"
"aw.rect(S,[(h,g,f)for f in(0,G)for g in(0,G)for h in(0,G)][int(m(i/H,i%H))],("
"(i/H*Q,i%H*Q),(Q,Q)))for i in R(W*H)];t=''.join;z=[t([p[L(p)-1-i][j]for i in "
"R(L(p))])for j in R(L(p[0]))];p,x,y=[p,z][K[P.K_UP]*k(z,x,y)],x-(K[P.K_LEFT]*"
"k(p,x-1,y))+(K[P.K_RIGHT]*k(p,x+1,y)),y+(K[P.K_DOWN]*k(p,x,y+1));B=[t([m(i,j)"
"for i in R(W)])for j in R(H)];e=sum(r.find('0')<0for r in B);D.flip();c+=1\n "
" if c%5<1:\n if k(p,x,y+1)<1:\n if y<1:break\n a+=e and 2**e;n=b=v([r"
" for r in B if~r.find('0')])\n else:y+=1\n");print 'GAME OVER: score %i'%a
Powered by shinGETsu.