;; assg 3 sp 2004 ;; did not reduce LHS's to <= 3 !! ;; === danger rules === (defrule danger-lion (declare (salience 100)) (check ?who) (lion) => (assert (danger ?who))) (defrule danger-tiger (declare (salience 100)) (check ?who) (tiger) => (assert (danger ?who))) (defrule danger-hunter (declare (salience 100)) (check ?who) (hunter) => (assert (danger ?who))) ;; -- added to make comparison psitive (defrule no-danger (declare (salience 100)) (check ?who) (not (danger ?)) => (assert (no-danger ?who))) ;; === elephant rules === (defrule elephant-danger-hungry ;; (check ?who) (elephant ?who) (danger ?who) (hungry) => (assert (goto cherry-tree) (do paint-toenails-red))) (defrule elephant-danger ;; (check ?who) (elephant ?who) (danger ?who) (not(hungry)) => (assert (goto lake) (do hide-under-water))) (defrule elephant-hungry ;; (check ?who) (elephant ?who) (no-danger ?who) (hungry) => (assert (goto savanna) (do eat))) (defrule elephant ;; (check ?who) (elephant ?who) (no-danger ?who) (not(hungry)) => (assert (goto home) (do sleep))) ;; === bird rules === (defrule bird-danger-hungry "#1" ;; (check ?who) (bird ?who) (danger ?who) (hungry) => (assert (goto forest) (do eat-at-canopy))) (defrule bird-danger "#2" ;; (check ?who) (bird ?who) (danger ?who) (not(hungry)) => (assert (goto home) (do stay-still))) (defrule bird-hungry "#3" ;; (check ?who) (bird ?who) (no-danger ?who) (hungry) => (assert (goto savanna) (do eat))) (defrule bird "#4" ;; (check ?who) (bird ?who) (no-danger ?who) (not(hungry)) => (assert (goto home) (do sleep))) ;; === report rule === (defrule conclusion (check ?who) (goto ?go) (do ?do) => (printout t ?who " should go to " ?go " and " ?do crlf)) (deffunction test() ;; --- bird tests (reset) (printout t " --- test 1 " crlf) (assert (check Tweety)(bird Tweety)(hunter)(hungry)) (run) (reset) (printout t " --- test 2 " crlf) (assert (check Tweety)(bird Tweety)(tiger)) (run) (reset) (printout t " --- test 3 " crlf) (assert (check Tweety)(bird Tweety)(hungry)) (run) (reset) (printout t " --- test 4 " crlf) (assert (check Tweety)(bird Tweety)) (run) ;; === elephant tests (reset) (printout t " --- test 5 " crlf) (assert (check Clyde)(elephant Clyde)(hunter)(hungry)) (run) (reset) (printout t " --- test 6 " crlf) (assert (check Clyde)(elephant Clyde)(lion)) (run) (reset) (printout t " --- test 7 " crlf) (assert (check Clyde)(elephant Clyde)(hungry)) (run) (reset) (printout t " --- test 8 " crlf) (assert (check Clyde)(elephant Clyde)) (run) (reset) (printout t " --- test X " crlf) (assert (bird Tweety)(check Clyde)(elephant Clyde)) (run) DONE )