picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

maze.l (1112B)


      1 # 27feb13abu
      2 # (c) Software Lab. Alexander Burger
      3 
      4 # ./pil misc/maze.l -"setq M (maze 16 12)" -"display M" -bye
      5 
      6 (load "@lib/simul.l")
      7 
      8 (de maze (DX DY)
      9    (let Maze (grid DX DY)
     10       (let Fld (get Maze (rand 1 DX) (rand 1 DY))
     11          (recur (Fld)
     12             (for Dir (shuffle '((west . east) (east . west) (south . north) (north . south)))
     13                (with ((car Dir) Fld)
     14                   (unless (or (: west) (: east) (: south) (: north))
     15                      (put Fld (car Dir) This)
     16                      (put This (cdr Dir) Fld)
     17                      (recurse This) ) ) ) ) )
     18       (for (X . Col) Maze
     19          (for (Y . This) Col
     20             (set This
     21                (cons
     22                   (cons
     23                      (: west)
     24                      (or
     25                         (: east)
     26                         (and (= Y 1) (= X DX)) ) )
     27                   (cons
     28                      (: south)
     29                      (or
     30                         (: north)
     31                         (and (= X 1) (= Y DY)) ) ) ) ) ) )
     32       Maze ) )
     33 
     34 (de display (Maze)
     35    (disp Maze 0 '((This) "   ")) )
     36 
     37 # vi:et:ts=3:sw=3