I’m on Skynet’s side

By on May 11, 2010 1:06:55 PM from JoeUser Forums JoeUser Forums

Frogboy

Join Date 03/2001
+1491

image

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.

Locked Post 80 Replies
Search this post
Subscription Options


Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 1:13:51 PM from Elemental Forums Elemental Forums

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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 1:27:48 PM from Elemental Forums Elemental Forums

I would for one, find it really ironic if the FFH team made a Civ mod for Elemental.

 

 

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 3:31:52 PM from Elemental Forums Elemental Forums

Awesome stuff. This will make custom tweaking of the AI's a breeze.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 3:34:25 PM from Elemental Forums Elemental Forums

Hey that computer is cheating, single Farm at 15 food, and 4 huts at 4 food each. Where is it coming up with that extra food unit?

 

 

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 3:39:22 PM from Elemental Forums Elemental Forums

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

Darvroth

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 5:33:47 PM from Elemental Forums Elemental Forums

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?

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 5:38:55 PM from Elemental Forums Elemental Forums

Quoting Ryan Hanson,
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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 5:59:11 PM from Sins of a Solar Empire Forums Sins of a Solar Empire Forums

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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 6:11:24 PM from Elemental Forums Elemental Forums

I love games with lots of difficulty levels and and lots of different kinds of ways that the AI plays. Leads to very fun games!

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 6:14:51 PM from Elemental Forums Elemental Forums

Quoting Maktaka,
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.

 

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 6:49:51 PM from Sins of a Solar Empire Forums Sins of a Solar Empire Forums

so... when you mean XML you mean Extensible Markup Language?

cause I dont quite understand how XML is helpfull in making a state machine.

and then you go on to say the code is <100 lines of c++...

gosh, if i could create an AI that could play a game optimally in 100 lines of code... heh!

maybe i am just stupid.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 6:55:46 PM from Elemental Forums Elemental Forums

Quoting Frogboy,



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

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 7:01:27 PM from Elemental Forums Elemental Forums

Quoting Darvroth,

Quoting Frogboy, reply 10


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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 7:05:06 PM from Elemental Forums Elemental Forums

Quoting XeronX,
Hey that computer is cheating, single Farm at 15 food, and 4 huts at 4 food each. Where is it coming up with that extra food unit?

I am pretty sure the Granary provides a 15% Food bonus. What gets me is that that Town would have to destroy the Guard Tower ( apersonal selection) to move up to the next level.

Now, if the AI is to be capable of that level of detail, then we are Golden...

 

 

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 7:21:37 PM from Elemental Forums Elemental Forums

One of my curiousities was how you'd make tech trading work.  It was the one area in GC2 where I felt there was unique rules for the AI as compared to humans, which annoyed me.

 

 

 

 

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 8:19:07 PM from Elemental Forums Elemental Forums

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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 9:21:00 PM from Elemental Forums Elemental Forums

Well, just as a bit of terminology ... the research aspect should probably replace "Technology" with "Knowledge" and replace "Research" with something like seek.

What knowledge do you wish to seek?

We have found/uncovered another piece of knowledge!

Or

Which source of Knowledge do you wish to expand on?

We have gained more knowledge!

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 9:34:05 PM from Elemental Forums Elemental Forums

Quoting Frogboy,



Quoting Darvroth,
reply 12

Quoting Frogboy, reply 10


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?

Darvroth

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 9:39:50 PM from Elemental Forums Elemental Forums

I especially like the skewed data on winnable odds. That one makes me smile. Things like resource mal-data, and relations mal-data, feels less necessary yet for me is still welcomed.

Certainly a weaker AI should play with more "character", "personality", "flavor" and less so optimal play exploiting hidden strategies (like the high level AI)

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 10:00:01 PM from Elemental Forums Elemental Forums

Quoting Darvroth,

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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 10:53:10 PM from Elemental Forums Elemental Forums

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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 11, 2010 11:25:30 PM from Elemental Forums Elemental Forums

Quoting Frogboy,


These aren't random events.

It's noise on the data it receives.

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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 12, 2010 12:42:14 AM from Sins of a Solar Empire Forums Sins of a Solar Empire Forums

Quoting Campaigner,
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.

Reason for Karma (Optional)
Successfully updated karma reason!
May 12, 2010 1:06:22 AM from Elemental Forums Elemental Forums

Actually I think it would be funnier if Military Intelligence was selling (AI) contracts to "big time" Video Game developers (role reversal)

Reason for Karma (Optional)
Successfully updated karma reason!
May 12, 2010 1:43:08 AM from Elemental Forums Elemental Forums

Quoting Campaigner,


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

And gigahertz doesn't mean anything anymore

Reason for Karma (Optional)
Successfully updated karma reason!
Stardock Forums v1.0.0.0    #108433  walnut3   Server Load Time: 00:00:00.0000266   Page Render Time: