% Towers of Hanoi

% This version treats disks like blocks in
% the block world

% There are three pegs, and n disks
% which are stacked onto the pegs

% The disks are all of different sizes
% A disk may only have smaller disks on top
% of it

include "../library-ontology"
include "../library"

sorts
  Disk;

inclusions
  Disk << Thing;

module TOWERS_OF_HANOI;

  % This module captures info about moving the disks
  % onto pegs
  import MOUNT;

  objects
    Peg1, Peg2, Peg3:  Supporter;
    Disk1, Disk2, Disk3 : Disk;
     	
  fluents
    smaller(Disk, Disk) : rigid;

  variables
     d, d1, d2: Disk;
     s:         Supporter;

  axioms
    smaller(Disk1, Disk2);
    smaller(Disk2, Disk3);
    default -smaller(d, d1);

    % Two disks cannot be directly on top of the same supporter
    constraint Support(d)=Support(d1) -> d=d1;

    % We can only move disks which are clear (not under others)
    nonexecutable Mount(d,s) if Support(d1)=d;

    % A disk cannot be moved onto a disk being moved also
    nonexecutable Mount(d,d1) & Mount(d1,s);

    % A disk can only have a smaller disk on top of it
    constraint Support(d)=d1 -> (smaller(d, d1));
