Brad Wardell's views about technology, politics, religion, world affairs, and all sorts of politically incorrect topics.
What's involved in making a fair computer AI
Published on March 31, 2006 By Draginol In GalCiv Journals

Every so often someone, usually someone who just got beaten, will start screaming that the game "cheated!".  It's a lot like the neighbor kid who screams "cheater" every time he loses at a game.

One of the reasons people like Galactic Civilizations II's AI is because it doesn't cheat.  But that generalization is only true to a point -- it doesn't cheat until AFTER "intelligent" (aka "Tough" in the overall difficulty slider).  Few players can beat it at that difficulty level and that's where meticulous care was put in to make sure that it's playing exactly the same game as the player.  Beyond tough, all bets are off.  At that point, we're talking about players who have either found an exploit or are simply incredibly good at strategy games and our goal then is to make sure they have a challenge. 

At Intelligent, it's playing its best game, same rules, same money.  At genius, it gets a 125% modifier to its bonuses (economically mainly and ability bonuses).  In practice, it just makes them a little bit spunkier as no AI can be as efficient as a human in a crunch so this is the level I recommend for people who are really good at the game who can beat intelligent.  And the last one is called "Incredible" where we're doing everything we can to beat the player.  200% modifier to bonuses, the intuition algorithms are set to be very lucky, etc. Basically, the player's a god at this point and we're doing all we can do beat the player, no holds barred.

The difficulty levels (from the manual) are:

  1. Fool.
  2. Beginner
  3. Sub-Normal
  4. Normal
  5. Bright
  6. Intelligent (this is where the AI is playing the same game you are with no bonuses or penalties with its best algorithms)
  7. Genius
  8. Incredible

In most games, the AI begins cheating right away or at such a low level that even casual strategy gamers have to raise the level well beyond anything that is remotely "fair" in order to be challenged.  In Galactic Civilizations II, it's not until near the end that the game is tilted against the player.  Again, this is in the user manual so this isn't some state secret. 

In the development journals, we talked about the goal of having the "intelligent" AI being able to beat 95% of players.  I think we succeeded.  In v1.1, our goal is to maintain that 95% (as people get better at the game some will eventually be able to beat the "intelligent" AI so we have to evolve with them).

So where do people scream foul and why?

  1. Claim: "The AI knows where the good planets are".  This is largely a carry over from Galactic Civilizations 1 where they did know where the good planets are. As any experienced GalCiv 1 player can tell you, that advantage was really pretty minor in the bigger scheme of things.  A good player can colonize as fast as the AI in GalCiv 1.  In GalCiv II, it's even easier because if you have Stellar Cartography you can see the planets on the mini-map. 

    However, we knew that many people used the GalCiv 1 AI advantage to say "the AI isn't totally uncheating" so a lot of work was put into having the AI design, build, and scout out planets. And I mean a lot of work.  To a user, scouting is easy, they "look" at the mini map. But having the AI do it intelligently took some work.  Even things like how many scouts to build, when should it build them, where should it send them, involved a lot of work to do it well because every move at the start of the game is crucial.

    In 1.0X of the game, we even put in additional checks to make sure that this was the case since there were cases where the bIsKnown flag could be uninitialized and have some junk in it (and as any C/C++ coder can tell you, if you're doing a if(bIsKnown) and there's garbage in there it'll return true.

    But this scenario has been played out over and over again, tested, verified by us, other players, etc.  Anyone with the demo can test it for themselves too. It's very easy to verify that the AI does not know where the good planets are.  Now, at "Incredible", it's hard to say.  The ability bonuses and some of the simulated intuition stuff gets murky when you're multiplying everything by 200.  But that's not material to our discussion since the AI at Genius and Incredible is getting advantages over the player and has always been stated as such.

    For instance, at 200 bonus, the sensors are probably so powerful that they have no real fog of war. 
     
  2. Claim: "The AI builds too fast."  This part almost always rises out of, sorry, "newbie" players who don't realize you can quick buy things. Decent human players do this, and you can bet the AI does this when it can.  The more money it has, the more often it can quick buy things.  On the planet screen, that's what the "Buy" button means.  A player starts out with 5,000bc.  You can literally build something every turn for dozens of turns without any special advantage.  At the highest levels, where the AI gets money, it can go even longer. 

    This particular claim I find especially annoying because it sounds a lot like the neighbor kid screaming "cheater" because they don't know how to play the game effectively yet.  It would be much better for the person to simply ask on a forum and then someone could tell them how it's being done (or read the manual).
     
  3. Claim: "The AI trades with each other too much."  This is another one of those "I'm losing so the game must be cheating" type things.  In 1.0 to 1.0X the AI literally does a ulPlayerIDToTradeWith = rand()%(ulNumberOfActivePlayers);.  IF it's the human player, it pops up a dialog and offers to trade X for Y. ELSE it just simulates the same thing with the other player deciding whether they want to make the trade or not.  In 1.1, it still does much the same thing but I made it a lot less likely for the military techs to get traded if they're expensive since it was very annoying having each player having the same military techs. 

    The point being, the AI isn't making a distinction between the human player and another computer player.

Now this isn't to say there isn't some bug or something.  But I haven't seen it and I haven't seen one other than the bIsKnown initialization issue and even that would likely only show up on a saved game and was fixed weeks ago in 1.0X (and I was never able to reproduce it, I just saw that it wasn't being properly initialized and that the variable wasn't being loaded correctly from saved games).  So it's possible that there is some bug. 

For example, I haven't looked into this because I didn't write the code but the AI may know where galactic resources are.  I say that because during the beta, galactic resources showed up on the mini-map.  IF that's the case, we'll likely have galactic resources show up on the mini-map again (assuming they don't already) because there really shouldn't be a "Race" for them, they should just be known IMO.  But as a practical advantage, it's pretty minor. By the time you've found your planets, you've probably also found the galactic resources.

Consider some of the things the AI has to do, in order to play by the rules and still be effective:

  • It has to design its own ships. You think you have trouble deciding whether to put an extra sensor or life support unit or weapon on a ship? Try being a computer player trying to fit every last thing on the ship without cheating. Think of all the possible combinations of fitting stuff onto a ship to use up every last bit of space.  Think about what weapons you would put on and what defenses you would put on.
  • Similar to the first point, having to figure out which weapons and defenses to focus on. Not only does it have to focus on them and research them but it has to figure out when to research them and do so without being scripted.  It has to know how much offense and defense to put on.
  • It has to know whether it should be focusing on range or speed based on different galaxy sizes, different numbers of players, etc.
  • It has to know what to build on a planet and when.  Should it use that special food tile for a farm or put a factory on it anyway because it needs the production more than it needs the money?
  • It has to know when to know when it should be building colony ships as opposed to freighters as opposed to constructors.  In Civilization IV, my favorite TBS, the player might build a dozen or so "workers" throughout the game. Workers don't get consumed when they're used, they stick around the whole game.  But in GalCiv, you have constructors which are consumed and you have freighters, which are consumed, and you have transports, which are consumed which means a LOT more decisions have to be made on what to build on a planet.  And some of these units are expensive.
  • It has to do a lot of work on the diplomacy, there's a lot of factors to take into consideration.  Because the game has no political borders which in other games prevent players from doing a sneak attack, GalCiv's AI has to be on the look out for all kinds of threat patterns and do so intelligently.  Plus, you don't want players going to war with you one turn and then asking for peace the next. There has to be a good, logical, intuitive reason why it goes to war.
  • The game has fleets AND those fleets are bound by logistics. In other games you either have armies/fleets or you don't.  If you have them, there's no practical limit to how much stuff you can cram in them so they can just go around wreaking havoc.  In the games that don't there's no effort in having to put together such an army.  But in GalCiv II, the AI has to decide how big of a fleet to make, when it should be used, what ships to put in it.  Plus it has to research techs to increase those logistics abilities. When should it research them? Why?
  • The tactical battle AI could take pages to explain.  In most space games, they don't have an open surface so there's plenty of choke points and a very limited # of places a fleet can go.  In most land based games, you have mountains and oceans which create choke points as well.  But in GalCiv II, it's open space which means that it's very very easy for a human player to outflank or use mobility to win the day.  The AI has to deal with that kind of thing. It has to know when to flee or avoid a target, to circumvent an opponent to go to a more valued asset.
  • The AI has to contend with special invasion ships. In other games, any unit can invade. In other games, one can build a transport and send it over and not worry about having to escort it.  In GalCiv, the AI has to decide when and how to escort a ship.  Escort too much and you lose the initiative. Escort too little and you lose billions of troops in space.

And it goes on and on and on.  So when you look at the claims people have made above, they're such small potatoes compared to what is involved in writing a computer AI that is playing by the same rules. 

If I were going to have the AI cheat, I'd do things like give it more space on its ships. That would be a wonderful advantage.  Or I would teleport ships outside the fog of war so that it would be easier to coordinate attacks.  Or I'd bump up its logistics ability so it could fit just a bit more in the fleet.  Or maybe I'd sprinkle its worlds with just a few more special tiles.  But I don't.  Because the AI doesn't cheat.  But it would be so much easier if it did.  And so you can probably see why I get so annoyed when some new user or hack reviewer tries to build their own credentials by making cheating allegations.  Because I could have saved a ton of work if I had had the AI cheat.

And claims like "The AI colony ships knows where good planets are" are so annoying because first, it's not true and secondly, even if it was true, it's such a trivial advantage compared to the real tough stuff that players take for granted.  As most veteran GalCiv II players can tell you, they typically out-colonize the computer AI because human intuition is better than simulated intuition anyway and that would still be true even if it knew where the best worlds were.

But let's say that the game cheats. Let's say it cheats like crazy.  That would put it on par with pretty much every other strategy game out there.  Hearts of Iron 2 is a really good strategy game isn't it? Very popular in Germany?  Yet its AI isn't even remotely playing the same game as the human player. Does that make it a bad game? No. 

The reason Galactic Civilizations II's AI doesn't cheat isn't because it makes it more fun or it's a good marketing tool, it doesn't cheat because for me, as a developer, the whole point of the exercise of writing a strategy game is to write the AI.  That's why our graphics usually suck in our games because I tend to only care about the computer AI.  

The point being that there's no real business justification for me to be coding on the game other than I love coding computer AI.  It's what I love to do.  I love hearing about other people's strategies. I love making tweaks and enhancements to the AI.  I love adding in new features.  But I also get very annoyed when some user or "reviewer" makes "it cheats" claims without even talking to us.  Odds are, they either misunderstood something.  But let's say they found a bug (which isn't likely but for the sake of argument) unlike the AI, we're only human. Who knows, I could make a mistake.  The AI doesn't escort its ships as well as I try to code it, it's possible that I missed something.


Comments (Page 2)
5 Pages1 2 3 4  Last
on Mar 31, 2006
Waitasecond... people can beat the game on inteligent?
on Mar 31, 2006
Waitasecond... people can beat the game on inteligent?


lol, unfortunately yes, the AI is very beatable. Leaving out all the the 'cheap' methods, it is due one part to trading, and the other to starbase deployment. If you master these two facets of the game, you will dominate the incredible AI even with its 200% economy. That's why so much work has been done towards them. They are still not perfect yet though, trading is better, but they still like to ram paper-mashe fleets into brick walls.
on Mar 31, 2006
The one about trade really burns me up to no end too. I thought it (the game was fine where it was) didn't need any changing. What I thought was a shocker that late game minors that "appear" have all the techs. Other than that. I didn't care if the AI traded or no. I didn't trade it my weapons techs thats for sure. When I did make a trade I thought I got a fair shake, now I'm fairly sure I get shafted everytime a trade deal is made (either the computer AI offer or what I have to add extra to get a trade ). Ugh.


I am so glad that someone agrees with me on this. I had a rant about this before because I was tired of everyone saying that my favorite part of the game was "cheesy". (And really it was only 4 or 5 guys saying it, but saying it all the time.)
on Mar 31, 2006
Spin-center or whatever its called needs to be pushed back farther on the diplomacy techs or make it farthest on the planet defense tech.
on Mar 31, 2006
Good post , i sure dont mind hearing about this gosu AI...also didnt know how much cheating the AI does in most games. Thats just lame.
on Mar 31, 2006
I love this game because the AI actually plays a fair game. I hate playing single player strategy games against "cheating" AI's. I can do it a few times, but the replay values go down because of it. I am more of a "make the AI better at reacting to exploits" than to "nerf the abilities". Maybe this is because I work in a field where I need to design things to defeat something that I cannot control. The threat could always change, so our "systems" need to adapt. You could just make the threat go away, but I find it better to just get better at defending against that threat. This is why I loved C&C better than Red Alert, because they were not extremely balanced, but you could defend against anything if you put the work in.
on Mar 31, 2006
Just expand the minor race AI... they are sitting ducks...

thank you.
on Mar 31, 2006
Don´t worry, the writers at that magazine are able to speak and read english... we already provided a link to Brads response on the forum, I guess we´ll get some sort of answer on monday.
on Mar 31, 2006
Hi Brad, great journal entry. I was wondering is there chance of another difficulty level beining added in a later patch that stands between Genius and Incredible, perhaps with a 160% bonus.

I'm currently finding crippling level (Genius) too easy but going up to Masochistic (Incredible) is a big jump. A level inbetween would make the jump up much more fun and not immediately overchallenging.

thanks

Lenius.
on Mar 31, 2006
"without being scripted"


This point seems to keep getting lost in the noise - The fact that you have taken one or two steps back from the actual playing of the game and analyzed the PROCESS of playing so that the AI's go through the same decision process that the human player does (and generally better than the human )
1. keeps the game experience fresh, since the computer will react to the single game situation,
2. reduces the probability of a game wrecking exploit,
3. and in general puts this game head and shoulders above most of what is out there.

Are there things that the AI does that are unintended and overall detrimental to its cause? Yeah, probably - but I can say the same thing about my gameplay, too. Just like in GC1/AP, I feel certain the AI will get better as folks post to the metaverse and any AI "goofs" are analyzed and corrected.
on Mar 31, 2006
Honestly, to me, the principle problem with the AI is the diplomacy system.

When it comes right down to it, the diplomacy ability is effectively game-sanctioned cheating (though rarely in their favor). If the AI is supposed to behave like a human, why does it respond favorably to an otherwise useless number in the Civilization manager?

If the AI is going to play like a human, it should play like a human. It shouldn't do something that's patently against its better interest just because you researched a couple techs. Now, giving the AI gifts, or making trades in the AI's favor should certainly win you points (as it would with a human), but there should be no way to trick the AI into stupid moves because of it.

It is also the reason why the game can't work multiplayer. Your diplomacy ability means nothing to a human, so that entire tree of techs is utterly useless against them.

The diplomacy ability causes the game to have a game-sanctioned mechanism for taking advantage of the AI. The computer AI and the player are no longer on the same page, because the diplomacy ability doesn't affect the player the way it does to other AI's. It is an ill-conceived idea.
on Apr 01, 2006
In the development journals, we talked about the goal of having the "intelligent" AI being able to beat 95% of players. I think we succeeded. In v1.1, our goal is to maintain that 95% (as people get better at the game some will eventually be able to beat the "intelligent" AI so we have to evolve with them).

What makes you think that it can actually defeat 95% of players? That sounds way too high to me. Once a player learns the mechanics of the game, the AI doesn't seem hard to beat.

on Apr 01, 2006
Once a player learns the mechanics of the game, the AI doesn't seem hard to beat.


....Says the man who's won games playing on Suicidal. Just because you can beat the stuffing out of the AI doesn't mean the rest of us can. Yeah, I know there's a number of really good players here besides yourself, BladeVenom, but I'm pretty sure you guys are still a small percentage of the overall fanbase. I myself still lose on Normal, and I don't think I'm the only one who can say that. I have yet to hear very many people claim they can regularly beat the game at difficulty levels higher than Challenging. (Sorry, I'm not trying to sound like a smartass; I'm just saying.)

By the way, great work on the AI, Brad. I know the praise you receive for it is often drowned out by complaints, but I can assure you I (along with most of us here) truly appreciate the effort you've put into making it great. I've never played a strategy game--particularly a TBS game--that has given me this much of a challenge before. It's nice to get my butt whipped and know that it's not because the other races had artificial bonuses.
on Apr 01, 2006

What makes you think that it can actually defeat 95% of players? That sounds way too high to me. Once a player learns the mechanics of the game, the AI doesn't seem hard to beat.

Even in 1.1?  You shoudl share your secrets. I can no longer beat the AI on Genius level anymore. 

I suspect that there are specific techniques that work in specific galaxy configurations. 

on Apr 01, 2006
Hi!
Claim: "The AI knows where the good planets are".

Bah! I'm pretty sure AI says that for me, as I usually manage to beat them in the race for the best planets. I too do blind exploration, however AI does that with scouts, and I with colonizers. So far I haven't build a single early game scout. There are two main reasons I don't do that:
1) a scout can have only two engins with range-extenders - too slow compared to my colonizers that have 3 with range-extenders, or 4 without them (playing as Yor helps here tremendously )
2) a scout costs about 50% of a colonizer, but each turn I produce a scout, there's a half of a colonizer less produced, and that easily means one less good planet settled. It doesn't matter if I know where good planets are, if I can't get them faster than opponents. Despite scouting with colonizers is more expensive, it makes that approach possible.

the AI may know where galactic resources are. I say that because during the beta, galactic resources showed up on the mini-map. IF that's the case, we'll likely have galactic resources show up on the mini-map again

Erm, I have mixed feelings about that. In huge universe the minimap isn't so usefull anymore. Heck, I've missed to spot whole stelar systems on the minimap! (DreadLord's system in campaign) How the h... will I spot a tiny pixel of a single resource? Please avoid that, or make them also visible through the FOW on the main map. That would also come handy for stars. If we see them on minimap, should't ve see a representation of them on the main map too? Since they give off some light, IMO we should be able to spot them in the empty space.

AI at Genius and Incredible is getting advantages over the player and has always been stated as such.

I don't have an issue with that, when I specifically decided for that when setting up a game. What I'd like to see is all those bonuses are visible to us. In my current beta game on masichistic I especially remember one arceans' fighter changing its course to intercept my transport, that was "hanging" some 8 parsecs away, but the scan range on that fighter was still stated as 2 parsecs! Also, when I check the stats of other races, they're quite similar to stats of my race (like econ +70% to +110%), but despite I have twice their pop, they have up to three times my economy. Please make those numbers they operate with transparent.
{rant} And please make game give an explanation to those jumps and falls in econ stats: somewhere around turn 100 ALL AIs got an increase in econ by about 10%, but not my race. Around turn 130 my race's econ fell down ~20% without single lost econ base or trade ship, or having a trade line discontinued, without any event, without me touching the tax slider (not for last 80 turns!). WTH is going on?!? I know I'm playing a masochistic game, but I'd still like to see a notice, even in the form "You're playing a maso game and not losing, so your base tax ability is decreased by 20%!" {/rant}
BR, Iztok

5 Pages1 2 3 4  Last