Maze generation: Difference between revisions

→‎{{header|Julia}}: better code for the printer.
(→‎{{header|Julia}}: better code for the printer.)
Line 2,611:
check(bound) = cell -> all([1,1] .<= cell .<= [bound...])
 
maze(w, h) = walk([i%2|j%2 for i=1:2w+1,j=1:2h+1], 2+2ifloor(*[rand(1:w),h].*rand(2)1:h)])
 
mprintpprint(maze) = print(replacemapslices((@sprintfx-> "%s" maze[join(x)],'\t' maze, ""[2]))
 
function pprintmprint(maze, wall = CharString("╹╸┛╺┗━┻╻┃┓┫┏┣┳╋"...))
mprintpprint([ maze[i,j] == 0 ? ' ' :
wall[sum(c-> 2.0^.5(3c[1]+c[2]+3),
filter(x -> maze[x...] != 0,
Line 2,624:
{{out}}
<pre>
julia> pprintmprint(maze(15,30))
┏━━━━━━━━━━━━━━━┳━━━━━━━┳━━━┳━━━┳━━━━━━━┳━━━┳━━━━━━━━━┳━━━━━┓
┃ ╺━━━┳━━━┓ ╺━━━┛ ╻ ┏━╸ ┃ ╻ ┃ ╻ ┃ ╻ ╺━┳━┛ ╻ ╹ ╺━┓ ╺━┓ ┗━━━╸ ┃