%% entitysandobjects(a,[[a,1],[a,2],[b,1]],Objects). %% Objects = [1,2]; %% entitysandobjects(Entity,EntitysAndObjects,Objects) %% List the objects that an entity has interacted with %% Entity - the entity which has interacted with the objects to find %% EntitysAndObjects - the list of pairs of an entity and an object that entity has interacted with %% Objects - the list of objects the entity has interacted with entitysandobjects(Entity,EntitysAndObjects,Objects) :- entitysandobjects1(Entity,EntitysAndObjects,[],Objects). %% entitysandobjects1(Entity,EntitysAndObjects,Objects1,Objects2) %% Lists objects that an entity has interacted with %% Entity - the entity which has interacted with the objects, which we will find%% EntitysAndObjects - the list of pairs of an entity and an object that entity has interacted with %% Objects1 - the list of objects the entity has interacted with %% Objects2 - the list of objects the entity has interacted with, which we will return entitysandobjects1(_,[],Objects,Objects). entitysandobjects1(Entity,[[Entity,Object]|EntitysAndObjects],Objects1,Objects2) :- append(Objects1,[Object],Objects3), entitysandobjects1(Entity,EntitysAndObjects,Objects3,Objects2). entitysandobjects1(Entity,[[OtherEntity,_]|EntitysAndObjects],Objects1,Objects2) :- not(Entity=OtherEntity), entitysandobjects1(Entity,EntitysAndObjects,Objects1,Objects2).