State Space Search Program


(defun sss (s prev ops) ; state, prev states,
 (let ((op (pop ops)))  ; op = next ops to try
  (if (goal? s)         ; if s is a goal,
      '()               ; answer = list of no ops
    (if (or (failure? s) (null op))
        'failure
      (if (applicable? op s)
          (let ((new (apply-op op s)))
                  ; if it duplicates a prev state
            (if (member new prev :test #'equal)
                  ; try the next op
                (sss s prev ops)
                  ; else try to search from new
                (let ((opseq (sss new
                                  (cons s prev)
                                  *ops*)))
                      ; if search failed
                  (if (eq opseq 'failure)
                      ; try the next op
                      (sss s prev ops)
                      ; else cons op onto answer
                      (cons op opseq)))))
          ; try another op
          (sss s prev ops))))))

Contents    Page-10    Prev    Next    Page+10    Index