Jump to content
  • Advertisement
Abdou23

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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"

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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?"

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!