From: Troy McKinnon
Subject: HELP - neighbors "block world"
Date: 
Message-ID: <3472ECDB.496F@cryogen.com>
Hello again:

Below is something like what I have so far ... is this getting any
closer... 
REFER: <help - block world>
I am trying to impliment a block world search using stripping
representation and forward planning...
I am having trouble getting neighbors.  

<REPLY: ···············@cryogen.com>

I am thinking I might have to rewrite like this:

- Check Neighbor:

   neighbor(World1, Action, World2)

      It succeeds if performing the Action  in World1 can result
      in World2.

   neighbor(State1, Action, State2) <-
       preconds(Action, Pre),
       subset(Pre, State1),
       addlist(Action, AddList),
       deletelist(Action, DelList),
       remove(DelList, State1),
       append(AddList, State1, State2);

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BEGIN CODE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun extend (path)(print (reverse path))		; print results
	;(setf count (+ count 1))	; track number of steps
	(mapcar #'(lambda (new-node) (cons new-node path)) ; lambda function
used to apply function to list
	        (remove-if #'(lambda (neighbor) (my-member neighbor path)) ;
remove if member of path
			   (get-neighbors);(first path))
		  )
	)
)

; depth-first search
(defun depth-first (start finish &optional (queue (list (list start))))
	(cond		; set conditions
	((endp queue) nil)		; Is queue empty ?
	((equalp finish (first (first queue))) ; Is finish found ?
	     (reverse (first queue)))	; reverse first element of queue
	(t (depth-first start finish (append (extend (first queue)) (rest
queue)))) 	; recurse new path-queue
	)
)


(defvar *STACK* '(cleartop(Y) holding(X)))
(defvar *UNSTACK* '(handempty cleartop(X) on(X Y)))
(defvar *PICKUP* '(handempty ontable(X) cleartop(X)))
(defvar *PUTDOWN* '(holding(X)))
(defvar *ACTION_ARRAY* '(STACK UNSTACK PICKUP PUTDOWN))
(defvar *BLOCKS* '(a b c d))

(defvar InitialState '(ontable(a) ontable(c) cleartop(a) cleartop(b)
handempty))
(defvar GoalState '(ontable(c) on(a c) on(b a) cleartop(b) handempty))

; Function to determine neighbors of a given node
(defun get-neighbors () ;(State1 Action State2)
	(dotimes (i 3)	
		(setf X (nth i *BLOCKS*))
		(dotimes (j 3)
			(setf Y (nth j *BLOCKS*))
			(neighbors (X Y))
		)
	)
	neighbors ; return neighbor list
)

(defun neighbors (X Y)
   (dotimes (i 3)
   (setf ACTION (nth i *ACTION_ARRAY*))
	(if (and (eq ACTION stack(X Y)) 
		(all-members *STACK* CurrentState)
	    )
	    (append neighbors *STACK*)
	)
	(if (and (eq ACTION unstack(X Y)) 
		(all-members *UNSTACK* CurrentState)
	    )
	    (append neighbors *UNSTACK*)
	)
	(if (and (eq ACTION pickup(X)) 
		(all-members *PICKUP* CurrentState)
	    ) 
	    (append neighbors *PICKUP*)
	)
	(if (and (eq ACTION putdown(X)) 
		(all-members *PUTDOWN* CurrentState)
	    ) 
	    (append neighbors *PUTDOWN*)
	)
   )
        neighbors; return neighbor array
)

;  Used to find out if every element of list1 is contained
;  in list2.

(defun all-members (list1 list2)
       (setq a list1)
       (setq b list2)
       (cond ((member nil (mapcar 
                              '(lambda (x) (member x b))
                              a
                          )
              )
                  nil
              )
              (t t)
       )
)