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
lost about this predicate ,maybe is Simple but just i'don't see how to write
that .
Thanks in advance!



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  
 
 [ 2 post ] 

 Relevant Pages 

1. Farmer, Cabbage, Goat & Wolf Problem

2. newbie debugging farmer-goat-cabbage-wolf-puzzle

3. testing all the solutions of a question-predicate

4. Arithmetic gives wrong answer.

5. LOGO-L> predicate writing

6. Can Any one give the answer ?

7. please give me answers

8. "Attn: Frequently Given Answers (Read Me First)

9. Common statement does not work with gfortran, but g95 gives the correct answer

10. Farmer, Cabbage, Goat & Wolf Problem - sorry if posted twice

11. How to write predicate for ancestor

12. How to write predicate for ancestor

 

 
Powered by phpBB® Forum Software