each dot picks one friend and one enemy, then every tick takes a fixed-size step toward the friend and away from the enemy — direction matters, distance doesn't.
try crank enemy step above friend step and the swarm shatters into fleeing knots — drop it back down and clumps of friends pull themselves back together.