The AI attacks with the following priorities:
A) Each score point above your other teammates gives you 1 AI point. So if you have a score of 1337 and your friend has a score of 1330 you have 7 AI points.
B) Each feet closer (original settlement placement only counts) to the AI at hand grants you one point. So if you are 4 feet closer to the AI, you will gain 4 AI points and your buddy zero.
C) The host of the game always gets 5 AI points at the start of the game. These never changes, and was implemented to give a harder time to the host, since he sets the rules and gets the least lag.
D) At the end of you and your buddies archaic age, the CPU will make a scouting count. The one who scouted the most dark areas (1 point/5 square feet more scouted) is more likely to be attacked by the CPU. Ofcourse this also counts to your total AI points, and is accounted only when you and all your allies finish the archaic age.
This was implemented to somehow tell the CPU which player is more competent/agressive to give an easier time on the beginners who stays at home.
If you play with "Revealed Map", section D will not be accounted for at all.
The one with the most AI points will be attack, always, unless you are attacking the AI himself, in which case he will defend.
Hope this helps!
"All we have to decide is what to do with the time that is given to us"
Gandalf - JRR Tolkein. The Fellowship of the Ring