0
votes

Like the answer in How to define simple rule in prolog i define the following programm:

should(X, go_to(X, toilet)) :- full_bladder(X).

?- assert(full_bladder(bob)).
true.
?- should(bob, Action).
Action = go_to(bob, toilet)

I add now the facts:

?- assert(lastlocation(bob, floor)).
true.
?- assert(currentlocation(bob, toilet)).
true.
?- assert(empty_bladder(bob)).
true.

How can I now define the rule for:

"when currentlocation is toilet and empty_bladder then go to lastlocation"

This rule should ensure that for the following question

?- should(bob, Action).

the result should be

Action = go_to(bob, floor).

I hope, someone can help me, how to define the rule.

1

1 Answers

0
votes

You could define the rule:

should(X, go_to(X, floor)) :- empty_bladder(X),currentlocation(X, toilet).

The above says: if clause empty_bladder(X) exists and also currentlocation(X, toilet) then return as second parameter go_to(X, floor).