%--------------------------------------------------------------%
%   The farmer, wolf, cabbage and goat domain (Sicstus Prolog) %
%   (C) 1998 Zdravko Markov                                    %
%--------------------------------------------------------------%

change_state(s,W,G,C,n,W,G,C).
change_state(n,W,G,C,s,W,G,C).
change_state(s,s,G,C,n,n,G,C).
change_state(n,n,G,C,s,s,G,C).
change_state(s,W,s,C,n,W,n,C).
change_state(n,W,n,C,s,W,s,C).
change_state(s,W,G,s,n,W,G,n).
change_state(n,W,G,n,s,W,G,s).

illegal(s,n,n,_).
illegal(n,s,s,_).
illegal(s,_,n,n).
illegal(n,_,s,s).

% A solution without lists
solve(s,s,s,s).
solve(B,W,G,C) :-
    change_state(B,W,G,C,B1,W1,G1,C1),
    \+ illegal(B1,W1,G1,C1),
    \+ clause(passed(B1,W1,G1,C1),_),
    assertz(passed(B1,W1,G1,C1)),
    solve(B1,W1,G1,C1).
