
%   File   : MANDC
%   Author : Paul Brna
%   Updated: 23 September 2004 by Tim Smith
%   Purpose: Missionaries and Cannibals by Lawrence Byrd

?- use_module(library(random)).

go:-
	gofrom([3,3,1], [0,0,0], [[3,3,1]]).

gofrom([0,0,0], [3,3,1],_).

gofrom(Left, Right, PreviousLeftStates):-
        applymove(Left, Right, Direction, Comment, NewLeft, NewRight),
        safe(NewLeft),
        safe(NewRight),
        \+member(NewLeft, PreviousLeftStates),
        gofrom(NewLeft, NewRight,[NewLeft|PreviousLeftStates]),
	write(NewLeft), write(Direction), write(NewRight), write(' '), write(Comment), nl.

applymove(Left, Right, '-->', Comment, NewLeft, NewRight):-
        boathere(Left),
        moveload(Left, Right, Comment, NewLeft, NewRight).

applymove(Left, Right, '<--', Comment, NewLeft, NewRight):-
        boathere(Right),
        moveload(Right, Left, Comment, NewRight, NewLeft).

boathere([_,_,1]).

moveload(Source, Target, Comment, NewSource, NewTarget):-
        move(BoatLoad,Comment),
        possibletomove(Source, BoatLoad),
        performthemove(Source, Target, BoatLoad, NewSource, NewTarget).

/* these are the utilities */

member(X,[X|_]).
member(X,[_|Z]):-member(X,Z).

append([],L,L).
append([H|L1],L2,[H|L3]):-append(L1,L2,L3).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Add move/1 here:

move([1,1,1],'Move 1 Cannibal and 1 Missionary.').







%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add possibletomove/2 here:







%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add performthemove/5 here:












 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add safe/1 here:









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [Optional] If you want to try to implement a 
% different search strategy include your new
% predicates here:

% You may also need to modify the code provided.
