在序言中比较 [英] comparing in prolog

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

问题描述

我有以下知识库

team_name(1, conneticut).
team_name(2, duke).
team_name(3, memphis).
team_name(4, villanova).
team_name(5,gonzaga).

win_lose(1,22,2).
win_lose(2,24,1).
win_lose(3,23,2).
win_lose(4,20,2).
win_lose(5,21,3).

zone(west,5).
zone(south,3).
zone(east,1).
zone(east,2).
zone(east,4).

我想写一个查询,让边路最多的球队与胜利最少的球队比赛,他们都在同一个区域,主队是获胜最多的球队

I want to write a query that allows the team with most wing play against the team with the least wins, which both are in the same zone, and the home team is the one with most wins

我有以下内容

canPlay(X,Y).                 Y can play X
canPlay(X,Y):-zone(zone(X)=:=Y).        Y can play X, if Y zone == X

它不起作用.

推荐答案

我认为这应该符合您的要求

I think this should fit your requirements

canPlay(Home, Guest) :-
    % get different Zones
    setof(Zone, Team^zone(Zone, Team), Zones),

    % in a Zone
    member(Zone, Zones),

    % get ordered list
    setof(Win-Team, Lost^(zone(Zone, Team), win_lose(Team, Win, Lost)), Standings),

    % take first and last
    append([[_-HomeId],_,[_-GuestId]], Standings),

    team_name(HomeId, Home),
    team_name(GuestId, Guest).

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

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