# Doing a passable 4X game AI

I am coding a rather "simple" 4X game (if a 4X game can be simple). It's indie in scope, and I am wondering if there's anyway to come up with a passable AI without having me spending months coding on it.

The game has three major decision making portions; spending of production points, spending of movement points and spending of tech points (basically there are 3 different 'currency', currency unspent at end of turn is not saved)

• Spend Production Points
• Upgrade a planet (increase its tech and production)
• Build ships (3 types)
• Move ships from planets to planets (costing Movement Points)
• Move to attack
• Move to fortify
• Research Tech (can partially research a tech i.e, as in Master of Orion)

The plan for me right now is a brute force approach. There are basically 4 broad options for the player -

1. Upgrade planet(s) to its his production and tech output

2. Conquer as many planets as possible

3. Secure as many planets as possible

4. Get to a certain tech as soon as possible

For each decision, I will iterate through the possible options and come up with a score; and then the AI will choose the decision with the highest score. Right now I have no idea how to 'mix decisions'. That is, for example, the AI wishes to upgrade and conquer planets at the same time. I suppose I can have another logic which do a brute force optimization on a combination of those 4 decisions....

At least, that's my plan if I can't think of anything better. Is there any faster way to make a passable AI? I don't need a very good one, to rival Deep Blue or such, just something that has the illusion of intelligence.

This is my first time doing an AI on this scale, so I dare not try something too grand too. So far I have experiences with FSM, DFS, BFS and A*

-
The correct way to approach this problem is to do research on it yourself. Implement what you describe and see how well it works. Then make it better. Once you think you have a good algorithm, re-implement the AI to use the new structure. I'd suggest building this in a scripting language like Lua, to make it easier to throw the old code away. – Nicol Bolas Apr 3 '12 at 15:27
To clarify, I could try implementing what I have in mind. I am just wondering if there are other ways to create an AI besides min-maxing or the traditional 'iterate-and-compute-best-score' method. – Extrakun Apr 3 '12 at 16:37

Sounds like you could try out Minimax to "mix" your decisions. There was a talk at last year's Game AI Conf by the programmers behind Green Corp, and that's what they used to build their AI. It took them a lot of time to get it right, but they have a decent result.

-

If it is good enough to arouse interest (and you'll have to assume it will be, or you can quit it right now), and it supports networking, the best course of action for this kind of thing is:

• built it multiplayer without any AI
• ensure that every data that is send to the client can be easily "understood" by an AI
• create a very simple AI, which allows either some kind of scripting, or a lot of configuration options
• allow the players to modify the AI scripts, bind them to the game, and let the AI play via-networking, as if it was a real player

Doing so, the hard part will be to allow the AI to be scripted and used this way, and you'll just "outsource" the actual AI optimization to the players.

This will not only give you a much better AI, but will also add a lot of value to the game itself!

-