again over F/W/G/C Problem i need some help..
Author Message
again over F/W/G/C Problem i need some help..

I have written (with the help of a book) a solution to farmer/wolf/....
problem i hve to write a predicate
solve(X)/1 where X is a list of position that solves the problem and if Call
Solve(X) the answer is simply the solution but i dont know how to do that.
Would you be so kind to give the solution of/and an Hint over how to solve
this problem ,of i have to change  all the code ???
-----------------------------------------------------------------
The code :..path(position(n,n,n,n),position(s,s,s,s),[position(s,s,s,s)]).
gives the answare but is /3 predicate
how can i add a new /1 predicate ???
maybe with (asserta) ????
----------------------------------------------------------------
% move/2

move(position(X,X,G,C), position(Y,Y,G,C))           % Farmer+Wolf
:- opposite(X,Y),
not(unsafe(position(Y,Y,G,C))). % Test is not unsafe

move(positie(X,W,X,C), position(Y,W,Y,C))
%  Farmer+Goat
:- opposite(X,Y),
not(unsafe(position(Y,W,Y,C))). % Test is not unsafe

move(positie(X,W,G,X), positie(Y,W,G,Y))           % Farmer+Cabbage
:- opposite(X,Y),
not(unsafe(position(Y,W,G,Y))).%Test is not unsafe

move(positie(X,W,G,C), positie(Y,W,G,C))           % Farmer
:- opposite(X,Y),
not(unsafe(position(Y,W,G,C))). % Test is not unsafe

path(FirstNextPosition,FirstNextPosition,Stack) :-
% Final position
write('Solution Path Is:' ),nl,reverse(Stack).

path(StartPositie,EindPositie,Stack) :-
move(StartPositie,FirstNextPosition), %Find a move
not(member(FirstNextPosition,Stack)), %

path(FirstNextPosition,EindPositie,[FirstNextPosition|Stack]),!.

% member/2
member(X,[X|T]).
member(X,[Y|T]) :- member(X,T).

% reverse/1
reverse([]).
reverse([H|T]) :- reverse(T), write(H), nl.

% opposite structure
opposite(s,n).
opposite(n,s).

unsafe(position(X,Y,Y,C)) :- opposite(X,Y).
% Wolf eats  Goat
unsafe(position(X,W,Y,Y)) :- opposite(X,Y).
% Goat eats Cabbage

Mon, 02 Jun 2003 09:52:17 GMT

 Page 1 of 1 [ 1 post ]

Relevant Pages