Elemental – Data Driving the AI

Published on Thursday, April 29, 2010 By Brad Wardell In Elemental Dev Journals


When I wrote the AI for Galactic Civilizations, everything was hard-coded in C++.  That was nice for me but not so nice for everyone who would like to tweak things later. Moreover, it makes it very easy for things to become a mess later on as improvements rely on my memory of what technique I used to do a given thing.

Yesterday and this morning, I officially began my work on the Elemental AI.  What’s in the game presently isn’t AI, it’s just a few IF/THEN statements.  My job is to design and code a structure that allows the computer players to play intelligently and provide a challenge without having to cheat.

So…how do you start?

The first step is with XML.  You can do an awful lot just by defining lots and lots of “stuff” in the XML.

First, I start by defining AI personalities. My starting point is AI_General which is, as the name implies the general AI personality that I’ll start from.  When I’m done, modders will be able to go in and define their own AI personalities that behave completely differently.


Here’s an example that I whipped up last night.

I define some Priorities (Economy, Farming) and I define some things I want the AI to avoid (War, Construction Times, etc.).  Now, as I get better at this, I’ll tie together these definitions throughout all the game data. 

So for instance, items that are tagged as Economy and Farming by the “AI General” will get their priority multiplied by 3.0X and 5.0X respectively.  Someone else might come along and make AIPersonality=”RavenX” and have a totally different set of priorities.  When the game starts, it’ll eventually look for all the AIPersonalities and grab them for the different AI. We might even let people from within the game pick which AI personality they want (not in 1.0 but eventually).

I’m a n00b

I’ve been using XML for years for skinning purposes but I’ve never tried to data drive an AI before. It’s not hard, but there is no substitute for experience. So over time, it’ll get better and better so that less and less of the AI is actually hard-coded and what requires “real” coding would be provided as Python.

Eventually, we will also have all the AI difficulty levels clearly defined so that players can adjust them far beyond what you could provide in the game UI.

BTW, feel free to shoot off your own ideas on this. My “AI skillz” largely revolve on producing macro-level systems for intelligent artificial players. Implementation is not something I am passionate about so don’t feel like you’re stepping on my toes by suggesting different implementation techniques.