Génère un labyrinthe en 3D de manière aléatoire. Lorsqu’on trouve la sortie (mur vert), on accède à un nouveau labyrinthe aléatoire, et ce à l’infini. Version de nuit avec ciel étoilé et simulation d’ombre. Commandes : flèches de gauche/droite pour tourner à gauche/droite de 45 degrés, flèche du haut/bas pour avancer/reculer, parenthèses pour les pas de côté. Version basse résolution pour accélérer le tracer et minifiée pour peser moins.
l='#S$@E' k='$' j=zip i=dict b='#' R=round L=range K='E' J='.' D=int w=100 q=180 from kandinsky import set_pixel as c,fill_rect as M,color as N from ion import keydown as G from math import tan,cos,sin,atan,pi,ceil as S from random import choice as d,randint as T def O(wall): Q=None;A=[[wall]*B for A in L(B)];A[1][1]=A[1][2]=A[1][3]=J;O=[(0,1,2,3),(0,1,3,2),(0,2,1,3),(0,2,3,1),(0,3,1,2),(0,3,2,1),(1,0,2,3),(1,0,3,2),(1,2,0,3),(1,2,3,0),(1,3,0,2),(1,3,2,0),(2,0,1,3),(2,0,3,1),(2,1,0,3),(2,1,3,0),(2,3,0,1),(2,3,1,0),(3,0,1,2),(3,0,2,1),(3,1,0,2),(3,1,2,0),(3,2,0,1),(3,2,1,0)];I=[(1,3,0)];E,H,N=Q,Q,0 while I: F,G,M=I.pop() for P in d(O): C,D=[(F+2,G),(F-2,G),(F,G+2),(F,G-2)][P] if 0<=C<B and 0<=D<B and A[C][D]!=J: A[C][D]=A[(C+F)//2][(D+G)//2]=J if M>N and(C in(1,B-2)or D in(1,B-2)):N,E,H=M,C,D I.append((C,D,M+1)) A[1][0]='S' if E==1:A[0][H]=K elif E==B-2:A[B-1][H]=K elif H==1:A[E][0]=K else:A[E][B-1]=K return A def e(X,Y,angle): Q=1;A=angle A=(A+q)%360-q K=float('inf') if A!=0 and A!=q: L=1/a(A);E=A<0;H=w*D(Y/w)if E else S(Y/w)*w;I=X+(H-Y)*L while Q: F,G=H//w-1*E,D(I/w) if not 0<=F<B or not 0<=G<B or C[F][G]!=J:break H+=w*(-1)**E;I+=w*L*(-1)**E K,M=Z(X,Y,I,H),Q if B>F>=0 and 0<=G<B:N=C[F][G] if A!=90 and A!=-90: O=a(A);E=A>90 or A<-90;I=D(X/w)*w if E else S(X/w)*w;H=Y+(I-X)*O while Q: F,G=D(H/w),I//w-1*E if not 0<=F<B or not 0<=G<B or C[F][G]!=J:break I+=w*(-1)**E;H+=w*O*(-1)**E P=Z(X,Y,I,H) if P<K: K,M=P,0 if B>F>=0 and 0<=G<B:N=C[F][G] return K,M,N def U(r,g,b,d):A=(1.6-atan(d/25-6))/3.2;r,g,b=R(r*A),R(g*A),R(b*A);return N(r,g,b) def H(): C=[] for D in L(108):I=(D+1)//2*(-1)**D+D%2*108-54;B=A+I*5/9;J,S,T=e(E,F,B if B%45 else B+.05);J=R(J*P(A-B));K=R(14000/J);V,W,X=[g,h][S][T];C.append((160+3*I,111-K,3,2*K,U(V,W,X,J))) M(0,0,320,222,N(16,16,69)) for(G,H)in Q[A]:c(G,H,N(255,255,255)) for O in L(1,112,3):M(0,111+O,320,3,U(139,69,19,14000/O)) for(G,H,Y,Z,a)in C:M(G,H,Y,Z,a) del C def V(s): global E,F,A,C,I if A%90:return B,G=E-s*w*Y(A),F+s*w*P(A) if C[D(G/w)][D(B/w)]==J:E,F=B,G;H() elif C[D(G/w)][D(B/w)]==K:I+=1;C,E,F,A=O(b if I%5 else k),150,150,0;H() def W(s): global A;A+=s*45 if A<=-q or A>q:A-=s*360 H() def X(s,c): global E,F,A,C,I if A%90:return B,G=E+s*w*P(A),F+s*w*Y(A) if C[D(G/w)][D(B/w)]==J:E,F=B,G;H() elif C[D(G/w)][D(B/w)]==K:I+=1;C,E,F,A=O(c if I%5 else k),150,150,0;H() Z=lambda X,Y,x,y:((X-x)**2+(Y-y)**2)**0.5 a,P,Y=lambda a:tan(a/q*pi),lambda a:cos(a/q*pi),lambda a:sin(a/q*pi) Q={A:[]for A in L(-135,181,45)} for f in list(Q): for m in L(200):Q[f].append((T(0,319),T(0,111))) B=15 C,E,F,A,I=O(b),150,150,0,1 g=i(j(l,[(229,)*3,(255,0,0),(255,215,0),(72,118,255),(0,238,0)])) h=i(j(l,[(179,)*3,(205,0,0),(205,173,0),(58,95,205),(0,205,0)])) H() while not G(5): if G(33):V(-1) if G(34):V(1) if G(0):W(-1) if G(3):W(1) if G(1):X(1,b) if G(2):X(-1,'@')