home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Club Elmshorn Atari PD
/
CCE_PD.iso
/
pc
/
0600
/
CCE_0622.ZIP
/
CCE_0622.PD
/
CLIPS
/
MAB.CLP
< prev
next >
Wrap
Text File
|
1993-09-01
|
9KB
|
312 lines
;;;======================================================
;;; Monkees and Bannanas Sample Problem
;;;
;;; This is an extended version of a
;;; rather common AI planning problem.
;;; The point is for the monkee to find
;;; and eat some bannanas.
;;;
;;; To execute, merely load, reset and run.
;;;======================================================
;;;*************************
;;;* chest unlocking rules *
;;;*************************
(defrule unlock-chest-to-hold-object ""
(goal-is-to active holds ?obj)
(object ?chest ? ? ? ?obj ?)
(not (goal-is-to active unlock ?chest))
=>
(assert (goal-is-to active unlock ?chest)))
(defrule unlock-chest-to-move-object ""
(goal-is-to active move ?obj ?)
(object ?chest ? ? ? ?obj ?)
(not (goal-is-to active unlock ?chest))
=>
(assert (goal-is-to active unlock ?chest)))
(defrule hold-chest-to-put-on-floor ""
(goal-is-to active unlock ?chest)
(object ?chest ? light ~floor ? ?)
(not (goal-is-to active holds ?chest))
=>
(assert (goal-is-to active holds ?chest)))
(defrule put-chest-on-floor ""
(goal-is-to active unlock ?chest)
?f1 <- (monkey ?place ?on ?chest)
?f2 <- (object ?chest held light held ?contains ?key)
=>
(printout "Monkey throws " ?chest " off " ?on " onto floor." crlf)
(retract ?f1 ?f2)
(assert (monkey ?place ?on blank))
(assert (object ?chest ?place light floor ?contains ?key)))
(defrule get-key-to-unlock ""
(goal-is-to active unlock ?obj)
(object ?obj ?place ? floor ? ?key)
(monkey ? ? ~?key)
(not (goal-is-to active holds ?key))
=>
(assert (goal-is-to active holds ?key)))
(defrule move-to-chest-with-key ""
(goal-is-to active unlock ?chest)
(monkey ?mplace ? ?key)
(object ?chest ?cplace&~?mplace ? floor ? ?key)
(not (goal-is-to active walk-to ?cplace))
=>
(assert (goal-is-to active walk-to ?cplace)))
(defrule unlock-chest-with-key ""
?f1 <- (goal-is-to active unlock ?chest-obj)
?f2 <- (object ?chest-obj ?place ?weight ?on ?obj-in ?key)
(monkey ?place ?on ?key)
=>
(printout "Monkey opens chest with " ?key " revealing " ?obj-in crlf)
(retract ?f1 ?f2)
(assert (object ?chest-obj ?place ?weight ?on nil ?key))
(assert (object ?obj-in ?place light ?chest-obj nil nil)))
;;;***********************
;;;* process hold object *
;;;***********************
(defrule use-ladder-to-hold ""
(goal-is-to active holds ?obj)
(object ?obj ?place light ceiling ? ?)
(not (goal-is-to active move ladder ?place))
=>
(assert (goal-is-to active move ladder ?place)))
(defrule climb-ladder-to-hold ""
(goal-is-to active holds ?obj)
(object ?obj ?place light ceiling ? ?)
(object ladder ?place ? floor ? ?)
(not (goal-is-to active on ladder))
=>
(assert (goal-is-to active on ladder)))
(defrule grab-object-from-ladder ""
?f1 <- (goal-is-to active holds ?obj)
?f2 <- (object ?obj ?place light ceiling ?contains ?key)
(object ladder ?place ? ? ? ?)
?f3 <- (monkey ?place ladder blank)
=>
(printout "Monkey grabs the " ?obj crlf)
(retract ?f1 ?f2 ?f3)
(assert (object ?obj held light held ?contains ?key))
(assert (monkey ?place ladder ?obj)))
(defrule climb-to-hold ""
(goal-is-to active holds ?obj)
(object ?obj ?place light ?on&~floor&~ceiling ? ?)
(monkey ?place ~?on ?)
(not (goal-is-to active on ?on))
=>
(assert (goal-is-to active on ?on)))
(defrule walk-to-hold ""
(goal-is-to active holds ?obj)
(object ?obj ?place light ~ceiling ? ?)
(monkey ~?place ? ?)
(not (goal-is-to active walk-to ?place))
=>
(assert (goal-is-to active walk-to ?place)))
(defrule drop-to-hold ""
(goal-is-to active holds ?obj)
(object ?obj ?place light floor ? ?)
(monkey ?place ? ~blank)
(not (goal-is-to active holds blank))
=>
(assert (goal-is-to active walk-to ?place)))
(defrule get-on-floor-to-hold ""
(goal-is-to active holds ?obj)
(object ?obj ?place light floor ? ?)
(monkey ?place ~floor ?)
(not (goal-is-to active on floor))
=>
(assert (goal-is-to active on floor)))
(defrule grab-object ""
?f1 <- (goal-is-to active holds ?obj)
?f2 <- (object ?obj ?place light ?on ?contains ?key)
?f3 <- (monkey ?place ?on blank)
=>
(printout "Monkey grabs the " ?obj crlf)
(retract ?f1 ?f2 ?f3)
(assert (object ?obj held light held ?contains ?key))
(assert (monkey ?place ?on ?obj)))
;;;**************************
;;;* move object to a place *
;;;**************************
(defrule hold-object-to-move ""
(goal-is-to active move ?obj ?place)
(object ?obj ~?place light ? ? ?)
(monkey ? ? ~?obj)
(not (goal-is-to active holds ?obj))
=>
(assert (goal-is-to active holds ?obj)))
(defrule move-object-to-place ""
(goal-is-to active move ?obj ?place)
(monkey ~?place ? ?obj)
(not (goal-is-to active walk-to ?place))
=>
(assert (goal-is-to active walk-to ?place)))
(defrule drop-object-once-moved ""
?f1 <- (goal-is-to active move ?obj ?place)
?f2 <- (monkey ?place ?on ?obj)
?f3 <- (object ?obj ? light ? ?contains ?key)
=>
(printout "Monkey drops the " ?obj "." crlf)
(retract ?f1 ?f2 ?f3)
(assert (monkey ?place ?on blank))
(assert (object ?obj ?place light floor ?contains ?key)))
(defrule already-moved-object ""
?f1 <- (goal-is-to active move ?obj ?place)
(object ?obj ?place ? ? ? ?)
=>
(retract ?f1))
;;;*************************
;;;* process walk-to place *
;;;*************************
(defrule already-at-place ""
?f1 <- (goal-is-to active walk-to ?place)
(monkey ?place ? ?)
=>
(retract ?f1))
(defrule get-on-floor-to-walk ""
(goal-is-to active walk-to ?place)
(monkey ~?place ~floor ?)
(not (goal-is-to active on floor))
=>
(assert (goal-is-to active on floor)))
(defrule walk-holding-nothing ""
?f1 <- (goal-is-to active walk-to ?place)
?f2 <- (monkey ~?place floor blank)
=>
(printout "Monkey walks to " ?place crlf)
(retract ?f1 ?f2)
(assert (monkey ?place floor blank)))
(defrule walk-holding-object ""
?f1 <- (goal-is-to active walk-to ?place)
?f2 <- (monkey ~?place floor ?obj&~blank)
=>
(printout "Monkey walks to " ?place " holding " ?obj crlf)
(retract ?f1 ?f2)
(assert (monkey ?place floor ?obj)))
(defrule drop-object ""
?f1 <- (goal-is-to active holds blank)
?f2 <- (monkey ?place ?on ?obj&~blank)
?f3 <- (object ?obj held light held ?inside ?key)
=>
(printout "Monkey drops " ?obj crlf)
(retract ?f1 ?f2 ?f3)
(assert (object ?obj ?place light ?on ?inside ?key))
(assert (monkey ?place ?on blank)))
;;;*************************
;;;* process get on object *
;;;*************************
(defrule jump-onto-floor ""
?f1 <- (goal-is-to active on floor)
?f2 <- (monkey ?at ?on&~floor ?obj)
=>
(printout "Monkey jumps off " ?on " onto the floor." crlf)
(retract ?f1 ?f2)
(assert (monkey ?at floor ?obj)))
(defrule walk-to-place-to-climb ""
(goal-is-to active on ?obj)
(object ?obj ?place ? ? ? ?)
(monkey ~?place ? ?)
(not (goal-is-to active walk-to ?place))
=>
(assert (goal-is-to active walk-to ?place)))
(defrule drop-to-climb ""
(goal-is-to active on ?obj)
(object ?obj ?place ? ? ? ?)
(monkey ?place ? ~blank)
(not (goal-is-to active holds blank))
=>
(assert (goal-is-to active holds blank)))
(defrule climb-indirectly ""
(goal-is-to active on ?obj)
(object ?obj ?place ? ?on ? ?)
(monkey ?place ~?on&~?obj blank)
(not (goal-is-to active on ?on))
=>
(assert (goal-is-to active on ?on)))
(defrule climb-directly ""
?f1 <- (goal-is-to active on ?obj)
(object ?obj ?place ? ?on ? ?)
?f2 <- (monkey ?place ?on blank)
=>
(printout "Monkey climbs onto " ?obj crlf)
(retract ?f1 ?f2)
(assert (monkey ?place ?obj blank)))
(defrule already-on-object ""
?f1 <- (goal-is-to active on ?obj)
(monkey ? ?obj ?)
=>
(retract ?f1))
;;;**********************
;;;* process eat object *
;;;**********************
(defrule hold-to-eat ""
(goal-is-to active eat ?obj)
(monkey ? ? ~?obj)
(not (goal-is-to active holds ?obj))
=>
(assert (goal-is-to active holds ?obj)))
(defrule satisfy-hunger ""
?f1 <- (goal-is-to active eat ?obj)
?f2 <- (monkey ?place ?on ?obj)
?f3 <- (object ?obj ? ? ? ? ?)
=>
(printout "Monkey eats the " ?obj "." crlf)
(retract ?f1 ?f2 ?f3)
(assert (monkey ?place ?on blank)))
;;;*****************
;;;* initial-state *
;;;*****************
(defrule startup ""
(initial-fact)
=>
(assert (monkey t5-7 green-couch blank))
(assert (object green-couch t5-7 heavy floor foo foo))
(assert (object red-couch t2-2 heavy floor foo foo))
(assert (object big-pillow t2-2 light red-couch foo foo))
(assert (object red-chest t2-2 light big-pillow ladder red-key))
(assert (object blue-chest t7-7 light ceiling bananas blue-key))
(assert (object blue-couch t8-8 heavy floor foo foo))
(assert (object green-chest t8-8 light ceiling blue-key red-key))
(assert (object red-key t1-3 light floor foo foo))
(assert (goal-is-to active eat bananas)))