Functions for Missionaries and Cannibals


(defun ml (state) (second state))   ; m on left
(defun mr (state) (- *mtotal* (second state)))
(defun m (s) (if (boat s) (ml s) (mr s)))

(defun applicable? (op s)
  (and (< = (op-m op) (m s)) (< = (op-c op) (c s))))

; Test for failure: c >  m >  0 on either side.
(defun failure? (s)
  (or (>  (cl s) (ml s) 0)
      (>  (cr s) (mr s) 0) ) )
      
(defun goal? (s)    ; 0 mis and 0 can on left
  (and (= (ml s) 0) (= (cl s) 0) ) )

(defun apply-op (op s)   ; apply op =>  new state
  (if (boat s)
      (list nil (- (ml s) (op-m op))
                (- (cl s) (op-c op)))
      (list t   (+ (ml s) (op-m op))
                (+ (cl s) (op-c op))) ))

Contents    Page-10    Prev    Next    Page+10    Index