home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0622.ZIP / CCE_0622.PD / CLIPS / BLOCKS.CLP next >
Text File  |  1993-09-01  |  2KB  |  58 lines

  1.  
  2. ;;;======================================================
  3. ;;;   Sample Blocks World Problem
  4. ;;;
  5. ;;;     A real simple implementation of the blocks
  6. ;;;     world. Rules merely unstack the blocks in 
  7. ;;;     the proper order.
  8. ;;;
  9. ;;;     To execute, merely load, reset and run.
  10. ;;;======================================================
  11.  
  12. (deffacts known
  13.    (stack a b c)
  14.    (stack d e f)
  15.    (move-goal b on-top-of e)
  16.    (stack))
  17.  
  18. (defrule move-it ""
  19.   ?goal <- (move-goal ?block-1 on-top-of ?block-2)
  20.   ?stack-1 <- (stack ?block-1 $?rest-1)
  21.   ?stack-2 <- (stack ?block-2 $?rest-2)
  22.   =>
  23.   (retract ?goal ?stack-1 ?stack-2)
  24.   (assert (stack $?rest-1))
  25.   (assert (stack ?block-1 ?block-2 $?rest-2))
  26.   (printout ?block-1 " moved on top of " ?block-2 "." crlf))
  27.  
  28. (defrule floor-move ""
  29.   ?goal <- (move-goal ?block on-top-of floor)
  30.   ?stack <- (stack ?block ?under $?rest)
  31.   =>
  32.   (retract ?goal ?stack)
  33.   (assert (stack ?block))
  34.   (assert (stack ?under $?rest))
  35.   (printout ?block " moved on top of floor." crlf))
  36.  
  37. (defrule move-to-move ""
  38.   (declare (salience -100))
  39.   ?goal <- (move-goal ?block-1 on-top-of ?block-2)
  40.   ?stack <- (stack ?top $? ?block $?)
  41.   (test (|| (eq ?block ?block-1) (eq ?block ?block-2)))
  42.   =>
  43.   (assert (move-goal ?top on-top-of floor)))
  44.  
  45. (defrule goal-satisfied-1 ""
  46.   (declare (salience 100))
  47.   ?goal <- (move-goal ?block-1 on-top-of ?block-2)
  48.   (stack $? ?block-1 ?block-2 $?)
  49.   =>
  50.   (retract ?goal))
  51.  
  52. (defrule goal-satisfied-2 ""
  53.   (declare (salience 100))
  54.   ?goal <- (move-goal ?block on-top-of floor)
  55.   (stack $? ?block)
  56.   =>
  57.   (retract ?goal))
  58.