Fitltering in findall

31 views Asked by At

I have rule:

best_fit(Team, Enemies, Result, List) :-
    findall((H, E), score(H, Enemies, Team, E), List),

where score definition is:

score(Hero, Enemies, Team, Result) :- 
   hero(Hero),
...

I would like to find only that (H,E) where H is not in Enemies or Team. I tried to later exclude but the results are tuples and it is kind of complicated to make it work. Is there a way to filter it out in findall method? How can I approach this?

1

There are 1 answers

1
willeM_ Van Onsem On

You can enforce that in the goal:

best_fit(Team, Enemies, Result, List) :-
    findall((H, E), (
        score(H, Enemies, Team, E),
        \+ member(H, Enemies),
        \+ member(H, Team),
    ), List).

So here we modified the goal such that it is satisfied if score(H, Enemies, Team, E) and H is not a member of Enemies, and H is not a member of Team.