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 4)
5 PagesFirst 2 3 4 5 
on Apr 03, 2006
How about just leaving all bases there? Then players would have to do a clean-up after capturing the planet. How about negative morale? I'd be nervous being on a captured planet while enemy base and ships are still around it...
on Apr 03, 2006
Since planets are so valuable and fleets in orbit can't defend them well

Well, you need a specific improvement for having orbiting ships acting as a fleet.
on Apr 03, 2006
We have an additional difficulty level in the game, not listed in the manual, which is Gifted ( between Intelligent and Genius ). I didn't find any info and pardon me if it's already stated, but what is the Gifted AI' economy bonuses?
on Apr 03, 2006
Posted by draginol:

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.

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.

on Apr 03, 2006
Well, you need a specific improvement for having orbiting ships acting as a fleet.
Planetary invasion comes before planetary defense. Usually I've already conquered 2 other races before anyone has one built. Even after they've built planetary defenses the A.I. doesn't keep enough combat ships in orbit to stop more than one enemy fleet. The AI usually keeps more noncombat ships in orbit than combat ships. Most of his combat fleets are out of your way and never even matter.


on Apr 04, 2006
*furiously takes notes*

Felk the Studious
on Apr 04, 2006
Baloney! Fair trading practices can include diplomacy skills irregardless of it being human or AI. How? by the same +% related to the skill.


Just so that I understand this correctly, you're suggesting that the game somehow force human players to make trades the same way that the AI makes trades. IE, force human players to use the same system for trading that the AI does.

Your entire argument is based on a certain presumption: that a technology or whatever can be boiled down to a number and evaluated.

Not even the AI is that stupid. Even the AI knows that it shouldn't trade high-grade weapons tech to anyone, regardless of how much you give them or how high your diplomacy rating is (though, your diplomacy might be able to break it if it is high enough). A human player is capable of evaluating things a lot better than some rudimentary mathematical algorithm. It understands that it shouldn't trade "Research Centers" or industry techs to the guy with 4 planets, because those techs make this insignificant civilization much more dangerous, even more so than trading weapons technology. At no time would a human player do such a thing, unless the deal was really good.

Forcing the human players to accept bad deals just because some braindead algorithm says that its "fair" is bad gameplay, plain and simple. I'd certainly hate to be the human on the other end of that deal.
on Apr 05, 2006
Generally I play a game to play it--not to win it in the shortest amount of time possible. This is why games like starcraft always bothered me back in the day because I'd like to build a fantastic empire of buildings and such and spend time making my units the absolute best--and only crush others for good reason.
So I usually settle for the Civilization-type games instead. But, those games too aren't too good for the long-haul. The AI is somewhat nonsense for the most of the game and toward the end it just seems to get tired and stops doing much of anything. I've actually played to the point of nearly beating a civilization and then I leave them just a city or two, make them my 'protectorate, and do what I can to make them powerful. And they just sit there doing nothing. Worthless.
I like GalCiv2--and I never played (or heard of) the original. I just happened to have a best buy gift certificate and decided I needed a break from classes now and then. This game got insane reviews, so I've been enjoying it.
I'm usually not too big on a lot of fighting because it's kind of a hassle. I enjoy the politics of the situation (big maps, lots of players, lots of interactions). In my current game I've been playing the Thalians in a very long 'cold war' with the Drath. We share a long border, have a lot of units stationed not too far away (but not too close that it seems we're preparing for invasion. In fact, neither of us have much in the way of transports--just lots of evenly matched ships. We trade too much with each other and (although there are no real alliances yet), we have too many 'complex' relationships to go to war. We just, now and then, build an influence starbase in a threatening location, or send some scouts to chill next to a major planet. It's fun. It's a lot of fun, actually.
Thanks for making a game that's fun to play, not just to beat.
I would never say it's cheating--cuz in the 2 or 3 different campaigns I've played, I generally do okay. In one I barely even had a military, but I concentrated so hard on trade and industry and just being everyone's friend that just about civ was willing to protect me against anything.
What would really be interesting though, and this is impossibly complex and won't ever happen, is if there were more "real-universe" economic issues. Just some basic inflation, unemployment, foreign worker policies, exchange rates...but that's nuts.
Maybe make the minor races a little better--if some of them are clustered near each other, have them create some type of federation and get a seat on the UPN.
on Apr 05, 2006
It's a herculean challenge. I think there are some legitimate criticisms to be made about where the AI's at now--it compares very favorably to other games, it's true, but it doesn't yet measure up to either its hype or its tremendous potential, in my humble opinion. I don't feel it's accurate to say that the AI is good enough yet to beat 95% of players, but it's no question that it has taken some big strides towards being the kind of game that defines a genre.

Two quick things: What are your thoughts about opening up the inner workings of the AI logic to the modding community at some point in the future? It seems to me like a win-win situation. And second, it may be fruitful to consider numerical approaches to optimizing the AI, especially for fine-tuning parameters. A variety of global optimization algorithms could be used in an iterative optimization process with a computer-vs-computer simulated game as the inner loop. Well, something to think about, maybe.
on Apr 06, 2006
I just attack first, go after planets not fleets, and target all his planets at once. My wars usually last 1 turn.


Easy on a Tiny map - go try it on a gigantic where your opponent has got 30-40 planets spread across 20 sectors.
on Apr 07, 2006
its been my experiance that the AI is all over the map so to speak. im alot like Corsulian in my game play style, i play in mid size maps with scarse stars but lots of planets, usualy 5 civs are my stock compitition, 3 of the 'evil' races and 2 other 'good' ones to compliment me. but my 'challange' in the game now is to set up and actual galaxy along the lines of start trek or starwars and so on, not C&C in space. i play as normal AI levels and i find that if i really want to i just blast up the research chain to planet invasion and i can just sweep the field of the evil civs in no time flat. i get much more of a challange out of trying to keep ALL the other AIs in the game.

this is what i mean about the AI being all over the map. one game one AI dominates, the next its another one, the 3rd they are all just wandering around bumping into things and the 4th they are in a giant free for all. and ive found afterwords that its generaly all due to what planets they start out with. the one map i recall that the altarians kicked ass they had two double production tiles on their planet and they made full use of them, another i couldnt figure out how the yor of all races were out researching me (im a big tech player) only to find out after a long war that their home world had 3 double research tiles on it and i only 'won' because they striped 2 of them out for planet defences.

what i dont understand about the AI is the stress on war, why? ive had games where literaly 20 turns in all the AI is at war. and declarations of war make no sence alot of times. ive had 'good' races on the other side of the map who cant even get to me (i play humans usualy) declare war on me, whats the point? i mean i can understand if im altarian, and next door to the drengi, and have no fleets at all, that the drengi might try their luck. but on opposite sides of the map and both of the same general alignment (human and torians)? crazyness.

the only thing that really bothers me though is like Corsulian said, in late stages the AI seems to go out to lunch. ive had games where they were 'at war' with one another but didnt do anything. huge fleets of ships just seting one square away from each other and nothing, no movment, no attacks. nothing. only thing i can guess is that they are wating for me to make my move as the 800lbs monky in the bath. by this time one of my 3 ship 'fleets' can (and im tickeld to say does) clear the map of everything.

perhaps its just an outgrowth of the AI gives up when its out matched that was part of GS 1s AI. but i tryed an experiment one time. played a game to the latest stages, only thing i didnt research was tech victory, only had the drengi the altarians and myself left , about the same size in planets and so on, anyhow i gave the altarians all the techs for defence (all 3 branches) and all the laser techs through doomray, gave the defence techs to drengi along with the missle tree and used mass drivers myself, i ALSO gave them all the non millitary techs, everything. and ....... the AI still just sat there. even after 300 or 400 turns for all the planets/ships to be upgraded. by rights it should have been a hell of a fine battle. but nothing.

i guess they just gave up way back when and couldnt muster the gumption to take on us monkey boys in a free for all

well its good for what it is but its certianly no M5 (star trek the original series for those that dont know what an M5 is)
on Apr 08, 2006
Easy on a Tiny map - go try it on a gigantic where your opponent has got 30-40 planets spread across 20 sectors.

A bigger map doesn't make the game any harder; it just makes the game last longer. With bigger maps, the A.I.'s slow ships are even worse, and gives you even more time to react.
on Apr 09, 2006
I think this is an interesting line of posts.

The AI doesn't "cheat," but think about how the AI must be programmed.

How does the AI evaluate the skill of the player? That is a critical analysis when a race has to determine the threat level of a civilization.

From what I've seen, the AI assumes that the player will be a stronger threat than the other nations, and the player is more likely to affect global AI patterns. I've noticed that even before I start attacking any particular civilization, if I research "expert logistics" before they have "enhanced logistics," 3 or 4 of the 9 will begin researching logistics. Why? To prevent the player from romping through the galaxy with equal ships, but much larger fleets.

Bottom line is that I think that to program a game like this, the computer must evaluate the "human" player as a greater threat, because humans have built-in "advantages" and "capabilities" that aren't mentioned in the stats: innovation and creativity, "Creativity" in a real sense, not "+25%." So the AI, as a conglomerate, has to treat the human as a greater threat level, in terms of strategic decisions. The "diplomacy exploit" is an example of this.

Now, in terms of economic modeling. Whether or not it's worth it in real-life, real-time to spend two minutes tweaking each planet and adjusting the sliders over a 10yr game in order to have a shot at beating "suicidal" is where the real challenge comes in.

But it's very difficult to imagine the developers treating the human player as "just another race/civ," and although it doesn't cheat in terms of statistics, you can think of the AI as a conglomerate of states with individual interests, kind of like a country with different states, who view the player as more dynamic threat. So the computer doesn't "cheat," but it does evaluate player decisions differently than an equally powerful civilization. It has to do this to keep the game fresh for the player, and to compesate for a key flaw in all AI in these games: the AI doesn't doesn't "learn" from the previous games that the player has played, since it has no "memory" of it with every de novo start.
on Apr 10, 2006
You forgot one more item. The AI has to do all that FAST. Not many folks would like waiting 5-10 each turnn on the AI!


I wouldn't mind waiting that long if I knew it meant an AI being able to actually beat me, maybe a setting how much time you give the AI (instead of the suicidal level) is possible some time in the future? I know a chessgame that has that (but chess is a lot less complicated for an AI of course).

But the suicidal level is giving me a reasonable challenge at the moment, better than most strategy games so far, I really like it. Too bad the suicidal setting IS cheating, but I take it the AI is using the same intelligence as on genius so I guess it's just the nessecary boost in difficulty that's needed to give me that extra challenge



on Apr 10, 2006
... I take it the AI is using the same intelligence as on genius so I guess it's just the nessecary boost ...


I meant incredible level, not genius level.


Why is there no edit your post button?

5 PagesFirst 2 3 4 5