Essentially, if they see any ant they will go to its nest. Regardless of which nest is closer, even when they are inside a nest. I don't think it was intended for this to happen like it happened here. What might be best is for the enemies to set their target only once. Once they have a target nest they would not change it, making it impossible for them to do things that cannot be reacted to like what happened here.