Well, it would not be hard to do... All you have to do is design an algorithm that is designed to solve itself. On one side, you have the current DPS and the likelihood that the ship will survive. On the other, you have maximum and likihood of death. Let's say the cobalt is at a range of 3000 so the DPS is 8.
I don't feel like explaining likelihood of death/life values, but it would be calculated by the number/DPS of nearby enemy ships and the number/health of allied ships.
So, it would look something like this:
So, you reduce some things and you get:
So, this way, the ship will adjust itself if the values are incorrect. Let's say that the ship is at a range of 3000 and has:
now, calculate... (.3*20)/.7=8.57
Now, just run that through a polynomial function (which I am too lazy to write out) and you will get a range.
Simply put, the higher the chance of living, the closer the ship gets. The lower, the farther away it goes.