diff --git a/distances.lisp b/distances.lisp index 7809e00..d166621 100644 --- a/distances.lisp +++ b/distances.lisp @@ -17,21 +17,13 @@ (defgeneric calculate-distance (distances) (:documentation "Set the distance of the given cell from the root cell")) +(defgeneric distance-from-root-to (distances &key) + (:documentation "Get the distance from the root cell to cell at :X :Y position")) (defmethod set-distance ((d distances) &key cell distance) (let ((cells (distance-cells d))) (setf (gethash cell cells) distance))) - -(defgeneric distance-all-cells (distances) - (:documentation "Return a list of cells with their respective distance from root")) - -#| -(defmethod distance-all-cells ((d distances)) - (get-hash-keys (distance-cells d))) -|# - - (defmethod calculate-distance ((d distances)) ; (declare (optimize (debug 3))) (let* ((frontier (list (root-cell d))) @@ -47,5 +39,9 @@ (setf frontier (copy-tree new-frontier)))) (distance-cells d)) +(defmethod distance-from-root-to ((d distances) &key x y) + (let ((cell (get-cell (distance-grid d) x y))) + (gethash cell (distance-cells d)))) + (defun make-distance (root grid) (make-instance 'distances :root root :grid grid)) diff --git a/mazes.lisp b/mazes.lisp index 9e71b6c..3f8b208 100644 --- a/mazes.lisp +++ b/mazes.lisp @@ -68,33 +68,6 @@ (cell-neighbors current-cell)) -#| -(defmethod distances ((root cell)) - ((let ((distances (make-distance root)) - (frontier '(root)) - (new-frontier ())) - ; DO..UNTIL frontier is empty - (do () ((null frontier) ()) - (mapcar #'(lambda (x) - (setf x (* x x)) - (+ x 2)) '(1 2 3)))))) -|# -#| -(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)) -|# (defmethod distance-to ((root cell)) (let* ((dist (make-distance root)) (frontier '(root)))