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 3)
5 Pages1 2 3 4 5 
on Apr 01, 2006
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.


I know I bugged you about this a while back on the news group, but I really feel like this is a design decision you should reconsider for GC3. The fact that open space makes it easier (though more tedious) to manage your fleets tactically vs. the AI is a big weakness in making the miitary aspect of the game that much easier. Combine this with the absolute advantage that being able to attack gives you really presents a challenge for the AI.

If you went to a wormhole setup ala SEIV then you would still have some open space for resources/anomolies (though honestly in GC2 anomolies don't seem all that interesting anyway, or far to ocrazy with the luck ilke the 2500BC presents...) and also choke points which would make it easier for the AI to defend its 'area' of space.

Another alternative is to add another command for ships/fleets. Call it 'intercept' and assign so that the fleet will automaticaly move to 'intercept' any ship/fleet which enters its interception range. Of course this is tricky as you would have to add some logic in what it considers a target worth intercepting, or just make it so that after the first interception (assuming it is succesful) it is allowed to intercept multiple times (perhaps tie this to logicstics tech). This way the defender isn't such a sitting duck.

Hmm, you could even arrange it so that the interception ships have special engines, which control the interception range, but they can only move 1 space per turn normally (+speed boni). That way there is a strategic cost associated with using those ships.
on Apr 01, 2006
Good stuff. I for one get tired of arogant crybaby losers who have such a high opinion of themselves that anything beating them - human or computer - MUST be cheating. Not just on this forum, but all over the place. Although this doesn't help with the latter, at least this is something to point the former to in a hope to get them to actually think.



Anyway.... very glad that you do these journals. It's so much better to see and read about the internals of a game and what goes on behind the scenes than it is to just buy a box and that's the end of that. I enjoy them almost as much as the game itself.
on Apr 01, 2006
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.


I saw no noticable AI changes from 1.0X to 1.1beta. If anything, the game is easier, due to social production not being such a sinkhole.

Use military stabarses and you'll wtfpwn the AI.

on Apr 01, 2006
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.


I just attack first, go after planets not fleets, and target all his planets at once. My wars usually last 1 turn. Is the computer in 1.1 any better at detecting enemy fleet build up? I keep my transports outside of his sensor range, and the computer never sees it coming till it's too late.
on Apr 02, 2006

I just attack first, go after planets not fleets, and target all his planets at once. My wars usually last 1 turn. Is the computer in 1.1 any better at detecting enemy fleet build up? I keep my transports outside of his sensor range, and the computer never sees it coming till it's too late.

If you were the computer, how would you counter that? I.e. think of the AI as a human player, what's the counter to a sudden, massive sneak attack?

on Apr 02, 2006
The human counter to that is ....menu.....retire.

-Chris-
on Apr 02, 2006
Same tactic is popular in moo2 multiplayer (late game). The usual counter is to research warpfield interdicters beforehand.

Warp Field Interdicter: Creates a warp destabilizing field around the star system in which it is built. Generates a field 2 parsecs in radius about the system that slows all enemy movement to 1 parsec per turn.
on Apr 02, 2006

If you were the computer, how would you counter that? I.e. think of the AI as a human player, what's the counter to a sudden, massive sneak attack?


Perhaps the AI's could build cargo ships full of sensors or use scouts and locate them in places where an enemy might attack. If it sees a build up of fleets/transports then it should declare war.

Poss hard to code but i wouldn't know...

Lenius.

on Apr 02, 2006
I love the AI in this game. Sure it needs more work in diplomacy, but it is a clever bastage. I play on tough right now, may step up soon one more notch.

I was having a fine time in my last game, zipping up the Mass Driver Tree and holding off the hordes and expanding, when the Arceans attacked with ships specifically designed to counter my ships. I was too dependent on the Nano Ripper, and enjoying it. But my Frigates and Heavy Fighters with 18 attack were suddenly useless against the Arceans with 30-40 MD defense, which were also sporting some new nice missiles. I went from owning, to having the second largest fleet that was completely useless against the largest fleet that was heading in from the south.

The Arceans didn't simply turn to a new technology in their counter. They had to analyze my ships & technology, research defense techs, miniaturization, engines (I didn't mention they got substantially faster) + effective ship design + upgrading their existing fleet.

I did manage to survive, counter and am handily winning again. But it was touch and go for a bit. I also had to yield beating them on my own, and form an alliance.

How great is it that the AI actually counters real time situations so effectively?

ty
on Apr 02, 2006
The AI in the latest beta does a decent job escorting except for one thing. There was a thing put in to keep AI from upgrading escort ships to attack ships. But the problem is the AI doesnt upgrade the escort ships. I keep running into escort ships with only one point of attack so late in the game htey cant get past my shields! So you might aswell not escort at all.
on Apr 02, 2006
Hi!
If you were the computer, how would you counter that? I.e. think of the AI as a human player, what's the counter to a sudden, massive sneak attack?

There's no counter for such kind of attack, if you allow an opponent to organize it. And here's the catch: a single scout can ruin such a sneaky plan in a single turn, when it spots the (hidden?) incoming fleet.

just attack first, go after planets not fleets, and target all his planets at once

Visit us on starsautohost.org, and try such a tactic in a Stars! game against live opponents of your skill level. Then you'll see how it works (or doesn't ). Here on GalCiv2 you can try a bit bigger universe with more than 10 livable planets to see the same effect.

BR, Iztok
on Apr 02, 2006
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.


Baloney! Fair trading practices can include diplomacy skills irregardless of it being human or AI. How? by the same +% related to the skill. For example you have a scale of 11, indicating the fairness of a trade. (imagine the attitude indicator on the diplomacy screen)
0 1 2 3 4 5 6 7 8 9 10
-------------^---------------
-------------*---------------
This example would indicate a 5^ trade rating, at which all things are traded equally. If you want a tech that is valued at 25 points*, then you have to offer something worth 25 points to get a green responce. If you offer 20 points, no trade. if you offer 30 points, the 5 surplus could be used to increase relations. The * slider would show how close you are to a fair trade (do I need to add more techs, or would a couple of credits balance things out).
*********
0 1 2 3 4 5 6 7 8 9 10
---------------^------------
---------------*------------
Here my trade indicater shows I have a diplomatic edge of aprox 10% (5 diplomacy skill+5 relationship bonus). Now I can get the 25 point tech for 20 points offered, because of my skill and how much these guys like me. (more willing to help a friend out).
*********
0 1 2 3 4 5 6 7 8 9 10
---------------^------------
-----------*----------------
same as above, but my offer is a little light. Need to add something to my side line up the carrot and asterix to "green" the deal.
*********
0 1 2 3 4 5 6 7 8 9 10
^---------------------------
----------------------------
At war. about the only thing I can do here is gift them something in hopes of raising relations to make future trades possible.
**********

Of course this would need balancing and is only conceptual. But applying fair trades when dealing with the AI or human is possible, and still include diplomatic skill application.

War time modifiers could be added to appropriate techs. I want to trade xeno farming for laser 3. For example sake say they both have the same base value of 50. The AI looks and sees you are currently in a war with another civ. Because of the urgency of that, the cost for trading is +20% military techs. So now I have to up my offer an addition 10 points as it's apparent I need the laser 3 NOW. Supply and demand.

Modifiers can be applyed to all areas. Want xeno farming in trade and your empire is larger that theirs, expect to pay a premium for it. If they are larger then keep it at balanced levels.

Of course you would use a scale much larger than 11. It was only for the example.

Trades would be fair all things considered, diplomacy would be applied to the one area it is suppose to affect, and it would not matter if your trading with an AI or human.

Seriously doubt this would be a "patch" item. but there it is nonetheless
on Apr 02, 2006
Some great information in this journal entry and it really makes you appreciate how much the AI has to "think" about when playing the game. I'd like to give my thumbs up here for the AI as I think it plays fantastically well. It's true that in most strategy games the only reason the AI is a challenge is because it is heavily advantaged, and I reckon it is a wonderful achievement that unless you play on a very high difficulty level, the AI is on an equal level with you( in fact it is even handicapped on normal difficulty) and it plays a good game. The only suspicious activity I have seen with this game in terms of cheating AI is that if you place a survey ship on auto survey it will instantly head towards anomalies that have not yet been found, something I hope gets fixed eventually. Since the player can also benefit from this though you can't complain that the computer players get any advantage from it.
on Apr 02, 2006
If you were the computer, how would you counter that? I.e. think of the AI as a human player, what's the counter to a sudden, massive sneak attack?


As already been stated, use sensor ships or scout ships so you see the build up, and strike at the transports with faster ships. I always try to be the one to attack first.

I think the game mechanics favor offense, with no borders, no zones of control(my transports can fly right past his fleets and be side by side with them while I invade), planetary invasion tech coming before planetary defense (once I get invasion tech I'm already planning my attack), and attackers having the advantage. I think the best defense in the game is a good offense.

Edit: Another thing that makes going for planets so good is that his fleets and starbases just disappear after all his planets are captured. Their mass suicide is very convenient at harder level when they still have a bigger military than you do. Another thing a player does that the AI doesn't is when they are not at war, a human player will put excess population on transports. That would allow for a counterstrike. As long as they have ships, and starbases perhaps they should be allowed to fight on.
on Apr 03, 2006
Hi!
Another thing that makes going for planets so good is that his fleets and starbases just disappear after all his planets are captured.

I agree. I try to avoid taking out their armed/armored starbases, as they usualy inflict too much damage on my attackers. I need them for clearing defenders on planets. When I destroy/capture enough of them, the AI surreneders, and all their bases are belongs to void.

Since planets are so valuable and fleets in orbit can't defend them well, I'd really like to propose some better defense for planets. Like a single starbase over a planet, that would have to be destroyed before planet could be invaded. That would make early planet-taking MUCH more difficult / costly than it is now.

BR, Iztok
5 Pages1 2 3 4 5