对象与拥有它们的人一起移动的 Prolog 规则
Prolog rule for objects moving with people who have them
如果我有以下 Prolog 事实:
person(mary).
object(ball).
location(bedroom).
location(bathroom).
这个子句:
go(mary,bedroom).
get(mary,ball).
go(mary,bathroom).
我需要一条规则来表明球在 "mary." 中移动 如果被查询,Prolog 应该回复球在浴室里。我尝试了以下规则,但没有用:
has(X,Y) :- get(X,Y).
whereIs(P,R) :- has(P,Q),go(P,R).
什么是更好的规则集来表达拥有物品和前往不同房间之间的这种关系?
以下作品:
person(mary).
object(ball).
location(bedroom).
location(bathroom).
go(mary,bedroom).
get(mary,ball).
go(mary,bathroom).
whereIs(R) :- findall(R,(get(P,Q),go(P,R)),L), last(L,R),!.
根据命令:
?- whereIs(R).
R = [bathroom].
基本上,你想找到持球人的所有位置,然后确定最后一个位置。
我删除了 has(),因为它与 get() 基本相同。
如果我有以下 Prolog 事实:
person(mary).
object(ball).
location(bedroom).
location(bathroom).
这个子句:
go(mary,bedroom).
get(mary,ball).
go(mary,bathroom).
我需要一条规则来表明球在 "mary." 中移动 如果被查询,Prolog 应该回复球在浴室里。我尝试了以下规则,但没有用:
has(X,Y) :- get(X,Y).
whereIs(P,R) :- has(P,Q),go(P,R).
什么是更好的规则集来表达拥有物品和前往不同房间之间的这种关系?
以下作品:
person(mary).
object(ball).
location(bedroom).
location(bathroom).
go(mary,bedroom).
get(mary,ball).
go(mary,bathroom).
whereIs(R) :- findall(R,(get(P,Q),go(P,R)),L), last(L,R),!.
根据命令:
?- whereIs(R).
R = [bathroom].
基本上,你想找到持球人的所有位置,然后确定最后一个位置。
我删除了 has(),因为它与 get() 基本相同。