Tower of Hanoi

role(player).
init(on(disc5, pillar1)).
init(on(disc4, disc5)).
init(on(disc3, disc4)).
init(on(disc2, disc3)).
init(on(disc1, disc2)).
init(clear(disc1)).
init(clear(pillar2)).
init(clear(pillar3)).
init(step(s0)).
legal(player, puton(X, Y)) :- true(clear(X)), true(clear(Y)), smallerdisc(X, Y).
next(step(Y)) :- true(step(X)), successor(X, Y).
next(on(X, Y)) :- does(player, puton(X, Y)).
next(on(X, Y)) :- true(on(X, Y)), \+(put_on_any(X)).
next(clear(Y)) :- true(on(X, Y)), put_on_any(X).
next(clear(Y)) :- true(clear(Y)), \+(put_any_on(Y)).
put_on_any(X) :- does(player, puton(X, _Y)).
put_any_on(Y) :- does(player, puton(_X, Y)).
goal(player, 100) :- tower(pillar3, s5).
goal(player, 80) :- tower(pillar3, s4).
goal(player, 60) :- tower(pillar3, s3).
goal(player, 40) :- tower(pillar3, s2).
goal(player, 0) :- tower(pillar3, Height), smaller(Height, s2).
terminal :- true(step(s31)).
tower(X, s0) :- true(clear(X)).
tower(X, Height) :- true(on(Y, X)), disc_or_pillar(Y), tower(Y, Height1), successor(Height1, Height).
pillar(pillar1).
pillar(pillar2).
pillar(pillar3).
nextsize(disc1, disc2).
nextsize(disc2, disc3).
nextsize(disc3, disc4).
nextsize(disc4, disc5).
nextsize(disc5, Pillar) :- pillar(Pillar).
disc_or_pillar(disc1).
disc_or_pillar(disc2).
disc_or_pillar(disc3).
disc_or_pillar(disc4).
disc_or_pillar(disc5).
disc_or_pillar(P) :- pillar(P).
smallerdisc(A, B) :- nextsize(A, B).
smallerdisc(A, B) :- nextsize(A, C), smallerdisc(C, B).
successor(s0, s1).
successor(s1, s2).
successor(s2, s3).
successor(s3, s4).
successor(s4, s5).
successor(s5, s6).
successor(s6, s7).
successor(s7, s8).
successor(s8, s9).
successor(s9, s10).
successor(s10, s11).
successor(s11, s12).
successor(s12, s13).
successor(s13, s14).
successor(s14, s15).
successor(s15, s16).
successor(s16, s17).
successor(s17, s18).
successor(s18, s19).
successor(s19, s20).
successor(s20, s21).
successor(s21, s22).
successor(s22, s23).
successor(s23, s24).
successor(s24, s25).
successor(s25, s26).
successor(s26, s27).
successor(s27, s28).
successor(s28, s29).
successor(s29, s30).
successor(s30, s31).
smaller(X, Y) :- successor(X, Y).
smaller(X, Y) :- successor(X, Z), smaller(Z, Y).