我正在尝试为BDI代理编写一个程序,该代理在网格目标中移动。目标定义为其网格位置和权重作为目标(X,Y,S)。每个感知到的目标将按其权重的降序插入到意图列表中。如果目标已经在列表中,则应该忽略它。
我到目前为止的代码如下:
incorporate_goals([], _, Intentions, Intentions).
incorporate_goals([Goal|Tail], Beliefs, Intentions, Intentions1) :-
member(Goal, Intentions),
!,
incorporate_goals(Tail, Beliefs, Intentions, Intentions1).
incorporate_goals([Goal|Tail], Beliefs, Intentions, Intentions1) :-
not(member(Goal, Intentions)),
insert_goal(Goal, Intentions, Beliefs, Intentions_updated),
incorporate_goals(Tail, Beliefs, Intentions_updated, Intentions1).
insert_goal(Goal, Intentions, _, [[Goal, []]|Intentions]).
insert_goal(Goal, [H|Intentions], Beliefs, [Goal,H|Intentions1]) :-
eval(Goal, H, Beliefs).
insert_goal(Goal, [H|Intentions], Beliefs, [Goal,H|Intentions1]) :-
not(eval(Goal,H,Beliefs)),
insert_goal(Goal, [Intentions], Beliefs, [Intentions1]).
eval(goal(_,_,S1), goal(_,_,S2), _) :-
S1 > S2,
!.
eval(goal(X1,Y1,S1), goal(X2,Y2,S2), [at(X,Y)]) :-
S1 == S2,
distance((X,Y), (X1,Y1), D1),
distance((X,Y), (X2,Y2), D2),
D1 < D2.
我的问题是:
成员/ 2未正确检测到相同的目标
目标只是插入到列表的头部而不是按降序排列。
我现在已经坚持了很长一段时间。如果你能指出错误,我将非常感激。