I'm doing a prolog program for college that is a bit like the cluedo game. I have six suspects with different traits:
suspect(Name, Age, Weapon, Shape, Object, Shoes)
The goal is to implement a series of clues so that the program says which the different traits of all the six suspects. For example:
suspect(Hannibal Lecter,67,knife,'in good shape',mac,'high heels')
I'm having problems trying to implement the clue
or(suspect1, suspect2, suspect3, listOfSuspects)
This clue is supposed to say that the suspect1
has the same traits as suspect2
OR as suspect3
but not both. Example: To indicate that the suspect who is 50 years old has a ring or a mac, but not both:
or(suspect(_, 50, _, _, _, _),
suspect(_, _, _, _, ring, _),
suspect(_, _, _, _, mac, _), listOfSuspects).
Any help would be appreciated.
Here are some hints. You can state that
Suspect1
has the same traits asSuspect2
just bySuspect1 = Suspect2
, and to find out whether any member of a listSuspects
has the traits ofSuspect1
bymember(Suspect1, Suspects)
.The usual way of handling a disjunction in Prolog is by introducing a predicate with two clauses. E.g., a predicate that checks whether a suspect has either a ring or a mac is
If you put these hints together in the right way, you have a solution to your problem.