Prolog – Rules are correct, but not outputting the way it’s supposed to?
Four guests (Colonel Mustard, Professor Plum, Miss Scarlett, Ms. Green) attend a dinner party at the home of Mr. Boddy. Suddenly, the lights go out! When they come back, Mr Boddy lies dead in the middle of the table. Everyone is a suspect. Upon further examination, the following facts come to light:
There are two possible motives for the murder:
Part A: Write the above facts and rules in your Prolog program. Use the following names for the people: colMustard, profPlum, missScarlet, msGreen, mrBoddy. Be careful about how you encode (or don’t encode) symmetric relationships like marriage – you don’t want infinite loops!
Part B: Write a predicate, suspect/2, that determines who the suspects may be, i.e. who had a motive.
Part C: Add a single factto your database that will result in there being a unique suspect.
Whenever I type in
Here’s my source.
The problem is the recursive rules of the predicates
To better understand why you get an endless loop, use the trace facilities of your Prolog system. Try:
and go step by step.