🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How difficult is it​ to program​ enemy AI for a strategy Civ like game?

Started by
3 comments, last by IADaveMark 5 years, 10 months ago

I have an idea for a mobile game similar to Civilization or Polytopia but of course on a much smaller scale and not as complex. But I was wondering what approach should I take to program the enemy AI. Does each faction take actions depending on the situation they are in each turn like how many resources, what buildings it needs, what units to move and where. Or should each one has its own personality or agenda that they act upon, like I need to build a tower but I don't have resources, so I'm going to focus on collecting the resources and then build it. This, of course, seems like a more complex AI behaviour.

Also any tips for actual coding the AI would be helpful. I never did AI programming before.

Advertisement

Take a look at books "AI by Examples" and "AI Game Programming Wisdom". There is no difficult tasks in AI. Just general game play logic + probability theory + graphs/steering behaviors + fuzzy logic + ML/NN. But you can code good AI without last one. Also take a look at 0.a.d. or "deepmind Starcraft 2 ai"

Difficulty is always relative.  Relative to making the game as a whole, the AI system is fairly small. Tuning the AI system is a big effort because crafting the balance between fair and fun is hard.

I don't know about the official Civilization series code, but FreeCiv is open source so you can peek at their AI system.

Generally the technique is to create a list of what actions are available, then rank them based on how much each one is wanted.  How much they're wanted for civ is based on the government type or AI player's settings as well as immediate needs.  The functions calculate the utility of the action, generally called utility functions.  The code computes whatever has the highest utility among the options, and whatever is wanted most is what is selected. 

As an example, when choosing what to build a city may scan what's going on.  There may be no immediate risks and the society in general has chosen to expand. The city may choose that building Warrior ranks has a score of 457, Spearman has score 358; growth is important so the points allocated to Scout has score 580, Granary has a score of 874, and Settler has a score of 943.  So city chooses to produce a settler.

The hard part of these systems isn't building the choices or the decision tree, but fine-tuning the values and their computation. 

Frob nailed most of it pretty well. In theory, you could just do IF/THEN statements here and there and have simple AI. Or you could do really nuanced stuff with utility curves and whatnot. The best bet is to ask yourself, "if I was playing the game, what info would I take into account and what would I do with it? What move would I do?"

 

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement