diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be303db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.fasl diff --git a/grid.lisp b/grid.lisp index d7b5c3c..b87d724 100644 --- a/grid.lisp +++ b/grid.lisp @@ -33,7 +33,7 @@ (:documentation "Determine if a cell is inside the grid.")) (defgeneric random-cell (grid) - (:documentation "Return a random cell from the grid")) + (:documentation "Return a random cell from the grid")) (defgeneric size (grid) (:documentation "Return the size of the grid")) @@ -41,6 +41,9 @@ (defgeneric to-string (grid) (:documentation "Return ASCII string of the maze.")) +(defgeneric get-cell (grid row cell) + (:documentation "Return a cell at position (row,col)")) + (defmethod to-string ((obj grid)) (let ((body "") @@ -106,3 +109,7 @@ (defmethod size ((g grid)) (* (grid-rows g) (grid-cols g))) + +(defmethod get-cell ((g grid) row cell) + (aref (grid-matrix g) row cell)) + diff --git a/mazes.fossil b/mazes.fossil deleted file mode 100644 index 564d8a3..0000000 --- a/mazes.fossil +++ /dev/null Binary files differ diff --git a/mazes.lisp b/mazes.lisp index 9be1340..0a2a298 100644 --- a/mazes.lisp +++ b/mazes.lisp @@ -34,7 +34,7 @@ (defgeneric neighbors (cell) (:documentation "List of cells that adjoin this cell.")) -(defgeneric cell-distances (cell) +(defgeneric distance-to (cell) (:documentation "Caluclate distance of each cell from root cell")) (defmethod link ((current-cell cell) &key neighbor-cell (bidi t)) @@ -79,21 +79,22 @@ (setf x (* x x)) (+ x 2)) '(1 2 3)))))) |# - -(defmethod cell-distances ((root cell)) - (let ((distance (make-distance root)) - (frontier `(,root)) - (new-frontier ())) - (do () ((null frontier) ()) - (mapcar #'(lambda (cell) - (mapcar #'(lambda (linked) - (format t "mapcar2: ~a~%" linked) - (when (distance-cell linked) - (setf (distance-cell linked) (incf (distance-cell linked))))) - (links cell)) - (format t "~a" cell) - (setf frontier ())) - frontier)))) +#| +(defmethod distance-to ((ROOT CELL)) + (LET ((DIST (MAKE-DISTANCE ROOT)) + (FRONTIER `(,ROOT)) + (NEW-FRONTIER ())) + (DO () ((NULL FRONTIER) ()) + (MAPCAR #'(LAMBDA (CELL) + (MAPCAR #'(LAMBDA (LINKED) + (FORMAT T "MAPCAR2: ~A~%" LINKED) + (SET-DISTANCE DIST :DISTANCE ())) + (LINKS CELL)) + (FORMAT T "~A" CELL) + (SETF FRONTIER ())) + FRONTIER)) + DIST)) +|# ;; ;; cell constructor ;;