I’m on Skynet’s side

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.

Today’s AI

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.

Example: Elemental

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).

AI Modding

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.

Good news that the AI can be modded as well. Having a bad AI kills any game, but now this will not really be an issue. I do not doubt for a second that Elemental will draw a lot of attention from skilled and talented modders.

I did notice the AI chose to max out the city at level two..... The housing improvement tech tree, at least for Kingdoms is by far the most important. Without that it is not possible to advance a city past level 3 and have the city be anything other than a collection of huts....

Brad, given that it seems you intend for the AI to make minimal use of crude bonuses to be a challenge, how do you intend to differentiate the difficulty levels? Will there actually be an attempt made for the AI to play "dumber" or "smarter" at the different levels? Or will it be one level of "intelligence" with resource bonuses/handicaps to differentiate the levels?

Brad, given that it seems you intend for the AI to make minimal use of crude bonuses to be a challenge, how do you intend to differentiate the difficulty levels? Will there actually be an attempt made for the AI to play "dumber" or "smarter" at the different levels? Or will it be one level of "intelligence" with resource bonuses/handicaps to differentiate the levels?

I'm looking at two things to distinguish difficulty:

1. AI Errors

and

2. Money penalties.

AI errors would be feeding the AI randomly bad data about the world. The lower the intelligence, the more bad data it would receive.

When you say 'randomly bad data', would this be like imagining there being a non-existent resource on the map and planting a city near it to harvest it, or over/underestimating the amount of a resource available at a real location? I'd expect the latter to be more human-like, since we have a tendency to mis-read or mis-remember information and make bad judgments because of it. Although you may have something else in mind entirely.

When you say 'randomly bad data', would this be like imagining there being a non-existent resource on the map and planting a city near it to harvest it, or over/underestimating the amount of a resource available at a real location? I'd expect the latter to be more human-like, since we have a tendency to mis-read or mis-remember information and make bad judgments because of it. Although you may have something else in mind entirely.

Some examples might include getting bad distance data on different things.

So rather than attacking Unit A it might go to Unit B.

Or it might get slightly wrong data on the combat rating of a given unit so that it's more apt to attack a unit it can't defeat.

Or it might declare war (or ask for peace) because the data it's using to determine its relations with you is slightly off.

Or it might declare war (or ask for peace) because the data it's using to determine its relations with you is slightly off.

I have a distasteful response to this portion of the bad data. It is frustrating beyond belief to have the AI conduct diplomacy via random events. I'd suggest that diplomatic data not be included in the bad data for the AI to ensure a more consistent relation to the human and other AI players. Without that why bother to even research the diplomacy tech tree?

Or it might declare war (or ask for peace) because the data it's using to determine its relations with you is slightly off.

I have a distasteful response to this portion of the bad data. It is frustrating beyond belief to have the AI conduct diplomacy via random events. I'd suggest that diplomatic data not be included in the bad data for the AI to ensure a more consistent relation to the human and other AI players. Without that why bother to even research the diplomacy tech tree?

Here, "tech" trading should be non-existent, as "techs" actually more represent techniques and abilities as they are phased into society (hence each "discovery" uncovering a variety of things), not a widget that revolutionizes something, or a sword mkIII.

That being said, some sort of spell trading does sound feasable in some form.

Or it might declare war (or ask for peace) because the data it's using to determine its relations with you is slightly off.

I have a distasteful response to this portion of the bad data. It is frustrating beyond belief to have the AI conduct diplomacy via random events. I'd suggest that diplomatic data not be included in the bad data for the AI to ensure a more consistent relation to the human and other AI players. Without that why bother to even research the diplomacy tech tree?

Darvroth

These aren't random events.

It's noise on the data it receives.

Point taken however it has the same end result for the human player; the AI behaves in a manner inconsistent with the nominal ralations the human has achieved up to that point. From my perspective if I know up front the AI will act inconsistently what is the point attempting relations at all?

Point taken however it has the same end result for the human player; the AI behaves in a manner inconsistent with the nominal ralations the human has achieved up to that point. From my perspective if I know up front the AI will act inconsistently what is the point attempting relations at all?

It sounds to me like Frogboy is just saying that, e.g., when the AI goes to evaluate your military strength to determine whether to go to war against you, it might overestimate or underestimate it. i.e., depending on how stupid it is, it might be willing to declare hostility when it's not in its own interest because it thinks you're easy pickings, or refuse to attack you because it thinks you're too powerful. Presumably this would only apply if it was considering attacking you anyway, so a faction with a peaceful personality wouldn't randomly declare war, but a faction that was war-oriented anyway might start picking fights it couldn't handle or backing down sooner than necessary. That doesn't seem like a random event to me; it actually sounds like a really believable way for an opponent to make errors.

I like SkyNet too. Will be interesting when the first A.I that can "see the whole picture" gets created (Just hope it doesn't get installed in military supercomputers!)

I'm also interested in A.I. So what's the best programming language for A.I? XML like you want to use?

Am I correct in believing that CPUs (for home use) from 2005 and onwards are strong enough to handle any game A.I thrown at them in realtime?

Cause from my perspective A.I today is still just a bunch of scripts. Don't understand how THAT can consume so much computing power....and even if they do, we got DualCore cpus today at 3.0 GHz (effective speed 9.0 GHz? Considering that the Pentium 4 Northwood 3.2 GHz released around 2004 was above 3 GHz and therefore cannot match my Core 2 Duo 3 GHz.

Frogboy, have you by chance read any books by F. A. Hayek? He wrote several highly influential papers on the state and origin of knowledge and information. The concept that you have laid out concerning "noise on the data" fits almost exactly into his theories.

I will forgo the wall'o'text expounding on his theories. If you are interested you can look up one of the articles here.

I like SkyNet too. Will be interesting when the first A.I that can "see the whole picture" gets created (Just hope it doesn't get installed in military supercomputers!)

Honestly I'm pretty sure the military is going to have that kind of technology way before we have to face it in future strategy games. I would hope so anyways, though it might be funny to see a picture of Brad lecturing some weapon designers on AI programming.

I'm also interested in A.I. So what's the best programming language for A.I? XML like you want to use?

Am I correct in believing that CPUs (for home use) from 2005 and onwards are strong enough to handle any game A.I thrown at them in realtime?

Cause from my perspective A.I today is still just a bunch of scripts. Don't understand how THAT can consume so much computing power....and even if they do, we got DualCore cpus today at 3.0 GHz (effective speed 9.0 GHz? Considering that the Pentium 4 Northwood 3.2 GHz released around 2004 was above 3 GHz and therefore cannot match my Core 2 Duo 3 GHz.

Pathfinding and some learning algorithms can easily max out modern CPUs. Frogboy is using state machines for the decision logic, which doesn't require much CPU power to run. It's much more a matter of how well it's written (not the sort of thing you can easily throw brute force at). However, one thing you could do is use an offline learning algorithm to tweak various XML parameters. Basically you change some things, run 100 purely AI games, see how well the change worked, and repeat until you find an optimal combination.

By the way, XML is more of a way of storing data structures than a programming language. The programming languages Frogboy is using are C++ for the low level stuff (like pathfinding) and Python for the high level stuff (this is the scriptable part).