How is a computer strategy game's AI created?

I enjoy playing strategic war games against a computer AI. Some are real-time strategy games, others are of the you-go, I-go variety.

Oftentimes I am react with a slap-to-the-forehead “why didn’t I think of that!” when the computer makes its move.

These are typically games with literally hundreds of nitpicky rules involved.

In layman’s terms, how is a computer programed to take into account my moves, formulate a successful strategy against such moves, all while remaining within the confines rules of the game? We’re talking 50 game “pieces” per side operating under some complex interactions here! My head is spinning just contemplating what’s involved.


FYI: I enjoy games like People’s General, Steel Panthers, Panzer General, Third Reich, Risk, etc.

I’ve done full scale gaming programming, so hopefully someone with better specifics will give a better answer.

There are two basic ways for a computer to “decide” what to do next. The first method is the brute force method where it tries to check every possible outcome of every action, and based on those theoretical outcomes figure out which move was best. I had a computer chess program about 15 years ago that did this. It had settings for easy, medium, difficult and champion. All it did was compute every possible move that it could make, and I could make in response to determine which left the board in the best shape for itself. Easy looked 3 moves, medium looked 7, difficult looked 15, and Champion looked 30 moves deep(and took about 6-8 hours between moves with a full board).

The other way is to get an anyalisis of the situation and using a weighted system, and preprogammed tendancies decide on the action. If it is a primarily-defensive unit then attack anything comes within range of the base. If there is nothing within range, then wait. If there are two things, then attack the closest, or the strongest, or the most hurt, depending on what tendacies the programmer decided to give that unit. The best AI is programmed to notice weight more subtle things, in terms of the whole of the battle, and develop a strategy that uses all of the pieces together.