AI Plans

== Attack ==
The idea is that find_something_to_kill (hereafter fstk) should be retired in its entirety, along with kill_something_with (ksw) and other related braindamage.
A new system should be built which clearly separates defensive attacks (kill units converging on our cities) from coordinated offensive attacks (bring an army to the enemy).
Defensive attacks are in general in two categories:
 1) kill dangerous units that are too close to our cities
 2) kill transports, diplomats and other dangerous units before they get close
We already have ai_military_rampage (rampage) which looks for targets in a one-turn horizon. It has been basically rewritten by Greg, and now works pretty well, and the code is easily readable (unlike fstk and ksw). The plan is to extend this to slightly more than one turn, so that it can handle (1) above.
We should also add a counterattack check for the last defender of a city, of a fortress and of a carrier, which checks if a suicidal attack might actually be less suicidal than sitting duck.
I have written an AI hunter code, which builds fast-moving units that it sends after targets that the AI keeps track of and tries to guess roughly where is heading based on its past movement trajectory. Along with the custom code for air units this should take care of (2) above.
Then on to the offensive part.
We should calculate a 'ground zero', a place to concentrate our attacks. This should be a coordinate on a continent that is somewhat close to the AI, which has not too well defended cities, and bonus if there are rails and roads we can abuse. We should calculate a turn sometime in the future when we should have forces enough available to conquer this place.
Units that are recruited to offensive actions should check each turn if they must start moving towards ground zero this turn to reach it or not (with some margin of error). If they must, start moving. If not, just check for rampage targets and wait. This way the army will only assemble once they are at the ground zero, at which point it is hopefully too late to do countermeasures.
If they need to ferry, then they should grab a ferry immediately, and the ferry will sail when it is time. (I am not sure about this point. Greg?)
When moving into ground zero, avoid ending up stacked with other units (if killstack == 1). This is a challenge best left to the pf authors, I believe, rather than custom hacked into the AI movement code.
The offensive want calculation should be based on the same principles as ksw - that is, we check what is a good unit to attack versus the units in the ground zero area. We need a nice statistical distribution of attackers and defenders (bodyguards).
Now, the big question is how to stick the odd unit capabilities into this. Diplomats, nuclear and air units should (still) be handled by separate code, I think. Paratroopers, I am not sure. 
== Movemap ==
The "movemap" is a data structure to help easily find enemies at locations where we want to, and avoid them.
It is a mapsize array of 
 struct {
 struct unit_list 1_turn_reach;
 struct unit_list 2_turn_reach;
 } movemap;
These unit lists contain all the units that can reach the tile in one or
two turns. You can now iterate over all possibly dangerous units that can
reach a given tile quickly.
To set up this cache, run through all units once, and use pf to mark tiles
in the movemap. For ferries, for each ferry { make pf map; for each tile {
for each passenger { pf backtrace from tile and see if we can overlap with
the ferry's pf map, if so mark tile } } }. (Note that Greg does not agree with this ferry idea, and may have a better idea using pf combined sea/land movement.)
Setting up the cache will consume some CPU, and has to be recalculated
each turn for each player, but will not cost much more CPU than a
pf-converted city danger code, I think. The city danger code will have to
(well, should) do these calculations anyway.
There is a movemap patch here, which is waiting for Greg to add some ferry enhancements to the path-finding code.
== Defense ==
assess_defense():
The movemap code enables us to easily look for enemies that can reach us
in two turns. This is for immediate threats. I think using path-finding to
assess longer term dangers is not very useful. Instead, we can look for
total hostile attack power on continents and in oceans, and what kind of
capabilities they have (igwall, nuclear etc).
We can use aihunt tracking code to increase danger of two-turn units that
are on a movement vector that approaches us.
The unit findjob code should be changed to ensure we keep enough
defenders. First we should reserve some units in cities for defensive
duty. Then last we should move reserve units to reinforce emergency
points, if possible.
Category:AI