diff --git a/distances.lisp b/distances.lisp index 50d8a5c..3842db3 100644 --- a/distances.lisp +++ b/distances.lisp @@ -2,24 +2,40 @@ (defclass distances () ((root :initarg :root :accessor root-cell) - (cells :initarg :cells :initform (make-hash-table) :accessor distance-cells)) + (cells :initarg :cells :initform (make-hash-table) :accessor distance-cells) + (grid :initarg :grid :accessor distance-grid)) (:documentation "Keeps track of the distance of each cell from the given root cell.")) (defmethod initialize-instance :after ((d distances) &key) (setf (gethash (root-cell d) (distance-cells d)) 0)) -(defgeneric set-distance (distance &key) +(defgeneric set-distance (distances &key) (:documentation "Set the distance of the given cell from the root cell")) +(defgeneric calc-distance (distances) + (:documentation "Set the distance of the given cell from the root cell")) + + (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))) +|# -(defun make-distance (root) - (make-instance 'distances :root root)) + +(defmethod calc-distance ((d distances)) + (let* ((matrix (grid-matrix (distance-grid d))) + (num-rows (grid-rows (distance-grid d))) + (num-cols (grid-cols (distance-grid d))))) + (format t "calculate-distances...")) + + +(defun make-distance (root grid) + (make-instance 'distances :root root :grid grid)) diff --git a/mazes.lisp b/mazes.lisp index 0a2a298..9e71b6c 100644 --- a/mazes.lisp +++ b/mazes.lisp @@ -95,6 +95,17 @@ FRONTIER)) DIST)) |# +(defmethod distance-to ((root cell)) + (let* ((dist (make-distance root)) + (frontier '(root))) + (do () ((null frontier) ()) + (mapcar #'(lambda (cell) + (mapcar #'(lambda (linked) + (format t "2nd mapcar: ~a~%" linked)) + (links cell)) + (format t "~a~%" cell)) + frontier)) + dist)) ;; ;; cell constructor ;;