The problem with the ai is that it feels a need to spend all its money each turn, and if it can't afford castle units it goes for the cheaper militias. Of course, next turn is the same story as they didn't save up.