Who to attack for an AI is affected by several factors, listed in no particular order:
what is the relative strength of the military
is someone else already at war with the potential target, if so what is the diplomatic relationship to both parties
what is the diplomatic relationship to the potential target
As to the diplomatic relationship, that is probably the most important. It can be influenced by religion, whether or not you agreed to demands and requests (such as declare war on X, stop trading with X, change to religion of requester, pay tribute, etc), proximaty of borders, and several hidden factors, including inherent relationship with a human player and inherent relationship between an AI and the one that the human is playing as.
Proximaty of borders, other than as part of the diplomatic relationship, has nothing to do with it. They don't care how far away you are if you otherwise qualify as a target. In my current game, also on a huge map, several of the AIs declared war on another one located on a differernt land mass only accessable to them with astronomy, when they did not have astronomy. Later on an AI (Sitting Bull) declared war on me even though two other empires lay between us. His knights, maces, and more primitive units got wiped out by my infantry and cannon. So, you see, they don't evaluate their potential target by distance or quality of military. I had a smaller military and he did not like me because I had refused all his requests to join his wars, stop trading with his opponents, and pay him tribute. Therefore, in his eyes, I was a targert for conquest. As a result he has gone from 20 cities to 2, although due to the distance it took me a while to get there.