%%% DOMAIN PREDICATES time(1..n). place(left;right;boat). object(man;goat;cabbage;wolf). %%% INITIAL STATE on(1,goat,left). on(1,cabbage,left). on(1,wolf,left). on(1,man,left). %%% IF (goat and cabbage) OR (goat and wolf) are in place P, %%% THEN the man is in P on(T,man,P) :- on(T,goat,P), on(T,cabbage,P), time(T), place(P). on(T,man,P) :- on(T,goat,P), on(T,wolf,P), time(T), place(P). %%% In any time, any object is exactly in one place. 1 { on(T,O,P) : place(P) } 1 :- time(T), object(O). %%% Boat effect (it is important where the motion has started) on(T+2,O,right):- on(T+1,O,boat), on(T,O,left), time(T), object(O). on(T+2,O,left) :- on(T+1,O,boat), on(T,O,right), time(T), object(O). %%% IF someone is in boat, then the man must be on boat. on(T,man,boat) :- on(T,O,boat), time(T), object(O). %%% The boat constains from 0 to 2 objects 0 { on(T,O,boat) : object(O) } 2 :- time(T). %%% INERTIA rules :- on(T+1,O,left), on(T,O,right), time(T), object(O). :- on(T+1,O,right), on(T,O,left), time(T), object(O). %%% OPPURE: final :- on(n,goat,right), on(n,cabbage,right), on(n,wolf,right), on(n,man,right). :- not final. #hide. #show on(X,Y,Z).