This week will mark the second full week I’ve been working on the AI in Elemental. Beta 1 doesn’t have AI in it per se. It just randomly does nonsense really.
I’ve been writing computer AI now for 17 years (egads). It’s what got me into making games in the first place. I love computer AI. Everything else in the game (for me) is secondary.
Early AI: OS/2
The first computer AI I wrote was for Galactic Civilizations for OS/2. It had the distinction of being the first commercial (i.e. at retail) 32-bit PC game. The first commercial game to support >256 colors. But for me, the key feature was that it was also the first game to have a multithreaded AI.
Back in 1993, most developers weren’t familiar with multithreading. Games were made with a big WHILE loop. When a player hit the turn button, they would sit and wait for the computer to make their moves.
In the OS/2 version of Galactic Civilizations, the AI generated their move in the background. This was a key advantage back then because the computing power (think 386SX) was such that most AI had to massively cheat (and I don’t mean money bonuses, I mean play a different game) in order to be challenging. The AI in the OS/2 version of GalCiv didn’t have to cheat because it received the CPU time necessary to come up with a good strategy.
Of course, my programming abilities at the time were dismal. But thanks to multithreading, I was able to use brute force to make an AI that played reasonably well.
For me, multicore does’t make quite as much of a difference in AI programming as XML has. I have previously talked about data driving the AI. The goal is to move away from hard-coded scripts (whether in Python or C++) and towards XML based state machines.
The idea is that on reasonably modern computers, the AI can crunch a lot more data to come up with solutions that we humans wouldn’t think of. Chess programs have done this sort of thing for years but chess boards are very small compared to a game. With XML based state machines, we can do all kinds of interesting things by letting the AI look at lots and lots of data and look at overall goals that it might have and then make “intelligent” decisions.
If you look at the screenshot above, this is an example of an AI driven state machine. The AI was not “told” to build a city like this. Nor was there any sort of (IF I need Food THEN build a farm) type logic. Instead, it looked at the XML and looked at many different conflicting priorities and determined a course of action which. The amount of C++ code necessary to get it to intelligent build a city is less than 100 lines (compared to several thousand lines for the craptastic planetary improvement AI in Galactic Civilizations II).
A key feature of having an XML based AI comes in modding. Modders can make their own AI personalities and drive their own priorities. After all, the AI can only do what I (the AI developer) thinks is the best way to win. Experienced players may come up with other means.
Now, modding AI is nothing new. In the past, you could use Python or Lua or some other scripting language to write your own AI. XML driven AI isn’t particularly innovative either, it’s just the sheer level of its use that is a bit different here.