Prolog知识查询

Prolog知识查询,prolog,Prolog,我得到了上面的数据库,但我没有复制所有人的条目,因为它太长了 我被要求知道任何一位副队长的姓氏,他的团队包括一位队长或一位专业为科学的普通队员 我可以使用下面的代码获得副队长的姓氏,但我不能只返回那些包括队长或专业为科学的常规队员的球队。要做到这一点,我需要补充什么 % A quiz team structure takes the form: % team(Captain, Vice_captain, Regular_team_members). % Captain and Vice_capt

我得到了上面的数据库,但我没有复制所有人的条目,因为它太长了

我被要求知道任何一位副队长的姓氏,他的团队包括一位队长或一位专业为科学的普通队员

我可以使用下面的代码获得副队长的姓氏,但我不能只返回那些包括队长或专业为科学的常规队员的球队。要做到这一点,我需要补充什么

% A quiz team structure takes the form:
% team(Captain, Vice_captain, Regular_team_members).
% Captain and Vice_captain are player structures;
% Regular_team_members is a list of player structures.
% player structures take the form:
% player(First_name, Surname, details(Speciality,Recent_score)).

team(player(niall,elliott,details(history,11)),
     player(michelle,cartwright,details(fashion,19)),
          [player(peter,lawlor,details(science,12)),
          player(louise,boyle,details(current_affairs,17))]).
我还被要求知道任何一名队长的名字和姓氏,他的正式队员不止一名,而且都有相同的姓氏

这是我迄今为止的尝试:

part_two(Surname):-
    team(_,player(_,Surname,_),_).

我只需要排除那些队长的细节,他们的正式队员不是都有相同的姓氏

您可以对已经编写的内容进行一些更改,如下所示:

part_three(First_name,Surname):-
    team(Captain,_,Regular_team_members),
    first_name(Captain,First_name),
    surname(Captain,Surname),
    Regular_team_members=[_,_|_].
例如:

数据库:

 part_two(Surname):-
    team(P,player(_,Surname,_),L), 
    ( P=player(_,_,details(science,_)) -> true ; member(player(_,_,details(science,_)),L) ).
现在查询:

team(player(niall,elliott,details(history,11)),
     player(michelle,cartwright,details(fashion,19)),
          [player(peter,lawlor,details(history,12)),
          player(louise,boyle,details(current_affairs,17))]).


team(player(niall1,elliott1,details(science,11)),
     player(michelle1,cartwright1,details(fashion,19)),
          [player(peter,lawlor,details(history,12)),
          player(louise,boyle,details(current_affairs,17))]).

team(player(niall2,elliott2,details(history,11)),
     player(michelle2,cartwright2,details(fashion,19)),
          [player(peter,lawlor,details(science,12)),
          player(louise,boyle,details(current_affairs,17))]).



 team(player(niall3,elliott3,details(science,11)),
     player(michelle3,cartwright3,details(fashion,19)),
          [player(peter,lawlor,details(science,12)),
          player(louise,boyle,details(current_affairs,17))]).

您可以对已经编写的内容进行一些更改,如下所示:

part_three(First_name,Surname):-
    team(Captain,_,Regular_team_members),
    first_name(Captain,First_name),
    surname(Captain,Surname),
    Regular_team_members=[_,_|_].
例如:

数据库:

 part_two(Surname):-
    team(P,player(_,Surname,_),L), 
    ( P=player(_,_,details(science,_)) -> true ; member(player(_,_,details(science,_)),L) ).
现在查询:

team(player(niall,elliott,details(history,11)),
     player(michelle,cartwright,details(fashion,19)),
          [player(peter,lawlor,details(history,12)),
          player(louise,boyle,details(current_affairs,17))]).


team(player(niall1,elliott1,details(science,11)),
     player(michelle1,cartwright1,details(fashion,19)),
          [player(peter,lawlor,details(history,12)),
          player(louise,boyle,details(current_affairs,17))]).

team(player(niall2,elliott2,details(history,11)),
     player(michelle2,cartwright2,details(fashion,19)),
          [player(peter,lawlor,details(science,12)),
          player(louise,boyle,details(current_affairs,17))]).



 team(player(niall3,elliott3,details(science,11)),
     player(michelle3,cartwright3,details(fashion,19)),
          [player(peter,lawlor,details(science,12)),
          player(louise,boyle,details(current_affairs,17))]).
因为你无论如何都要扫描常规团队成员列表,寻找合适的约束条件,你可以得到一个更简单的“程序”,首先将队长“加入”到其他球员中


因为你无论如何都要扫描常规团队成员列表,寻找合适的约束条件,你可以得到一个更简单的“程序”,首先将队长“加入”到其他球员中。

如果团队中的前两名是队长和副队长,一个团队怎么可能没有队长?@BitTickler我只是跳过了队长的详细信息,因为我只需要副队长的详细信息。如果一个团队的前两名是队长和副队长,“一个团队怎么可能没有队长?”BitTickler我只是跳过了队长的细节,因为我只需要副队长的细节。你的解决方案非常有效。对于其他问题,您使用访问器的方法肯定会派上用场。非常感谢!我在上面贴了第二个问题。你能帮我完成吗?你可以使用…,常规团队成员=[[uuu,[uu124; uu],setofS,memberP,常规团队成员,姓氏p,S,[[uu]你的解决方案非常有效。对于其他问题,您使用访问器的方法肯定会派上用场。非常感谢!我在上面贴了第二个问题。你能帮我完成吗?你可以用…,普通团队成员=[[uuu,[uu124; uu],setofS,memberP,普通团队成员,姓氏,S,[[uu]我在上面贴了第二个问题。你认为你能帮我完成最后一部分吗?是的,但是如果你把它作为一个单独的问题问会更好。最好在单独的问题中提问,因为对于其他有类似问题的人来说,理解你的问题会很有帮助,也不会让人感到困惑……我已经在上面发布了第二个问题。你认为你能帮我完成最后一部分吗?是的,但是如果你把它作为一个单独的问题问会更好。最好在单独的问题中提问,因为对于其他有类似问题的人来说,理解你的问题会很有帮助,也不会让人感到困惑。。。