;----------------------------------------------------------------------------------------- ; The status of the water in the water-jug ; (deftemplate status (slot water-jug (type INTEGER) (default 0))) ;----------------------------------------------------------------------------------------- ; The initial Status ;; (defrule Initial-State ?initial <- (initial-fact) => (printout t "The Initial State is an Empty Jug" crlf) (assert (status (water-jug 0)))) ;----------------------------------------------------------------------------------------- ; Rule for Adding One Gallon to Water Jug ; (defrule Add-One-Gallon ?status <- (status (water-jug ?amount)) => (printout t "Adding 1 Gallon to " ?amount " to make " (+ 1 ?amount) " gallons" crlf) (modify ?status (water-jug (+ ?amount 1)))) ;----------------------------------------------------------------------------------------- ; Rule for Adding Two Gallons to Water Jug ; (defrule Add-Two-Gallons ?status <- (status (water-jug ?amount)) => (printout t "Adding 2 Gallons to " ?amount " to make " (+ 2 ?amount) " gallons" crlf) (modify ?status (water-jug (+ ?amount 2)))) ;----------------------------------------------------------------------------------------- ; Rule for Detecting Done with Task (i.e. the jug has 3 gallons in it) ; (defrule Done (declare (salience 1000)) ?status <- (status (water-jug 3)) => (printout t "Done - Jug has Three Gallons" crlf))