
Debugging AI is tough. Is the AI stupid because of a bug? Is it stupid because the AI developer was stupid? (in my case, that’s usually why). Or is it stupid simply because the player is doing something that the AI didn’t know how to handle.
So thanks to the forums, one thing that popped up was that the AI sovereigns were being unusually stupid by not cleaning up the goodie huts near them. Why weren’t they? There’s a fairly good algorithm for scouting the FOW and then going after goodie huts once it knows of them.
But it wasn’t.
Why?

The answer was that I was using a function called pUnit->GetPosition() which returned x,y coordinates. I thought (wrongly) that it returned the coordinates in tile form (i.e. what tile on the board it was in) but it wasn’t. It was returning the pixel position. So when I passed this into my various functions, it came up telling me that I was in enemy territory and to run away. Hence, the sovereign would run to a city and stick around there.
While not a crippling issue by any means, it is one of those things that would give a human player a significant advantage over the computer players, especially early game.