I just want to remind you that occam's razor as a principle of problem solving stands everywhere. The most complex of solutions are not better or best and this has been proven too many times to list an example. Also KISS is true to heart here.
There is no easy solution in AI. There are way too many parameters to track here. You are not done with just knowing where a missile crosses the path of a unit.
You need to account for collision sizes of units (what if a unit is surrounded? You still give it a move order in that case, causing it to do nothing while trying to reach the target?), the maps pathing (what if a cliff or wall of trees blocks the targeted point?) and also other gameplay factors (towers? Other players? You definitely don't want the unit to run into a direction that creates more problems than it solves).
The KISS principle has nothing to do with algorithm complexity. KISS is about usability.
Dodging missiles and travelling to cities have little in common, especially since cities remain static while missiles don't. Also the AI doesn't want to "visit" any cities or even care about cities far from its detection range. It only cares to dodge the missiles that wander too close.
It has very much in common. Creating a dodge AI is an optimization problem based on movement efficiency. But it's not only about finding the closest safe spot - it's also about planning ahead, otherwise your move order will lead this unit into sure death, even if that death isn't caused by another missile. The traveling salesman is very similar in this case in that you can not put a solution to an immediate problem out of context of the bigger scope. You must
think ahead.
So, yes, dodging
is an optimization problem, otherwise your AI will be predictable and exploitable.
That is why simpler AI systems usually work with
weighted randomness in which the weights shift according to external variables, of which the most basic (and easiest to track) would be:
- your health
- the health of enemies
- the position of enemies or friends not directly involved in the battle, but within proximity to assist
- the position of other external threats (creep camps, towers)
- expected damage of the missile
- expected gains you could have when
not dodging (killing an enemy vs. him escaping)
- immobilizing factors
- abilities of the enemy
These weighting factors could trigger a number of behaviours, of which the most common would be:
- take the hit
- dodge a missile moving sideways
- dodge a missile with the closest possible secure spot
- fall back (towards the location of nearby friendlies)
- move closer to the target
I recommend starting with this. Actually, I take back what I said: with weighted randomness and all the above parameters and the possible behaviours, it seems very possible to code something like that.
For example, your script could look like this:
- Have all 5 behaviours the same base weight and pick the decision at random
- If your health is significantly higher than that of the enemy, shift the weight towards moving closer and/or taking the hit.
- If the expected damage would be lethal, shift the weight of "closest dodge" higher
- If your health is significantly lower than that of the enemy, increase the weight of falling back
- If you are close to the enemies' base, shift the weight towards falling back
- If more enemies are in proximity than allies, shift weight towards falling back
- If more allies are in proximity than enemies, shift weight towards moving closer
... etc.