More connection predicates


next up previous
Next: Recursion
Up: An Adventure world (PPPE)
Previous: Prolog is not logic
Back: to main list of student notes

More connection predicates

Now define a predicate that begins

    is_two_from( Cave1, Cave2 ) :-
and which is true if there is one cave between Cave1 and Cave2, thus:
     -------     ------     -------
     !Cave1!-----!    !-----!Cave2!
     -------     ------     -------

Does your definition allow a cave to be two from itself? Why? What needs to be done to stop it happening?

Now, do the same for

    is_three_from( Cave1, Cave2 ) :-
There are two ways of doing this. One uses is_two_from after the if; one does not. Try them both.

Finally, define a predicate

    is_near( Cave1, Cave2 ) :-
which is true if the caves are adjacent, or two apart, or three apart. You will certainly need more than one clause for this.


next up previous
Next: Recursion
Up: An Adventure world (PPPE)
Previous: Prolog is not logic
Back: to main list of student notes



Jocelyn Paine
Tue Jun 4 17:55:54 BST 1996