Commit 4d5560c2 authored by Cory Chamblin's avatar Cory Chamblin

refactor `smooth`

parent 7b1558d0
......@@ -114,19 +114,25 @@
(loop for column upto (1- width) collect (random-tile)))))
(defun smooth (world)
(map-world-tiles world
(lambda (x y)
(if (> (wall-neighbors world x y) 4)
(gethash 'wall *tiles*)
(gethash 'floor *tiles*)))))
(defun map-world-tiles (world fn)
(destructuring-bind (world-height world-width) (array-dimensions world)
(let ((r (make-array (list world-height world-width))))
(loop for row upto (1- world-height) do
(loop for col upto (1- world-width) do
(let ((wall-count (length
(remove-if-not (lambda (tile) (equal "wall" (tile-name tile)))
(neighbors world col row)))))
(setf (aref r row col)
(if (> wall-count 4)
(gethash 'wall *tiles* )
(gethash 'floor *tiles*))))))
(setf (aref r row col)
(funcall fn col row))))
r)))
(defun wall-neighbors (world x y)
(length
(remove-if-not (lambda (tile) (equal "wall" (tile-name tile)))
(neighbors world x y))))
(defun neighbors (world x y)
(loop for xd from (1- x) upto (1+ x) append
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment