Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defvar *letters* nil)
- (defvar *steps* 0)
- (defstruct coord nil (y 0) (x 0))
- (defvar dir (new coord y 1 x 0))
- (defvar p (new coord))
- (defvar *map*
- (vec-list
- (mapcar (lambda (l)
- (vec-list
- (mapcar (lambda (c)
- (caseq c
- (#\space nil)
- ((#\| #\- #\+) t)
- (t c)))
- l)))
- (get-lines))))
- (defun is-in-bounds (y x)
- (and (<= 0 x (- (len [*map* 0]) 1))
- (<= 0 y (- (len *map*) 1))))
- (defun find-new-dir ()
- (let ((new-dir (new coord))
- (new-p (copy-struct p))
- (slot (if (= dir.x 0) 'x 'y)))
- (inc (slot new-p slot))
- (if [[*map* new-p.y] new-p.x]
- (inc (slot new-dir slot)))
- (dec (slot new-p slot) 2)
- (if [[*map* new-p.y] new-p.x]
- (dec (slot new-dir slot)))
- (if (= new-dir.x new-dir.y) nil new-dir)))
- (set p.x (car (where (fun use) [*map* 0])))
- (while t
- (inc *steps*)
- (if (chrp [[*map* p.y] p.x])
- (set *letters* (cons [[*map* p.y] p.x] *letters*)))
- (cond ((or (not (is-in-bounds (+ p.y dir.y) (+ p.x dir.x)))
- (not [[*map* (+ p.y dir.y)] (+ p.x dir.x)]))
- (set dir (find-new-dir))
- (unless dir (return))))
- (inc p.x dir.x)
- (inc p.y dir.y))
- (mapcar (fun put-char) (nreverse *letters*))
- (format t "\n~a\n" *steps*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement