% the call would be: % search(state(north, has(cabbage, goat,
wolf), has(nil, nil, nil)), % state(south, has(nil, nil, nil),
has(cabbage, goat, wolf)), R). % A state is represented by the
structure % state(BoatLocation,NorthContent,SouthContent) %
where the content on each shore is represented by %
has(Cabbage,Goat,Wolf). % Each of the parameters Cabbage, Goat,
and Wolf may be nil. % Pick something to move to the other shore
pick_object(X, has(A, B, C)) :- member(X, [A, B, C]), not(X =
nil). % Erases an object from a shore. del_object(cabbage,
has(A, B, C), has(nil, B, C)). del_object(goat, has(A, B, C),
has(A, nil, C)). del_object(wolf, has(A, B, C), has(A, B, nil)).
% Adds an object to a shore. add_object(cabbage, has(A, B, C),
has(cabbage, B, C)). add_object(goat, has(A, B, C),has(A, goat,
C)). add_object(wolf,has(A, B, C),has(A, B, wolf)). % Moving
around %from north to south first... move(state(north, X, Y),
state(south, R1, R2), moved(O, north, south)) :- pick_object(O,
X), add_object(O, Y, R2), del_obj