Monkey and Banana Problem.......endless loop? 
Author Message
 Monkey and Banana Problem.......endless loop?

Good Day Folks,

tryin to modify the monkey/banana problem so that it is more descriptive
than just YES or NO.

however.......it goes into an infinite loop

could somebody point out where i am goin wrong...
i realize that the order of the "move" clauses are important to stop the
infinite loop prob...but i cannot see what i have wrong

tia
Barry

% goal = canget(state(atdoor, onfloor, atwindow, hasnot)).

%Monkey and Banana Problem.
%move(State1, Move, State2): making Move in State1 results in State2;
% a state is represented by term:
% state(MonkeyHorizontal, MonkeyVertical, BoxPosition, HasBanana)

move(state(middle,onbox,middle,hasnot),       %Before move
     grasp,
    nl,write('Monkey is Grasping the Banana'),nl,    %Grasp Banana
     state(middle,onbox,middle,has)).       %After move

move(state(P,onfloor,P,H),          %climb box
     climb,
     nl,write('Monkey is Climbing on Box'),nl,
     state(P,onbox,P,H)).

move(state(P1,onfloor,P1,H),         %push box from P1 to P2
     push(P1,P2),
     nl,write('Monkey is moving Box '),write(P1),write(' to '),
     write(P2),nl,
     state(P2,onfloor,P2,H)).

move(state(P1,onfloor,B,H),          %walk from P1 to P2
     walk(P1,P2),
     nl,write('Monkey is walking from '),write(P1),write(' to '),
     write(B),nl,
     state(P2,onfloor,B,H)).

%canget(State): monkey can get banana in State

canget(state(_,_,_, has),nl,write('got it!!!')).    %can 1: Monkey already
has it

canget(State1) :-            %can 2: Do some work to get it
 move(State1, Act, State2),nl,        %Do something
 write('Monkey is '),write(Act),write('ing.'),nl,
 canget(State2).            %Get it now



Mon, 27 Jun 2005 00:16:46 GMT  
 Monkey and Banana Problem.......endless loop?

Quote:

> Good Day Folks,

> tryin to modify the monkey/banana problem so that it is more descriptive
> than just YES or NO.

> however.......it goes into an infinite loop

> could somebody point out where i am goin wrong...
> i realize that the order of the "move" clauses are important to stop the
> infinite loop prob...but i cannot see what i have wrong

you forgot to tell us the query
if I do ?- canget(X).
I get

Calling an unknown predicate: move / 3 move(_462,_487,_486) in_module(user)

seems like all your move/n facts have an arity different from 3 (two of them have arity 6,
the other 2 have arity 9)

I can't see this could loop - it just doesn't execute at all

but in case you eventually get the arities of move right - fix the arity of canget and you are set

Cheers

Bart Demoen



Mon, 27 Jun 2005 01:22:23 GMT  
 Monkey and Banana Problem.......endless loop?

Quote:

> Good Day Folks,

> tryin to modify the monkey/banana problem so that it is more descriptive
> than just YES or NO.

> however.......it goes into an infinite loop

> could somebody point out where i am goin wrong...
> i realize that the order of the "move" clauses are important to stop the
> infinite loop prob...but i cannot see what i have wrong

> tia
> Barry

> % goal = canget(state(atdoor, onfloor, atwindow, hasnot)).

> %Monkey and Banana Problem.
> %move(State1, Move, State2): making Move in State1 results in State2;
> % a state is represented by term:
> % state(MonkeyHorizontal, MonkeyVertical, BoxPosition, HasBanana)

> move(state(middle,onbox,middle,hasnot),       %Before move
>      grasp,
>     nl,write('Monkey is Grasping the Banana'),nl,    %Grasp Banana
>      state(middle,onbox,middle,has)).       %After move

I think you're looking for something like:

move( state(...), grasp, state(...) ) :-
        nl, write(...), nl.

and the same applies for canget/1

--
Matthew Purver - matt at purver dot org



Mon, 27 Jun 2005 01:29:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. MAC VM has endless loop on startup

2. Range filter in endless loop

3. ENDLESS LOOP HELP

4. an endless loop.

5. Interrupting endless loop - how?

6. URGENT! [VWNC] Hung in Endless Loop

7. endless loop..what did I do wrong???

8. Endless Loop

9. Q: Endless loop by dispatching

10. Asserts / Endless loops

11. exit endless python loop in emacs

12. Wish and Endless loops

 

 
Powered by phpBB® Forum Software