Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

list - "Or" procedure in prolog

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are some hints. You can state that Suspect1 has the same traits as Suspect2 just by Suspect1 = Suspect2, and to find out whether any member of a list Suspects has the traits of Suspect1 by member(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

ring_or_mac(suspect(_, _, _, _, ring, _)).
ring_or_mac(suspect(_, _, _, _, mac, _)).

If you put these hints together in the right way, you have a solution to your problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...