Help flushing out idea for detecting friend from foe [closed]

I need help with flushing out an idea into a game mechanic. There is a goal and there are friendly npcs and enemies. Both are walking toward the goal. However, the player can’t tell friend from foe.

The goal is to have the player detect and eliminate the enemies before they reach the goal. I mostly need help with detection. Most examples and ideas I see are for ai detecting the player and not the other way around.

What are some ways, examples, or ideas I can use to implement this sort of mechanic?