;;; flashlight.scm Dave Reed 10/04/04 (require (lib "list.ss")) (require (lib "compat.ss")) (define (GET-MOVES state) (define (all-pairs lst) (define (pair-up item lst) (if (null? lst) '() (cons (list item (car lst)) (pair-up item (cdr lst))))) (cond ((< (length lst) 2) '()) ((= (length lst) 2) (list lst)) (else (append (pair-up (car lst) (cdr lst)) (all-pairs (cdr lst)))))) (define (all-moves move-list) (if (null? move-list) '() (cons (list (if (equal? (cadr state) 'left) (list (remove-all (car move-list) (car state)) 'right (sort < (append (caddr state) (car move-list)))) (list (sort < (append (car state) (car move-list))) 'left (remove-all (car move-list) (caddr state)))) (apply max (car move-list))) (all-moves (cdr move-list))))) (if (equal? (cadr state) 'left) (all-moves (append (map list (car state)) (all-pairs (car state)))) (all-moves (append (map list (caddr state)) (all-pairs (caddr state)))))) (define (remove-all del-list arblist) (cond ((null? arblist) '()) ((member (car arblist) del-list) (remove-all del-list (cdr arblist))) (else (cons (car arblist) (remove-all del-list (cdr arblist)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ORIGINAL VERSION: COUNT NUMBER OF PEOPLE OUT OF POSITION (define (H state goalState) (+ (length (remove-all (car goalState) (car state))) (length (remove-all (caddr goalState) (caddr state)))))