Maze generation: Difference between revisions
m
→{{header|EasyLang}}
(→{{header|Haskell}}: Specified imports, applied hlint hindent, simplified a Boolean chain with 'bool') |
|||
Line 2,032:
=={{header|EasyLang}}==
[https://easylang.online/ide/?code=size=20%0A%23 %0Asz=2*size+1%0A%23 we only have one-dimensional arrays%0Alen f[] sz*sz%0A%23 %0Afunc make_maze..%0A%23 the maze is created by random walking around%0A for i range len f[] f[i]=1 . x=1+2*random size y=1+2*random size f[x+y*sz]=0 visited=1 while visited < size*size oldx=x oldy=y dir=random 4 if dir=0 and x+2 < sz x+=2 elif dir=1 and y+2 < sz y+=2 elif dir=2 and x > 2 x-=2 elif dir=3 and y > 2 y-=2 . if f[y*sz+x]=1 f[y*sz+x]=0 f[(y+oldy)/2*sz+(x+oldx)/2]=0 visited+=1 . . f[(sz-1)*sz+sz-2]=0 . func show_maze.. c2%23=(100-24/size)/size/2 c10%23=c2%23/5 linewidth 2*c10%23 color 997 move 0 0 rect 100 100 color 543 for r range sz for c range sz if f[r*sz+c]=1 if r mod 2=0 if c mod 2=1 move c10%23+(c-1)*c2%23 c10%23+r*c2%23 line c10%23+(c+1)*c2%23 c10%23+r*c2%23 . else move c10%23+c*c2%23 c10%23+(r-1)*c2%23 line c10%23+c*c2%23 c10%23+(r+1)*c2%23 . . . . . call make_maze call show_maze Run it]
<lang easyprog.online>size = 20
|