; missionaries and cannibals problem ; ; This is the code that we wrote in class on 9/6/02 for the ; missionaries and cannibals problem. We'll finish this up in the ; coming week. (define start-state '(left 3 3 0 0)) (define goal-state '(right 0 0 3 3)) (define boat-side first) (define l-miss second) (define l-cann third) (define r-miss fourth) (define r-cann fifth) ; node: ( ) ; root node: ( ()) (define node:state first) (define node:parent second) (define start-node (list start-state '())) (define (mc-goal? n) (equal? (node:state n) goal-state)) (define (mc-children n) ; take state of n ; generate children of that state ; turn those state into nodes () ; this is here just so that the file will load into Scheme as is ) (define (mcs-children s) (); this is here just so that the file will load into Scheme as is ) ; assume boat on left (define (mcs-boat-trip s) (do-trip s '((-2 0 2 0) (0 -2 -2) (-1 0 1 0) (0 -1 0 1) (-1 -1 1 1))))) (define (do-trip s additions-list) (if (null? additions-list) '() (cons (list (boat-side s) (+ (l-miss s) (first (first additions-list))) (+ (l-cann s) (second (first additions-list))) (+ (r-miss s) (third (first additions-list))) (+ (r-cann s) (first (first additions-list)))) (do-trip s (cdr additions-list)))))