I have been working on a game for a while now, and it is going to be a TBS(Turn based strategy) in space.

And now I have come to the point where I am creating an AI for the game. I have no experience when it comes to designing AI's, the first one I ever made was based on random int's and getting the target out of an array.(not exactly a real AI)

On this topic I have a few questions:

  • How can an AI assess what is the best move to do next? Several units can move every turn.
  • How does a common AI consider what to do?(Example: Civilization, StarDrive 2, and similar)
  • How do I manage all the possible outcomes and the moves the AI can/should do?
  • 2
    \$\begingroup\$ This question is extremely broad right now, and might not be answerable in a concise way. I think your best bet is to start by doing some research - maybe try a free online course on AI to cover the basics like graph search and minimax strategies, or look up presentations and GDC talks about how existing games have approached AI. This basic research will help you identify techniques you might want to try, and you can then ask more focused questions about implementing them. \$\endgroup\$
    – DMGregory
    Mar 7, 2017 at 19:51
  • \$\begingroup\$ Hm, I already used my close vote to mark this question as "Too Broad," but Candid Moon raises a good point below that it may be more appropriate to close this question as a duplicate of "Complex Game AI for Turn-Based Strategy Games" \$\endgroup\$
    – DMGregory
    Mar 7, 2017 at 20:50

2 Answers 2


For the tactical AI of our turn based strategy game we use an approach inspired by utility-based decision making. Here is a simplified explanation:

Each AI Action (i.e. Attack, Advance, Hide) has a list of Considerations and an Execute routine.

Each Consideration is a relatively simple function that takes some parameters (i.e. the tested position, the unit that is tested, etc.) and returns a normalized floating point score (from zero to one). Some example Considerations are ConsiderDamage, ConsiderAnyTargets, ConsiderAdvanceImprovement, ConsiderUnitsSpread, ConsiderSafePath, ConsiderSafeSpot etc.

The AI evaluates all possible Actions at all available positions (i.e. in movement range) by invoking all Considerations for each Action/Position pair, and combining Consideration results by multiplying them. This product is the score for the Action/Position pair.

A boost can be applied to pair scores by multiplication, so some actions are preferred to others. For example in our game the MoveThenAttack action has a boost value a few times higher than the Roam and Advance actions, so MoveThenAttack is almost always preferred by the AI if there is an opportunity for an actual attack at a given position.

Finally the AI picks the Action/Position with the highest score and invokes the Action's Execute routine at Position.

Here are some talks on utility-based game AI:





You have many options:

1) State machine based on global values, preferences, and location.

2) Machine learning and neural networks.

3) Decision tree.

4) Value map (every tile has its value).

5) Different AI layers that calculate their own behavior, some layers can depend one on another.

6) Combine them all.


I recommend you watching GDC AI as was stated above in the comments. - this will help you not only create the AI that will beat everyone in the game but to create a real AI that is fun to play against and that you can relax playing vs him - then player won't be tired of the game. And ofc try to make the AI as smart as it can be at the moment and make it more stupid from there if he is easy to beat, but it's only when you have AI - by that I mean don't try to make it super smart in the beginning. I recommend first watching this talk Less is More: Designing Awesome AI for Games - in my opinion, it's the best talk about AI I have ever seen.

Also, this question might be a duplicate of this: AI


(If you haven't already)

I recommend you to learn some Algorithms and Data structures before diving into AI. Understand big O() notation and use the most efficient way to implement AI. Good AI should work fast as well, especially if it's TBS, it will take forever to calculate the things if you did something not efficiently.

Also, learn OOP, programming patterns and code design (architecture). AI without them would be hard to handle.

  • 1
    \$\begingroup\$ For future reference, if you think a question is a duplicate of an existing question, or might be too broad to answer completely, it's generally best not to answer it. If there's content you feel is missing from the potential dupe, add your answer on the original question's page - this keeps the information more centralized for future users looking for answers, so they don't need to cross-reference several pages to see the whole story. \$\endgroup\$
    – DMGregory
    Mar 7, 2017 at 20:53
  • \$\begingroup\$ Well, actually I can remove the statement about the duplicate, but still, leave the link. Why would I say it's not a duplicate because here OP is asking for tips about AI and AI in TBS. But another answer is asking about the exact AI that was implemented in Civilization V. So this is not a duplicate - that is why I said "might". I didn't think it was a duplicate - I made a guess. Though my question doesn't really answer OP listed questions, but I'm going to change that. \$\endgroup\$ Mar 7, 2017 at 23:33