CLIPS Rule Based Expert Systems

Discussion in 'Mac Programming' started by abijnk, Feb 18, 2008.

  1. macrumors 68040

    abijnk

    Joined:
    Oct 15, 2007
    Location:
    Los Angeles, CA
    #1
    Does anyone have any experience with writing expert systems in CLIPS? I have to do an assignment to solve the Towers of Hanoi problem using CLIPS, but I don't know how to handle the fact that the solution is recursive...

    Anyone have some advice?

    Thanks
     
  2. macrumors newbie

    Joined:
    Apr 29, 2009
    #2
    The solution

    ; Towers of Hanoi in CLIPS
    (defrule move-disk
    ?old-list <- (goals disk ?number ?from ?to $?rest)
    =>
    (retract ?old-list)
    ; (printout t "move disk from " ?from " to " ?to crlf)
    (assert (goals ?rest)))

    (defrule move-single-disk-tower

    ?old-list <- (goals tower 1 ?from ?to $?rest)
    =>
    (retract ?old-list)
    (assert (goals disk 1 ?from ?to ?rest)))

    (defrule move-tower
    ?old-list <- (goals tower ?number&1 ?from ?to $?rest)
    =>
    (retract ?old-list)
    (assert (goals tower =(- ?number 1) ?from =(- 7 ?from ?to)
    tower 1 ?from ?to
    tower =(- ?number 1) =(- 7 ?from ?to) ?to ?rest)))

    (defrule completed
    ?old-list <- (goals done)
    =>
    (retract ?old-list))
     

Share This Page