# What AI for a resource management + combat?

I have a very simple game: 2 players (one human and a computer) and both have 1000 tokens. They must build an army. Depending on the type of soldier, it cost from 10 to 100 token to train one. Eventually I want them to attack the each other.

What would be the AI to use in that case? Is there any example around that I could learn from?

Thanks!

• Without knowing more details, you could end up needing a very complex solution indeed! RTS AI is some of the most complex (and therefore fun :-D ) game AI to develop, even if you remove all spatial factors. – tenpn Jun 28 '11 at 16:16

For this type of game, I'd like to refer you to a question that I asked before:

Basically the idea is that you keep a power score for every unit owned by a player. This score can be based on the unit's cost, the unit's stats or even a score that you chose arbitrarily for every unit.

Then you calculate the power score of each player, based on the power score of all their units.

Finally, you compare the score of the computer and the human player to make AI decisions.

For example, a computer with a Hard AI difficulty level could decide to always try to keep 20% more power than the player, or whatever. You can even put different random play styles like Aggressive, Defensive, etc. based on the power level of the opponent.

This technique certainly is not the best way to go and won't work with all games, but it sure is simple to implement and it did the trick for my AI demands. I always prefer to try out a simple solution first, and then move on to a more sophisticated one if the first approach looks too stupid or inappropriate.

I think that the Jesse Emond answer is a very good solution. It's simple and effective, the games purpose is that they look real, and many times this is achieved with simple rules.

But if you want to complicate more, you can try to investigate in the use of behavior trees. The use of a data-driven AI system in a plain-text format or a script language as Lua, Scheme or Python can be useful. Age of Empires use scripts to define the AI of the enemies that can be modified by the players. A sample:

(defrule
(or
(goal TRAIN_UNIT TRUE)
(goal NEED_MANGONEL TRUE)
)
(soldier-count >= POPULATION-5)
(can-train-with-escrow mangonel-line)
=>
(chat-local-to-self "train mangonel:Anti Scorpion")
(release-escrow wood)
(release-escrow gold)
(train mangonel-line)


The term AI is misused here. Well you need no AI. Hey i don't want to be rude! This is just an optimization problem that generally can be solved using greedy strategy. Alas, greedy solution means boring game: as the player gains experience he will adopt the same optimum greedy solution and your game becomes simply an advanced tic-tac-toe.

But don't worry! Let's talk about your problem and the possible strategies.

Here the (greedy) solution is to build as much strong-superpower-invincible-lastlevel unit as possible, because this kind of units overwhelm the others in term of power. Normally those units are slow to build so your base is left undefended until they are ready so your opponent can build a single demolition-unit and "the white wins in a move".

Then you start to think to build some "lower-level-but-faster-to-build" units before start to build the "final-weapon". This is still a greedy solution: you simply put a "defence" parameter in the objective function to minimize.

In general you should model your objective function leaving room for such parameters and let the computer to choose among a pre-fixed set of parameters or to choose randomly.

This gives to your otherwise booring optimum finder algoritm, a sort of character, a personality.

Once those parameters are choosed you should simply apply your favorite optimization algorithm.