Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

abijnk

macrumors 68040
Original poster
Oct 15, 2007
3,287
5
Los Angeles, CA
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
 

zor724

macrumors newbie
Apr 29, 2009
1
0
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))
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.