1

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?

false
  • 10,264
  • 13
  • 101
  • 209
Marcin Majewski
  • 1,007
  • 1
  • 15
  • 30

1 Answers1

2

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.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • 1
    Many thanks, much cleaner than excluding etc. I kind of tried to do it like this but sth was not right, anyway it works now ! – Marcin Majewski Nov 13 '19 at 18:39