Anonymous user
Maze generation: Difference between revisions
→{{header|Common Lisp}}
Line 732:
=={{header|Common Lisp}}==
Uses unicode line drawing chars. Assumes they are single width on console. Code pretty horribly unreadable.
<lang lisp>
(defun
(setf *random-state* (make-random-state t))▼
▲ :initial-element 0)))
(setf (aref arr i j) 15)))▼
(let ((vis (
(labels
(loop for j to w do▼
(
with cnt = 0 do
(
(zerop (random (incf cnt))))
(setf xx x1 yy y1))))▼
(if (= x xx)▼
(wipe yy (1+ x) 4)▼
▲ (setf (aref arr yy x) 0)))
(setf (aref arr y xx) 0)))▼
(show ()
(let ((g " │││─┘┐┤─└┌├─┴┬┼"))▼
(loop for i from 0 to h do
▲ (loop for j from 0 to w do
(format t "~c~a"
(char g
(+ (or-and 1 (= i 0) (> j 0) (aref ver (1- i) (1- j)))
(or-and 2 (= i h) (> j 0) (aref ver i (1- j)))
(or-and 4 (= j 0) (> i 0) (aref hor (1- i) (1- j)))
(or-and 8 (= j w) (> i 0) (aref hor (1- i) j ))))
"───" " ")))
(terpri)
(loop for j from 0 below w do
"│ " " ")))
(format t "│~%"))))))
▲(defun show-maze (m)
(show))))
▲ (let ((g " │││─┘┐┤─└┌├─┴┬┼"))
▲ (format t "~c" (char g (!and= (aref m i j) 16)))))
│ │ │ │
┼──── │ │ │ │ ┌───┐ ├
|