(defun astar (state) (as state nil nil 0)) (defun as (state history togoto g_value) (cond ((in state history) (as (caddar togoto) history (cdr togoto) (caar togoto))) ((goal_test state) (list g_value (length history))) (t (as2 (addnewstates (expand state g_value operators) togoto) (cons state history))))) (defun as2 (togoto history) (cond ((null togoto) nil) (t (as (caddar togoto) history (cdr togoto) (caar togoto))))) (defun expand (state g_value ops) (cond ((null ops) nil) (t (expand2 state g_value ops (funcall (car ops) state))))) (defun expand2 (state g_value ops result) (cond ((null result) (expand state g_value (cdr ops))) (t (cons (list (+ (caar result) g_value) (h (cadar result)) (cadar result)) (expand state g_value (cdr ops)))))) (defun addnewstates (newlist togoto) (cond ((null newlist) togoto) (t (addone (car newlist) (addnewstates (cdr newlist) togoto))))) ; (t (append (addone (car newlist) togoto) ; (addnewstates (cdr newlist) togoto))))) (defun addone (one togoto) (cond ((null togoto) (list one)) ((< (+ (car one) (cadr one)) (+ (caar togoto) (cadar togoto))) (cons one togoto)) (t (cons (car togoto) (addone one (cdr togoto)))))) ;(defun length (lst) ; (cond ((null lst) 0) ; (t (1+ (cdr lst))))) (defun in (x y) (member x y :test #'equal))