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 5)
5 PagesFirst 3 4 5 
on Apr 10, 2006
They killed the edit button?!?!
on Apr 14, 2006
I've noticed that as long as you're military is lower or equivalent to another civs military, they'l employ hit'n'run tactics and generally try to attack you, though after you've started creating really powerfull ships and military, then the AI seems to know it can't beat you, and avooids your sphere of influence like the plague... allowing another more powerfull civ to try their luck! correct me if I'm wrong in this. I've been engaged in a long drawn out war with the Thalans, and finally conquered them, as soon as I did, the Yor, which were my other warmongering neighbours decided to stay out of my sphere of influence, even though their ships could and did destroy mine when I tried to invade them!
on Apr 14, 2006
One thing I noticed that the AI does NOT do well is selecting planets to colonize.

I have notiuced too many times a system with multiple inhabilable planets and colonies on the LOWEST class ones.
on Apr 14, 2006
I don't like how tech trading is implemented in this game, but it is not a problem because i'm losing or because AI is cheating; the problem is that i don't want to be FORCED to tech trading every 4-5 turns.I must say that things after recent patches and betas are a lot improved about this problem but in my opinion tech trading is too powerful.Playing as humans i have found that with their bonus at diplomacy with diplomatic translators and galactic bazaar i could really trade for 1 of my techs nearly 8 techs.Anyway the game is improved, before patches were released, for every tech researched i could get 4-5 tech by trade, now it is 1 tech researched for 2 taken by trade (which is also too much).
I think so that the problem is not the AI but the fact that the tech tree is a very great and what could really improve tech trading is some new options as you can trade only tech you researched which is a mid measure between no tech trading option (diplomacy broken) and tech whoring.


I find this to be far more realistic. I mean, did Germany design the microwave from scratch after it was discovered to cook in the U.S.? When Britain figured out how to make radar, did the U.S. have to go through all of the same research to find out how to make it? The answer is no. The difference is that this game doesn't follow the same paradigm of every other game (Forcing to player to do everytihng themselves, when in reality there would be some help), and it actually tries to similate what actually would happen. I like the way it is, and I don't like the way other games do it. I understand it is out of your comfort zone, but it is probably the right way of doing it.
on Apr 14, 2006
.
on Apr 14, 2006
The AI is pretty good. I find myself beating it on "Intelligent" level with increasing ease though. I am not sure if it is the tweaks they've made or if I'm just getting much better.

However, I am certain that the tweaks they made to the Approval and the taxes is rediculous. I can have 85% approval with 65% taxes!!!! This makes me able to dominate more. I like the old tax-approval model where I had to keep it at or around 40-45 to avoid a shrinking population, this really made the game a lot more challenging. I am not sure if this is an advantage to the player, because I guess the AI also gets the benefits of the higher tax rates to.

Strange that at the end of a game though, the AI usually has a MUCH lower average tax rate than me. Maybe that is why they lost?

I think this is an area of the AI that probably should be looked at. My two cents
on Apr 14, 2006
Crap sorry to do this.. but I forgot to add something to my previous pose and I can't edit it.


The AI are wusses. They need to explore the options of Joining together to attack the player. I find that once I build a military that is stronger than each individual AI, they all become scared little wimps afraid to fight me, and I just sit back building my military slowly, while researching HEAVILY and by mid game I'm so far ahead of them that they can never beat me.

The AI should gang up on you. The manual says that when the player is EVIL the good races will rally against them, but that never happens. Ever since I discovered that EVIL IS THE BEST ALIGNMENT EVER. I always go evil, and these wusses NEVER gang up on me. They just cower in their SOI until my influence consumes their planets and my armies slaughter their people!!!

I play on intelligent in a gigantic galaxy with all races. I use only the Terran Alliance. We're always evil, and the enemy never gangs up on me. I wish they would, then there would actual be a disadvantage to being evil, because as it stands being evil has the most percs.
on Apr 14, 2006
I agree. Once one race starts becoming dominant, then the other races should try to be their ally, or form a coalition to oppose them. They do nothing, and seem oblivious to the fact that they are going to be the next race conquered.
on May 01, 2006
I would also like to know the answer what actually Gifted difficulty means (between Genious and Intelligent).
on Jun 03, 2006
Heres an example of a well formed early game attack it would be cool to see the AI use:

Have small size ships with 1 attack and 1 defence, the rest is engines (2 warp drives is what I like to aim for). No other components. 2 or 3 fleets of 3 ships (10 logistics) is good. Have a large number of transports, enough to take out a few worlds. (1 transport module the rest engines). Have about 8 constructors (constructor module, rest engines).

Have them all in 1 big group and move to a spot where you can build a military starbase that covers a few enemy planets. Build the base and instantly upgrade it to have protection fields and the attack assist upgrades, along with some basic attacks so the base can defend itself if needed. This turns your small ships into attack 5 defence 4 juggernauts. Have the transports and at least 1 (preferably 2) fleets sit at the starbase to guard it. Send your other fleets to sweep the area in the bases radius, targeting enemy military starbases first. If there is an enemy starbase then place your starbase so the radius's overlap.

Once a planet has been cleared of defences, send in the transports in big fleets to conquer them. They should be able to travel from the starbase to the planet in 1 turn with the big engines on them.

If range is a problem for getting to the enemy, build starbases to extend range. A 1 constructor starbase is fine as they aren't often detected and it doesn't matter if they get destroyed once the military base is up.

The AI shouldn't bother with defence, but if it wants to be at peace then having military bases protect all of their planets is a great first step. Then a full fleet on each starbase and a full fleet on each planet (no more). If there is no orbital manager then don't bother putting any ships on defence its completely pointless. Having scouts (cargo ships filled with sensors and engines) getting rid of any fog of war can help it decide if planets need defence or not. Having everything on attack is never a bad idea though especially against a stronger enemy.
on Jun 03, 2006
.
on Jun 03, 2006
You said "In the development journals, we talked about the goal of having the "intelligent" AI being able to beat 95% of players." Bravo. AI =6, me = 0. I'm not that good a player yet, granted but so far I've been thoroughly spanked everytime. Hopefully, I'll get the me = 1 before the AI gets the AI = 19. So far, it's not looking to good.
5 PagesFirst 3 4 5