Building a believable computer opponent for a 4X strategy game is one of those problems that turns out to be bottomless. I'd use the cliche it looks simple from the outside... but I don't think thats true, I thought this would be a tough nut from the outset. I've built a chess playing engine before and that was far simpler to get a strong opponent - though it helps that that is such a well understood and documented problem. The player wants an opponent that explores, expands, exploits and exterminates with apparent intent — one that musters an army over several turns, marches it across a continent, lands it on your shore and takes your city, all while you watched it coming and couldn't quite stop it. They do not want an opponent that teleports units, reads your mind, or sits inert in its starting cities until you wander into range.
This post is a tour through the Annhexation AI — explaining how it makes decisions, what it remembers between turns, and how the same core machinery produces eight distinct civilizations and four difficulty levels. Annhexation isn't open source, so rather than quote the implementation I'll describe the design and illustrate the interesting bits with pseudocode.








