
APT.all-test.towers-of-hanoi.towers-of-hanoi-no-ops.soar Maven / Gradle / Ivy
###
### FILE : tower-of-hanoi8.soar
###
###
### ABSTRACT. This file provides a Soar system to solve the Tower
### of Hanoi problems. This puzzle "involves three vertical pegs or
### posts and a number of doughnut-like disks of graduated sizes that
### fit on the pegs. At the outset, all the disks are arranged pyrami-
### dally on one of the pegs, say A, with the largest disk on the bottom.
### The task is to move all of the disks to another peg, C, say, under
### the constraints that (1) only one disk may be moved at a time, and
### (2) a disk may never be placed on top of another smaller than itself.
### Any number of disks may be used; the minimum number of moves for
### a solution is (2**n - 1), where n is the number of disks" (Simon,
### 1975/1979, pp. 230-231).
###
### This version uses search control rules to solve the TOH in the
### minimum number of moves.
### The search control is as follows:
### Always alternate between moving the smallest disk and
### the other exposed disk that can move.
### Move the exposed disk to the one place it can move (the other disk
### that is bigger than it or an empty peg).
### Move the smallest disk to the peg it was not at last.
### This requires remembering the last peg the smallest disk was on,
### and initializing this to the appropriate peg (the destination peg
### if there is an even number of disks, and the other peg if there is
### an odd number of disks).
### These declaration help Soar reorder the conditions of the rules
max-elaborations 50000
multi-attributes on 3
multi-attributes peg 4
multi-attributes holds 10
#multi-attributes upper-disk
multi-attributes clear 3
learn --off
###
### TOWER-OF-HANOI:
### INITIAL-STATE AND DESIRED-STATE
###
sp {tower-of-hanoi*propose*state*initial-and-desired-states
"A 3-Disk Tower of Hanoi Problem."
(state ^superstate nil)
-->
( ^operator
^peg a b c
^holds
^last-disk1-peg b
^last-disk-moved 2
^clear b c)
( ^name doit)
( ^disk 1 ^above 2 ^on a)
( ^disk 2 ^above 3 ^on a)
( ^disk 3 ^above 4 ^on a)
( ^disk 4 ^above 5 ^on a)
( ^disk 5 ^above 6 ^on a)
( ^disk 6 ^above 7 ^on a)
( ^disk 7 ^above 8 ^on a)
( ^disk 8 ^above 9 ^on a)
( ^disk 9 ^above 10 ^on a)
( ^disk 10 ^above 11 ^on a)
( ^disk 11 ^above none ^on a)}
###
### PROPOSE OPERATORS TO MOVE DISKS
###
sp {tower-of-hanoi*move-disk1*source-clear*target-not-clear
(state ^operator.name doit
^holds
^upper-disk
^peg { <> <> }
^last-disk1-peg
^last-disk-moved {<> 1 })
( ^disk 1
^above none
^on )
( ^disk
^on )
-->
# (write (crlf) |Move 1 from | | to | )
( ^on -
^above none -)
( ^clear
^upper-disk -
^last-disk1-peg -
^last-disk-moved 1 -)}
sp {tower-of-hanoi*move-disk1*source-not-clear*target-clear
(state ^operator.name doit
^holds
^clear
^peg { <> <> }
^last-disk1-peg
^last-disk-moved {<> 1 })
( ^disk 1
^above
^on )
-->
# (write (crlf) |Move 1 from | | to | )
( ^on -
^above - none)
( ^clear -
^upper-disk
^last-disk1-peg -
^last-disk-moved 1 -)}
sp {tower-of-hanoi*move-disk1*source-not-clear*target-not-clear
(state ^operator.name doit
^holds
^upper-disk
^peg { <> <> }
^last-disk1-peg
^last-disk-moved {<> 1 })
( ^disk 1
^above { <> none }
^on )
( ^disk
^on )
-->
# (write (crlf) |Move 1 from | | to | )
( ^on -
^above -)
( ^upper-disk
^upper-disk -
^last-disk1-peg -
^last-disk-moved 1 -)}
###
sp {tower-of-hanoi*move-diskn*source-clear*target-clear
(state ^operator.name doit
^upper-disk
^holds
^clear
^last-disk-moved 1)
( ^disk { <> 1 }
^above none
^on )
-->
# (write (crlf) |Move | | from | | to | )
( ^on -)
( ^clear -
^last-disk-moved 1 -)}
sp {tower-of-hanoi*move-diskn*source-clear*target-not-clear
(state ^operator.name doit
^upper-disk
^holds
^upper-disk
^last-disk-moved 1)
( ^disk { <> 1 }
^above none
^on )
( ^disk { > }
^on )
-->
# (write (crlf) |Move | | from | | to | )
( ^on -
^above none -)
( ^clear
^upper-disk -
^last-disk-moved 1 -)}
sp {tower-of-hanoi*move-diskn*source-not-clear*target-clear
(state ^operator.name doit
^upper-disk
^holds
^clear
^last-disk-moved 1)
( ^disk { <> 1 }
^above { <> none }
^on )
-->
# (write (crlf) |Move | | from | | to | )
( ^on -
^above - none)
( ^clear -
^upper-disk
^last-disk-moved 1 -)}
sp {tower-of-hanoi*move-diskn*source-not-clear*target-not-clear
(state ^operator.name doit
^upper-disk
^upper-disk
^holds
^last-disk-moved 1)
( ^disk { <> 1 }
^above { <> none }
^on )
( ^disk { > }
^on { <> })
-->
# (write (crlf) |Move | | from | | to | )
( ^on -
^above -)
( ^upper-disk
^upper-disk -
^last-disk-moved 1 -)}
###
### TOWER-OF-HANOI GOAL-TEST
###
sp {tower-of-hanoi*desired-of-disk*satisfied
(state ^holds )
( ^disk 1 ^on c)
( ^disk 2 ^on c)
( ^disk 3 ^on c)
( ^disk 4 ^on c)
( ^disk 5 ^on c)
( ^disk 6 ^on c)
( ^disk 7 ^on c)
( ^disk 8 ^on c)
( ^disk 9 ^on c)
( ^disk 10 ^on c)
( ^disk 11 ^on c)
-->
(write (crlf) |Success!|)
(halt)}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy