我在StackExchange上看到了ASCII空間入侵者的這個代碼,並且想要試着理解它背後的概念。如果任何人有幾分鐘時間向幾個星期前剛開始的人指出關鍵概念,那將非常感謝!Python - 可以向我解釋一下這個代碼嗎?
exec'''import threading as t
import msvcrt,Queue,time,random,os
u=raw_input('name:')
r=range
@Z:
$~(S):S.w=78;S.h=30;S.X();S.l='';S.Q=[];S.q=[];S.m=''
$J(S,x,y,c):S.q.append([x,y,c])
$X(S):S.s=[[' '^y in r(78)]^x in r(30)]
$V(S):
?s='';S.X()
?^x,y,z in S.q:S.s[y][x]=z
?S.q=[]
?^x in S.s:
? ^y in x:s+=y
? s+='\\n'
?s+=S.m.center(S.w)
?if s!=S.l:os.system('cls');S.l=s;print s
@E(Exception):pass
@C:
$~(S,g,c,p):S.g=g;S.c=c;S.p=p;S.s=[]
$M(S,a,d):
?if (a<0 and S.p[d]==0) or (a>0 and S.p[d]==(S.g.z.h if d else S.g.z.w)-1):raise
E()
?S.p[d]+=a
$X(S):S.s.remove(S)
@A(C):
$~(S,g):C.~(S,g,'A',[39,28])
$M(S,a,d=0):
?try:C.M(S,a,d)
?except E:pass
@Y(A):
$~(S,g,p):C.~(S,g,'Y',p);S.s=g.a
@B(C):
$~(S,g,p,n):C.~(S,g,'|'if n<0 else'*',[p[0],p[1]+n]);S.s=g.b;S.d=n;S.a=0 if n<0
else 1
$M(S):
?try:C.M(S,S.d,1)
?except E:S.X()
$b(S):S.g.z.J(S.p[0],S.p[1],'X');S.g.z.V();S.X()
$co(S):
?^w in S.g.w:
? if S.p==w.p:S.b();w.X()
?if S.a:
? if S.p==S.g.p.p:S.b();S.g.d()
?else:
? ^a in S.g.a:
??if S.p==a.p:S.b();S.g.P(50);a.X()
@W(C):
$~(S,g,p):C.~(S,g,'#',p);S.s=g.w
@I(t.Thread):
$~(S,g):t.Thread.~(S);S.f=1;S.c={'a':g._g4,'d':g._g3,'x':g._X,' ':g._fi};S.start()
$run(S):
?while S.f:
? c=msvcrt.getch()
? if c in S.c:S.c[c]()
$X(S):S.f=0
@G:
$~(S):S.z=Z();S.x=3.0;S.c=0;S.b=[];S.Q=Queue.Queue();S.I=I(S);S.g2=0;S.g1=0;S.do=0;S.f=1;S.v=0;S.l=3;S.ti=[];S.G(1);S.O()
$O(S):
?while S.f:
? time.sleep(0.02)
? if not S.a:S.G(1)
? S.ch();S.B();S.u()
$u(S):
?S.z.X();S.P(0)
?s=u+' '+`S.l`
?^i in r(len(s)):S.z.J(i,0,s[i])
?^i in S.a+S.b+[S.p]+S.w:S.z.J(i.p[0],i.p[1],i.c)
?S.z.V()
$ch(S):
?try:
? while not S.Q.empty():S.Q.get_nowait()();S.Q.task_done()
?except Queue.Empty:pass
$cl(S):
?try:
? while not S.Q.empty():S.Q.get_nowait();S.Q.task_done()
?except Queue.Empty:pass
$_g4(S):
?if not S.g2:S.g2=1;S.Q.put(S.g4)
$g4(S):S.p.M(-1);S.g2=0
$_g3(S):
?if not S.g1:S.g1=1;S.Q.put(S.g3)
$g3(S):S.p.M(1);S.g1=0
$_X(S):S.I.X();S.Q.put(S.X)
$X(S):S.f=0;S.I.X();S.st()
$_fi(S):
?if not S.do:S.do=1;S.Q.put(S.fi)
$fi(S):S.b.append(B(S,S.p.p[:],-1));S.do=0;S.P(-1)
$_af(S):S.Q.put(S.af)
$af(S):c=random.choice(S.a);S.b.append(B(S,c.p[:],1));S.nt(random.uniform(0.1,2),S._af)
$nt(S,n,f):x=t.Timer(n,f);S.ti.append(x);x.start()
$st(S):
?^i in S.ti:i.cancel()
$G(S,n=0):
?S.st();S.cl();S.p=A(S);S.a=[];S.w=[];S.b=[]
?^x in[[i,o]^i in r(30)^o in r(3,10)]:
? if random.randint(0,99)%4==0:S.a.append(Y(S,x))
?S._m();S._af();f=[]
?^x in [6,27,46,65]:f+=[[z,y]^z in r(x,x+6)^y in r(23,26)]
?^i in f:S.w.append(W(S,i))
?S.v+=n;S.z.m='Level %s'%S.v;S.u()
?if S.x>0.2:S.x=1.6 - S.v*0.1
?S.m1=0;S.m2=0;S.k=1;time.sleep(3)
$_m(S):S.Q.put(S.m)
$m(S):
?x=0
?if S.m2:S.m2=0;S.m1=0;S.k=-S.k;x=1
?^i in S.a:i.M(*(abs(S.k),1)if x else(S.k,0))
?if S.m1==47:S.m2=1
?else:S.m1+=1
?S.nt(S.x,S._m)
$B(S):
?^i in S.b:i.M();i.co()
$d(S):
?S.l-=1
?if S.l==0:S.z.m='Game Over!';S.X();return
?S.G(0)
$P(S,n):
?S.c+=n if S.c+n>0 else 0;x=`S.c`
?^n in r(len(x)):S.z.J(n,1,x[n])
G()'''.replace('@','class ').replace('?',' ').replace('$',' def ').replace('^','for ').replace('~','__init__')
我不是說我要被編碼這樣的事,只是想究竟發生了什麼事的想法! :)
感謝
啊好的,它在代碼高爾夫頁面,所以這將解釋混淆:)感謝您的幫助。我會聽從你的建議,並將其放入「冰箱」,直到我準備好。 – Cairn