Move object closer to another object using python?
The near sensor has an attribute "Property". The sensor will filter the sensed objects by to have a property of the same name. 

So you are able to sense friends by giving them a property called "friend" and let the near sensor filter for "friend" too.

Do the same thing just with "enemy" to sense enemies.

To get the appropriate operation after detecting the near event you can use either the steering actuator (Flee, Seek, Path following), or you activate an TrackTo + Move forwards/backward. I'm sure there are more options.

Detecting a collision can be done via collision sensor. An object can end itself via Edit Actuator in End Object mode.