;;; Prof R. Williams Artificial Intelligence ;;; ;;; The following implements depth-limited depth-first search for a path ;;; from a given start to any goal state in a graph. For simplicity, no ;;; checking is done for repeated states. (defun find-path-dldf (start goal-test successors depth-limit) (check-node start goal-test nil successors depth-limit) ) (defun check-node (node goal-test path-so-far successors dl) (let ((path-so-far (cons node path-so-far))) (cond ((funcall goal-test node) path-so-far) ((zerop dl) nil) (t (check-nodes (funcall successors node) goal-test path-so-far successors dl)) ))) (defun check-nodes (nodes goal-test path-so-far successors dl) (unless (null nodes) (or (check-node (first nodes) goal-test path-so-far successors (1- dl)) (check-nodes (rest nodes) goal-test path-so-far successors dl)) ))