Maze generation: Difference between revisions
→Quality Breadth-First: Drop @(do ...). Remove while macro; while has been built in for a long time.
m (→{{header|REXX}}: added/changed whitespace and comments, simplified some statements.) |
(→Quality Breadth-First: Drop @(do ...). Remove while macro; while has been built in for a long time.) |
||
Line 5,610:
===Quality Breadth-First===
The following is a complete, self-contained command line utility. We also drop use of the TXR pattern extraction language and work purely in TXR Lisp.
The algorithm is quite different from the previous. This version is not recursive. This algorithm divides the maze cells into visited cells, frontier cells and unvisited cells. As in the DFS version, border cells outside of the maze area are pre-initialized as visited, for convenience. The frontier set initially contains the upper left hand corner.
Line 5,622:
At the user interface level, the straightness parameter is represented as a percentage. This percentage is converted to a number of cells based on the width and height of the maze. For instance if the straightness parameter is 15, and the maze size is 20x20, it means that 15% out of 400 cells, or 60 cells will be traversed before the queue is scrambled. Then another 60 will be traversed and the queue will be scrambled, and so forth.
<lang txr>
(list (- x 1)..y (+ x 1)..y
(while q
(let* ((cu (first q))
(ne (rnd-pick (remove-if (orf vi fr) (neigh cu)))))
(sc (max 1 (
▲ (push cu [pa ne])
▲ (push ne q)
▲ (cond ((<= (dec c) 0)
▲ (set q (scramble q))
▲ (set c sc))))
▲ (t (set [vi cu] t)
▲ (del [fr cu])
▲ (pop q)))))))
(if (memqual i..(- j 1)
▲ (set [vi x..-1] t)
▲ (set [vi x..h] t))
▲ (each ((y (range* 0 h)))
(set [vi -1..y] t)▼
(set [vi w..y] t))▼
▲ (make-maze-impl 0..0)
▲ pa))
(if
(
▲ (set str `@str| `)))
▲ (put-line `@str|\n@str|`)))
▲ (print-tops pa w h))
(exit 1)))
▲ (defun usage ()
(*random-state* (make-random-state nil)))
▲ (put-line `@invocation <width> <height> [<straightness>]`)
▲ (put-line "straightness-factor is a percentage, defaulting to 15")
((w h s
▲ (let ((args [mapcar int-str *args*])
(
▲ (usage))
▲ (tree-case args
▲ (set h (max 1 h))
{{out}}
|