“或"序言中的过程 [英] "Or" procedure in prolog

查看:17
本文介绍了“或"序言中的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为大学做一个序言程序,有点像线索游戏.我有六个具有不同特征的嫌疑人:

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)

这条线索应该是说 suspect1 具有与 suspect2suspect3 相同的特征,但不是两者兼而有之.示例:表示 50 岁的嫌疑人有戒指或 mac,但不是两者都有:

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).

任何帮助将不胜感激.

推荐答案

这里有一些提示.您可以通过 Suspect1 = Suspect2 声明 Suspect1Suspect2 具有相同的特征,并找出列表中是否有任何成员 Suspect 具有 member(Suspect1, Suspects)Suspect1 的特征.

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).

在 Prolog 中处理析取的常用方法是引入一个带有两个子句的谓词.例如,检查嫌疑人是否有戒指或 mac 的谓词是

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.

这篇关于“或"序言中的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆