# generate a maze via depth-first random walk
# and render it as ASCII art

on maze w h do
	used:up:lf:()
	on walk here do
		each delta in random[(list -1,0),(list 1,0),(list 0,-1),(list 0,1) -4]
			there:(w,h)&(0,0)|here+delta
			if !used[there]
				if delta[0]<0 lf[here ]:1 end
				if delta[0]>0 lf[there]:1 end
				if delta[1]<0 up[here ]:1 end
				if delta[1]>0 up[there]:1 end
				used[there]:1
				walk[there]
			end
		end
	end
	walk[0,0]

	# display the maze
	each y in range h
		print[each x in range w ("+--","+  ")[up[x,y]] end,"+"]
		print[each x in range w ("|  ","   ")[lf[x,y]] end,"|"]
	end
	print[(1+w*3) take "+--"]
end

maze[20 8]
