home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / demo / clips.sit / MAB.CLP < prev    next >
Encoding:
Text File  |  1988-04-29  |  8.2 KB  |  318 lines

  1.  
  2. ;;;======================================================
  3. ;;;   Monkees and Bannanas Sample Problem
  4. ;;;
  5. ;;;     This is an extended version of a
  6. ;;;     rather common AI planning problem.
  7. ;;;     The point is for the monkee to find
  8. ;;;     and eat some bannanas.
  9. ;;;
  10. ;;;     To execute, merely load, reset and run.
  11. ;;;======================================================
  12.  
  13.  
  14. ;(defrelation monkey (?location ?on-top-of ?holding))
  15. ;(defrelation object (?name ?location ?on-top-of ?weight))
  16. ;(defrelation chest (?name ?contents ?unlocked-by))
  17. ;(defrelation goal-is-to (?action $?arguments))
  18.  
  19. ;;;*************************
  20. ;;;* chest unlocking rules *
  21. ;;;*************************
  22.  
  23. (defrule unlock-chest-to-hold-object ""
  24.   (goal-is-to holds ?obj)
  25.   (chest ?chest ?obj ?)
  26.   (not (goal-is-to unlock ?chest))
  27.   =>
  28.   (assert (goal-is-to unlock ?chest)))
  29.  
  30. (defrule unlock-chest-to-move-object "" 
  31.   (goal-is-to move ?obj ?)
  32.   (chest ?chest ?obj ?)
  33.   (not (goal-is-to unlock ?chest))
  34.   =>
  35.   (assert (goal-is-to unlock ?chest)))
  36.  
  37. (defrule hold-chest-to-put-on-floor "" 
  38.   (goal-is-to unlock ?chest)
  39.   (object ?chest ? ~floor light)
  40.   (monkey ? ? ~?chest)
  41.   (not (goal-is-to holds ?chest))
  42.   =>
  43.   (assert (goal-is-to holds ?chest)))
  44.  
  45. (defrule put-chest-on-floor "" 
  46.   (goal-is-to unlock ?chest)
  47.   ?f1 <- (monkey ?place ?on ?chest)
  48.   ?f2 <- (object ?chest held held light)
  49.   =>
  50.   (printout t "Monkey throws " ?chest " off " ?on " onto floor." t)
  51.   (retract ?f1 ?f2)
  52.   (assert (monkey ?place ?on blank))
  53.   (assert (object ?chest ?place floor light)))
  54.  
  55. (defrule get-key-to-unlock "" 
  56.   (goal-is-to unlock ?obj)
  57.   (object ?obj ? floor ?)
  58.   (chest ?obj ? ?key)
  59.   (monkey ? ? ~?key)
  60.   (not (goal-is-to holds ?key))
  61.   =>
  62.   (assert (goal-is-to holds ?key)))
  63.  
  64. (defrule move-to-chest-with-key "" 
  65.   (goal-is-to unlock ?chest)
  66.   (monkey ?mplace ? ?key)
  67.   (object ?chest ?cplace&~?mplace floor ?)
  68.   (chest ?chest ? ?key)
  69.   (not (goal-is-to walk-to ?cplace))
  70.   =>
  71.   (assert (goal-is-to walk-to ?cplace)))
  72.  
  73. (defrule unlock-chest-with-key "" 
  74.   ?f1 <- (goal-is-to unlock ?chest)
  75.   ?f2 <- (chest ?chest ?contents ?key)
  76.   (object ?chest ?place ?on ?)
  77.   (monkey ?place ?on ?key)
  78.   =>
  79.   (printout t "Monkey opens chest with " ?key " revealing " ?contents t)
  80.   (retract ?f1 ?f2)
  81.   (assert (chest ?chest nothing ?key))
  82.   (assert (object ?contents ?place ?chest light)))
  83.  
  84. ;;;***********************
  85. ;;;* process hold object * 
  86. ;;;***********************
  87.  
  88. (defrule use-ladder-to-hold ""
  89.   (goal-is-to holds ?obj)
  90.   (object ?obj ?place ceiling light)
  91.   (not (object ladder ?place ? ?))
  92.   (not (goal-is-to move ladder ?place))
  93.   =>
  94.   (assert (goal-is-to move ladder ?place)))
  95.  
  96. (defrule climb-ladder-to-hold ""
  97.   (goal-is-to holds ?obj)
  98.   (object ?obj ?place ceiling light)
  99.   (object ladder ?place floor ?)
  100.   (monkey ? ~ladder ?)
  101.   (not (goal-is-to on ladder))
  102.   =>
  103.   (assert (goal-is-to on ladder)))
  104.  
  105. (defrule grab-object-from-ladder "" 
  106.   ?f1 <- (goal-is-to holds ?obj)
  107.   ?f2 <- (object ?obj ?place ceiling light)
  108.   (object ladder ?place ? ?)
  109.   ?f3 <- (monkey ?place ladder blank)
  110.   =>
  111.   (printout t "Monkey grabs the " ?obj t)
  112.   (retract ?f1 ?f2 ?f3)
  113.   (assert (object ?obj held held light))
  114.   (assert (monkey ?place ladder ?obj)))
  115.  
  116. (defrule climb-to-hold "" 
  117.   (goal-is-to holds ?obj)
  118.   (object ?obj ?place ?on&~ceiling light)
  119.   (monkey ?place ~?on ?)
  120.   (not (goal-is-to on ?on))
  121.   =>
  122.   (assert (goal-is-to on ?on)))
  123.  
  124. (defrule walk-to-hold ""
  125.   (goal-is-to holds ?obj)
  126.   (object ?obj ?place ~ceiling light)
  127.   (monkey ~?place ? ?)
  128.   (not (goal-is-to walk-to ?place))
  129.   =>
  130.   (assert (goal-is-to walk-to ?place)))
  131.  
  132. (defrule drop-to-hold ""
  133.   (goal-is-to holds ?obj)
  134.   (object ?obj ?place ?on light)
  135.   (monkey ?place ?on ~blank)
  136.   (not (goal-is-to holds blank))
  137.   =>
  138.   (assert (goal-is-to holds blank)))
  139.  
  140. (defrule grab-object "" 
  141.   ?f1 <- (goal-is-to holds ?obj)
  142.   ?f2 <- (object ?obj ?place ?on light)
  143.   ?f3 <- (monkey ?place ?on blank)
  144.   =>
  145.   (printout t "Monkey grabs the " ?obj t)
  146.   (retract ?f1 ?f2 ?f3)
  147.   (assert (object ?obj held held light))
  148.   (assert (monkey ?place ?on ?obj)))
  149.  
  150. ;;;**************************
  151. ;;;* move object to a place * 
  152. ;;;**************************
  153.  
  154. (defrule hold-object-to-move ""  
  155.   (goal-is-to move ?obj ?place)
  156.   (object ?obj ~?place ? light)
  157.   (monkey ? ? ~?obj)
  158.   (not (goal-is-to holds ?obj))
  159.   =>
  160.   (assert (goal-is-to holds ?obj)))
  161.  
  162. (defrule move-object-to-place "" 
  163.   (goal-is-to move ?obj ?place)
  164.   (monkey ~?place ? ?obj)
  165.   (not (goal-is-to walk-to ?place))
  166.   =>
  167.   (assert (goal-is-to walk-to ?place)))
  168.  
  169. (defrule drop-object-once-moved "" 
  170.   ?f1 <- (goal-is-to move ?obj ?place)
  171.   ?f2 <- (monkey ?place ?on ?obj)
  172.   ?f3 <- (object ?obj ? ? light)
  173.   =>
  174.   (printout t "Monkey drops the " ?obj "." t)
  175.   (retract ?f1 ?f2 ?f3)
  176.   (assert (monkey ?place ?on blank))
  177.   (assert (object ?obj ?place floor light)))
  178.  
  179. (defrule already-moved-object ""
  180.   ?f1 <- (goal-is-to move ?obj ?place)
  181.   (object ?obj ?place ? ?)
  182.   =>
  183.   (retract ?f1))
  184.  
  185. ;;;*************************
  186. ;;;* process walk-to place *
  187. ;;;*************************
  188.  
  189. (defrule already-at-place "" 
  190.   ?f1 <- (goal-is-to walk-to ?place)
  191.   (monkey ?place ? ?)
  192.   =>
  193.   (retract ?f1))
  194.  
  195. (defrule get-on-floor-to-walk ""
  196.   (goal-is-to walk-to ?place)
  197.   (monkey ~?place ~floor ?)
  198.   (not (goal-is-to on floor))
  199.   =>
  200.   (assert (goal-is-to on floor)))
  201.  
  202. (defrule walk-holding-nothing ""
  203.   ?f1 <- (goal-is-to walk-to ?place)
  204.   ?f2 <- (monkey ~?place floor blank)
  205.   =>
  206.   (printout t "Monkey walks to " ?place t)
  207.   (retract ?f1 ?f2)
  208.   (assert (monkey ?place floor blank)))
  209.  
  210. (defrule walk-holding-object ""
  211.   ?f1 <- (goal-is-to walk-to ?place)
  212.   ?f2 <- (monkey ~?place floor ?obj&~blank)
  213.   =>
  214.   (printout t "Monkey walks to " ?place " holding " ?obj t)
  215.   (retract ?f1 ?f2)
  216.   (assert (monkey ?place floor ?obj)))
  217.  
  218. (defrule drop-object ""  
  219.   ?f1 <- (goal-is-to holds blank)
  220.   ?f2 <- (monkey ?place ?on ?obj&~blank)
  221.   ?f3 <- (object ?obj held held light)
  222.   =>
  223.   (printout t "Monkey drops " ?obj t)
  224.   (retract ?f1 ?f2 ?f3)
  225.   (assert (object ?obj ?place ?on light))
  226.   (assert (monkey ?place ?on blank)))
  227.  
  228. ;;;*************************
  229. ;;;* process get on object * 
  230. ;;;*************************
  231.  
  232. (defrule jump-onto-floor "" 
  233.   ?f1 <- (goal-is-to on floor)
  234.   ?f2 <- (monkey ?at ?on&~floor ?obj)
  235.   =>
  236.   (printout t "Monkey jumps off " ?on " onto the floor." t)
  237.   (retract ?f1 ?f2)
  238.   (assert (monkey ?at floor ?obj)))
  239.  
  240. (defrule walk-to-place-to-climb "" 
  241.   (goal-is-to on ?obj)
  242.   (object ?obj ?place ? ?)
  243.   (monkey ~?place ? ?)
  244.   (not (goal-is-to walk-to ?place))
  245.   =>
  246.   (assert (goal-is-to walk-to ?place)))
  247.  
  248. (defrule drop-to-climb "" 
  249.   (goal-is-to on ?obj)
  250.   (object ?obj ?place ? ?)
  251.   (monkey ?place ? ~blank)
  252.   (not (goal-is-to holds blank))
  253.   =>
  254.   (assert (goal-is-to holds blank)))
  255.  
  256. (defrule climb-indirectly "" 
  257.   (goal-is-to on ?obj)
  258.   (object ?obj ?place ?on ?)
  259.   (monkey ?place ~?on&~?obj blank)
  260.   (not (goal-is-to on ?on))
  261.   =>
  262.   (assert (goal-is-to on ?on)))
  263.  
  264. (defrule climb-directly ""  
  265.   ?f1 <- (goal-is-to on ?obj)
  266.   (object ?obj ?place ?on ?)
  267.   ?f2 <- (monkey ?place ?on blank)
  268.   =>
  269.   (printout t "Monkey climbs onto " ?obj t)
  270.   (retract ?f1 ?f2)
  271.   (assert (monkey ?place ?obj blank)))
  272.  
  273. (defrule already-on-object ""
  274.   ?f1 <- (goal-is-to on ?obj)
  275.   (monkey ? ?obj ?)
  276.   =>
  277.   (retract ?f1))
  278.  
  279. ;;;**********************
  280. ;;;* process eat object * 
  281. ;;;**********************
  282.  
  283. (defrule hold-to-eat ""
  284.   (goal-is-to eat ?obj)
  285.   (monkey ? ? ~?obj)
  286.   (not (goal-is-to holds ?obj))
  287.   =>
  288.   (assert (goal-is-to holds ?obj)))
  289.  
  290. (defrule satisfy-hunger ""
  291.   ?f1 <- (goal-is-to eat ?obj)
  292.   ?f2 <- (monkey ?place ?on ?obj)
  293.   ?f3 <- (object ?obj ? ? ?)
  294.   =>
  295.   (printout t "Monkey eats the " ?obj "." t)
  296.   (retract ?f1 ?f2 ?f3)
  297.   (assert (monkey ?place ?on blank)))
  298.  
  299. ;;;*****************
  300. ;;;* initial-state * 
  301. ;;;*****************
  302.  
  303. (defrule startup ""
  304.   =>
  305.   (assert (monkey t5-7 green-couch blank))
  306.   (assert (object green-couch t5-7 floor heavy))
  307.   (assert (object red-couch t2-2 floor heavy))
  308.   (assert (object big-pillow t2-2 red-couch light))
  309.   (assert (object red-chest t2-2 big-pillow light))
  310.   (assert (chest red-chest ladder red-key))
  311.   (assert (object blue-chest t7-7 ceiling light))
  312.   (assert (chest blue-chest bananas blue-key))
  313.   (assert (object blue-couch t8-8 floor heavy))
  314.   (assert (object green-chest t8-8 ceiling light))
  315.   (assert (chest green-chest blue-key red-key))
  316.   (assert (object red-key t1-3 floor light))
  317.   (assert (goal-is-to eat bananas)))
  318.