(deftemplate ingredients (slot name) (slot quantity) ) (deffacts init (auxiliar aux) (menu-level engine main) ) (defrule start (auxiliar aux) ?m <- (menu-level engine main) => (retract ?m) (printout t crlf crlf crlf) (printout t " *******EXPERT BREAKFAST*******" crlf " To start, please tell me what ingredients do you have!" crlf crlf crlf " Quantity of Eggs: ") (bind ?response (read)) (assert (ingredients (name Egg) (quantity ?response) )) (printout t " Quantity of Bread: ") (bind ?response2 (read)) (assert (ingredients (name Bread) (quantity ?response2)) ) (printout t " Milliliters of Milk: ") (bind ?response3 (read)) (assert (ingredients (name Milk) (quantity ?response3)) ) (printout t " Grams of Cereals: ") (bind ?response4 (read)) (assert (ingredients (name Cereals) (quantity ?response4)) ) (printout t " Grams of Cheese: ") (bind ?response5 (read)) (assert (ingredients (name Cheese) (quantity ?response5)) ) (printout t " Grams of Ham: ") (bind ?response6 (read)) (assert (ingredients (name Ham) (quantity ?response6)) ) (printout t crlf crlf " > Lets start cooking? <" crlf " (yes/no): ") (bind ?response9 (read)) (assert (step ?response9)) ) (defrule cook (auxiliar aux) ?s <- (step yes) => (retract ?s) (printout t crlf crlf " Ok, so tell me what you want to eat! " crlf crlf " 1) Cereals" crlf " 2) Omelette" crlf " 3) Fried Eggs" crlf " 4) Scrambled Eggs" crlf " 5) French Toast" crlf " 6) Sandwich" crlf crlf " Choice: ") (bind ?response (read)) (assert (choice ?response)) ) (defrule cereals (auxiliar aux) ?c <- (choice 1) ?ingr <- (ingredients (name Milk) (quantity ?q)) (test (>= ?q 200)) ?ingr2 <- (ingredients (name Cereals) (quantity ?q2)) (test (>= ?q2 100)) => (retract ?c) (printout t crlf" Preparing cereals..."crlf crlf " Bon Appétit!" crlf) (modify ?ingr (quantity (- ?q 200))) (modify ?ingr2 (quantity (- ?q2 100))) (printout t crlf crlf " > Do you wanna cook anything else? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule cereals2 (auxiliar aux) ?c <- (choice 1) => (retract ?c) (printout t crlf " You don't have the ingredients necessary to make Cereals!" crlf " You need at least 200cl of Milk and 100gr of Cereals" crlf crlf) (printout t crlf crlf " > Do you wanna try to cook a different recipe? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule omelette (auxiliar aux) ?c <- (choice 2) ?ingr <- (ingredients (name Egg) (quantity ?q)) (test (>= ?q 2)) => (retract ?c) (printout t crlf " Preparing omelette..."crlf crlf " Bon Appétit!" crlf) (modify ?ingr (quantity (- ?q 2))) (printout t crlf crlf " > Do you wanna cook anything else? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule omelette2 (auxiliar aux) ?c <- (choice 2) => (retract ?c) (printout t crlf " You don't have the ingredients necessary to make an Omelette!" crlf " You need at least 2 Eggs" crlf crlf " > Do you wanna try to cook a different recipe? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule fried (auxiliar aux) ?c <- (choice 3) ?ingr <- (ingredients (name Egg) (quantity ?q)) (test (>= ?q 1)) => (retract ?c) (printout t crlf " Preparing Fried Eggs..."crlf crlf " Bon Appétit!" crlf) (modify ?ingr (quantity (- ?q 1))) (printout t " > Do you wanna cook anything else? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule fried2 (auxiliar aux) ?c <- (choice 3) => (retract ?c) (printout t crlf " You don't have the ingredients necessary to make Fried Eggs!" crlf " You need at least 1 Egg" crlf crlf " > Do you wanna try to cook a different recipe? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule scrambled (auxiliar aux) ?c <- (choice 4) ?ingr <- (ingredients (name Egg) (quantity ?q)) (test (>= ?q 2)) => (retract ?c) (printout t crlf " Preparing Scrambled Eggs..."crlf crlf " Bon Appétit!" crlf) (modify ?ingr (quantity (- ?q 2))) (printout t " > Do you wanna cook anything else? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule scrambled2 (auxiliar aux) ?c <- (choice 4) => (retract ?c) (printout t crlf " You don't have the ingredients necessary to make Scrambled Eggs!" crlf " You need at least 2 Eggs" crlf crlf " > Do you wanna try to cook a different recipe? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule ftoast (auxiliar aux) ?c <- (choice 5) ?ingr <- (ingredients (name Egg) (quantity ?q)) (test (>= ?q 1)) ?ingr2 <- (ingredients (name Bread) (quantity ?q2)) (test (>= ?q2 2)) => (retract ?c) (printout t crlf " Preparing French Toast..."crlf crlf " Bon Appétit!" crlf) (modify ?ingr (quantity (- ?q 1))) (modify ?ingr2 (quantity (- ?q2 2))) (printout t " > Do you wanna cook anything else? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule ftoast2 (auxiliar aux) ?c <- (choice 5) => (retract ?c) (printout t crlf " You don't have the ingredients necessary to make Franch Toast!" crlf " You need at least 1 Egg and 2 Breads" crlf crlf " > Do you wanna try to cook a different recipe? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule sandwich (auxiliar aux) ?c <- (choice 6) ?ingr <- (ingredients (name Cheese) (quantity ?q)) (test (>= ?q 1)) ?ingr2 <- (ingredients (name Ham) (quantity ?q2)) (test (>= ?q2 1)) ?ingr3 <- (ingredients (name Bread) (quantity ?q3)) (test (>= ?q3 2)) => (retract ?c) (printout t crlf " Preparing Sandwich..."crlf crlf " Bon Appétit!" crlf) (modify ?ingr (quantity (- ?q 1))) (modify ?ingr2 (quantity (- ?q2 1))) (modify ?ingr3 (quantity (- ?q3 1))) (printout t " > Do you wanna cook anything else? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule sandwich2 (auxiliar aux) ?c <- (choice 6) => (retract ?c) (printout t crlf " You don't have the ingredients necessary to make Sandwich!" crlf " You need at least 1 Bread, 1 slice of Cheese and 1 slice of Ham" crlf crlf " > Do you wanna try to cook a different recipe? <" crlf " (yes/no): ") (bind ?response10 (read)) (assert (step ?response10)) ) (defrule user-quits (auxiliar aux) (step no) => (printout t crlf " *******EXPERT BREAKFAST*******" crlf " Have a good day! :)" crlf crlf crlf ) (halt))