How to Write a predicate solution(X)/1 that gives an answer to the farmer/wolf/goat/cabbage
Author Message
How to Write a predicate solution(X)/1 that gives an answer to the farmer/wolf/goat/cabbage

I want to write a predicate solution(X)/1 that gives an answer to the
farmer/wolf/goat/cabbage problem i've
(with the help of a Book)already written a solution
but i don't know how to write a solution(X) predicate
where X is a list of position that gives a solution to the
problem
exmple:
solution(X).
X=[position()......]
yes
solution([position()....]).
yes
move(position(X,X,G,C), position(Y,Y,G,C))
:- opp(X,Y), not(unsafe(position(Y,Y,G,C))). % move
Boer+Wolf

move(position(X,W,X,C), position(Y,W,Y,C))
:- opp(X,Y), not(unsafe(position(Y,W,Y,C))). % move
Boer+Geit

move(position(X,W,G,X), position(Y,W,G,Y))
:- opp(X,Y), not(unsafe(position(Y,W,G,Y))). % move
Boer+Hooi

move(position(X,W,G,C), position(Y,W,G,C))
:- opp(X,Y), not(unsafe(position(Y,W,G,C))). % move Boer

path(Z,Z,L) :- write('Solution Path Is:' ),nl,rpt(L).
path(X,Y,L) :- move(X,Z), not(member(Z,L)), path(Z,Y,[Z|L]).

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

rpt([]).
rpt([H|T]) :- rpt(T), write(H), nl.

opp(s,n).
opp(n,s).

unsafe(position(X,Y,Y,C)) :- opp(X,Y). % Wolf eats Geit
unsafe(position(X,W,Y,Y)) :- opp(X,Y). % Geiteats Hooi
--------------------------------------------------------------
is a  week that i try to understand something obout prolog ,so i'm one week
beginner ,but i'm completely
that .

Sun, 01 Jun 2003 06:06:24 GMT
How to Write a predicate solution(X)/1 that gives an answer to the farmer/wolf/goat/cabbage
[omitted]

First you yave to decide if you want to implement depth-first tree-search or
width-first tree-search algorithm.  (Or if you want to use an heuristic).  Look
for these topics in any AI or Prolog manual.  I think "width search" would be
better, but this is not the default mode in prolog.   Maybe you can find
examples in a book (or try looking at these terms in a Web search engine)

Good luck.

Sun, 22 Jun 2003 04:29:21 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages