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

sorts
  Block;

inclusions
  Block << Thing;


module BLOCKS_WORLD;

  objects
    Robot: Thing;
    Table, Floor: Supporter;
    Block1, Block2, Block3: Block;

  actions
    PutDown(Block, Supporter);
    PickUp(Block);

  variables
    x: Thing;
    b, b1: Block;
    s: Supporter;

% The action PickUp is synonymous with library action Grasp 
% executed by the Robot
  import MOUNT;
    Mount(b,Robot) is PickUp(b);

% The action PutDown is synonymous with library action Mount
  import MOUNT;
    Mount(b,s) is PutDown(b,s);  

% The robot can only perform a putting down or a picking up at a time
  import NOCONCURRENCY;

  axioms
    % The robot is on the floor
    Support(Robot)=Floor;

    % Blocks cannot be on the floor
    constraint -Support(b)=Floor;

    % The robot cannot hold two blocks
    % and two blocks cannot be right on top of the same block
    constraint Support(b)=Support(b1) -> (Support(b)=Table | b=b1);

    % The robot cannot be holding a tower
    constraint -(Support(b)=Robot & Support(b1)=b);

    % The robot cannot put down a block it isn't holding
    nonexecutable PutDown(b,s) if -Support(b)=Robot;

    % The robot cannot pick up a block it is already holding
    nonexecutable PickUp(b) if Support(b)=Robot;
