Introduction to GalCiv III AI Talk

I've created a new sub-forum here dedicated to talking about GalCiv III AI. Because of our forum system, active posts here will float up to the top so you can see this post from the main forum too.

A big welcome to GalCiv III fans or future AI game developers!

## AI Background ##

GalCiv III is the first of the GalCiv games where I didn't write the initial AI for. This has turned out to be a good thing, something that we will all benefit from for years. But in this section, we'll talk about what this means.

Unlike the previous GalCiv AI's, this one is data driven. That means most of its intelligence is derived from XML files in the game directory. The team implemented the AI as a huge library of APIs that use this data and make very simple decisions with it. Because the game is 64-bit and because each AI player gets its own thread, there is a huge amount of built in potential to do some amazing stuff.

In late March of 2015, I finished up my main work on Sorcerer King and began to look at the AI for GalCiv III. The primary strengths in the AI are what I just described. However, it has some weaknesses too which revolve mostly around not being very good at PLAYING the game.

To use the Chess metaphor, the GalCiv III AI at the 0.80 level (March 2015) knew how to play the game. It just didn't know how to play it well yet. That's where I came in. My pre-release work consisted on making the AI more skilled in playing actual humans.

If I were to rate the GalCiv AIs over the years, and this rating changes a bit based on how I"m feeling that day I'd rate them as follows where 1 is brain dead and 10 is the absolute best AI a game can have.

GalCiv OS/2: 8

GalCiv I for Windows: 7

GalCiv II: Dread Lords: 6

GalCiv II: Dark Avatar: 8

GalCiv II: Twilight 7

GalCiv III: 1.0: 6

## AI Expectations ##

Anyone who has had to deal with me on forums knows that I have very limited patience for arm-chair AI designers. I'm old and cranky. If you're participating in these discussions, here are a few ground rules you need to understand:

1. Nearly all players play at either beginner or easy. And by nearly all, I mean 90%. This has always been the case and will always be the case. So feedback or suggestions that involve affecting those players negatively or spending a vastly disproportional sum of money and time on some AI idea just isn't helpful

2. Unless you've programmed AI, feedback suggesting new APIs isn't really helpful. Every AI discussion always has people suggesting things like "The AI should be able to detect threats" or "The AI needs to build better fleets" or "The AI should reinforce planets that are endangered" as if these features weren't in the game before I showed up. That's the most basic stuff. The aI fails to do those things because something else happened and our job is to figure out what happened that kept it from doing those things.

3. Extreme exploits aren't going to be fixed. Most people who win the game are taking advantage of some level of exploit. That is fine and we can, on a case by case basis, determine which ones we should address. I tend to fix exploits that are too tempting to ignore. If the AI is making bad trades, for instance, that's something that should be fixed. But if someone has figured out that they can kite some unit in tactical battle for 45 minutes doing 1 damage per turn until the monster is dead I"m not going to fix that kind of thing. Kite away, my friend.

4. My near time objective is to get the GalCiv III AI up to a 7 and later an 8. It is extremely unlikely I'll be able to get it to a 9 on my arbitrary scale because it's not commercially viable and I've never seen a game reach anywhere close to a 9 and only one commercial strategy game has reached an 8 besides Dark Avatar. Most PC strategy games are less than a 6 and provide their challenge through actual cheating AI which is much cheaper and often more fun for players anyway.

5. Understand what cheating really is. If you get a handicap at bowling or golf you are not cheating. If you get to walk up and kick down the pins you are. People throw around the term "Cheating" so lazily now that it's having a negative impact on the incentive to actually make good AI. The AI in GalCiv does't cheat with 1 exception: On the higher difficulties it doesn't have FOW (and even that is something I'm looking to get rid of). Giving an AI a handicap (i.e. every credit it makes is matched by another 0.25 credits) is not cheating, it's a handicap. If the community ever reached a consensus that giving the AI a handicap is cheating AND felt the AI was dumb then it would make more sense to just have the AI actually cheat (i.e. just give the AI whatever units, weapons, techs, etc. it needed based on the difficulty level, much easier to code).

## AI Weaknesses in 1.0 ##

The biggest problem I'm dealing with in the 0.80 to 1.03 AI of GalCiv III is that all its thinking is empire wide. I cannot control spending on a per planet basis. I do not have access the shipyard building a ship. I am making decisions for an empire without any local knowledge. As a result, the bigger the map, the weaker the AI gets.

The second biggest issue is related and has to do with the ships. The AI doesn't currently have access to the ships in a way that lets me work with them based on on their location. I've alw2ays written the AIs in GalCiv as a gamer and less as a programmer. So, in my mind, I always thought of fleets as having a geographical duty. That isn't the case in GalCiv. As a reuslt, it has a lot tougher time coordinating ships into coherent local "Stuff. The bigger the map, the worse it gets.

Now, before someone says "How can you have crazy sized maps and an AI that can't 'handle' it" I'll bring you back to expectation #1. The AI handles it just fine for nearly all players. It's for people who are really good at strategy games that can overcome this and it's not an all or nothing thing (The AI, with enough handicaps, can overcome this weakness).

Nearly every weakness in the 1.0 AI boils down to a lack of local awareness (that is, letting planets, ships, shipyards, think locally instead of globally). The AI would do great as a federal politician...

## Rolling up our sleeves ##

I have a bunch of low hanging fruit that I intend to address in GalCiv 1.1, 1.2, and 1.3. Let's talk about those first:

1. Eliminate the AI's all seeing FOW vision. This will actually make the AI substantially smarter on bigger maps. This seems counter intuitive until you see the weaknesses I pointed out. It's better for the AI to only "see" stuff that actually matters so that it's not sending ships across the map or building starbases where it has no business doing so.

2. Making the AI more aware of ZOC. Remember, the AI gets annoyed when units and starbases are in its ZOC. The AI makes no distinction between meat and silicon. As a result, the AI often ends up with war with each other because of this which reduces the AI's focused strength.

3. Pre-war build up. This is something I'll be working with the Civ IV and Civ V AI developers on. This is something they're good at that I haven't done as much on. So I'll be implementing some of those systems (not source code of course, I'm just going to talk to them about it) into the AI.

4. Localized tactics. This will be a major bit of work but we will start dividing up the galaxy into theaters and have the AI start thinking of its empire and strategically vital interests as theaters rather than the current system which defines 2 theaters: Theater of focus (where it is concentrating its forces) and everything else.

## How you can help ##

Helpful: Telling me dumb things you saw the AI do that made you able to beat it is helpful. Very helpful in fact. Any mistake that would allow you to win regardless of the handicap.

Not helpful: Things that could be addressed just as easily with a handicap. The AI doesn't build up its planets well. This is on our list. But it's actually not that important since that can be addressed with handicaps.

Really helpful: Saved LATE games with descriptions of what you are seeing. Maybe the AI isn't defending its planets well. Maybe it's sending out crappy fleets. Maybe its fallen way behind militarily. Maybe its ships are crappy. These are things that I'm interested in.

This thread makes me happy. Can't wait to dig in and see what will come of it and how the community may be of help.

While I haven't designed Game AI's, I do have extensive experience working on "AI-Like" software that ingests data from a variety of sensory apparatus, processes that data along with some rules in a large rules engine and then uses a genetic algorithm to determine a best course of action across multiple action / decision points, places and people.

The hug difference is that my customers don't expect that when they hit "Turn" that they get all the answers and get to "keep playing" in one minute. We get hours to perform our processing.

I would think that is another limitation of what you have to do with Game AI. Most Humans (especially those who have don't anything more than script coding), don't have any inkling just how fast they actually process data, make decisions, and balance various factors. Consider this, when I see the strategic map, my visual cortex quickly identifies via color and shape the threats, opportunities and spatial relationships between all the units on the board. Poor computer doesn't get to see this "strategic relationship" view without YOU having to write a ton of code and invent a way to represent in a machine friendly format, the information that your human brain does in just a moment.

My initial thoughts are that the items you have already suggested are exactly what the AI needs. Example, having made the decision to go to war, prepare as a human would, before you declare war.

My map preferences will automatically give the Ai fits and make it tougher, however I will offer advice as I can as constructive as I can frame it. I prefer Insane or excessive sized maps with Abundant stars and Planets but with very few habitable planets. I have been tinkering with the hab settings on Uncommon. Anyhow my goal is to have about 15-16 AI with minors in an Insane map with each of us having about 20 to 35 planets. This would give enough for production and keep research up enough to keep moving through the trees.

I have 14 ai in my game and most have about 25 planets but the Drengin had 96. I have since lowered that to about 78. Insane maps take more time to move across. All the other ai in this game are set to Normal.

My current game has the Drengin as 'gifted'. He was right behind me in global power but has since fallen by 2k points upon the onset of war. The random military tech it gets is helpful. Keep this in. It keeps him on par with weapons. He is reacting to my missile fleets and I am seeing 7-10 ship fleets with point defense and mass drivers now showing up. I think he is fleeting up well but may need either a handicap for hull size or logistics to keep him strong. He currently has medium ships.

I tend to build few shipyards and hook them up to planets to boost the production so I can get fleets and ships faster. The Ai is doing it but only if there is a 5 hex distance to the shipyard. Its a tough thing to decide upon but I think he should hook up more planets to shipyards especially in is 'locally' owned area near his home planet.

I will likely restart a new game after 1.1 drops but will continue with this as I can.

I was really hyped for this game because of the talks during previews about how great the ai would be so I thought it would change from what most of other games do, by raising the bar with the ai not just match gal civ 2 ai.

I though finally a game that would give us a challenging opponent to play with on equal footing for years until the next game. oh well I guess my expectations were a bit too high for this decade, thanks for being honest.

It seems from your posts that most players play on low difficulty / normal.

Is handicapping the only way you are planning to differentiate the different ai levels?

If thats the case then normal will gradually become harder as you improve the ai then what happens to those people that were satisfied with the current level of difficulty? Players pride is usually quite big and wont allow them to lower the difficulty even if they feel that it has changed past their comfort zone probably resulting in angry players.

A CEO asking and listening to his customers, who wouda thunk it possible, God i wish i could have come and worked for you.

Dispite your great lead in, not sure.. is this the kind of thing you want a report/comment on?

* Ai is typically aggressive declaring war early, probably a little too soon or not accounting for my production/research ability. Seemed to judge me mostly on mil power. Once war started, was "relatively" easy to totally shift to a military footing and win through attrition by out producing the AI.

* AI fleet management

= Too often AI mixes tiny/small (slow) in with med and large ships resulting in a huge speed hit. The fleet without the smalls was powerful enough without the addition of a tiny/small. > e.g. saw a fleet of 4 M4 frigates add a single tiny, really did nothing for fire power and slowed the fleet form 6 to 2.

= Slow to react in countering my weapon specialization. e.g. if i had beams, and it was doing missile, first encounters the AI typically had zero to little shields. As the war dragged on it would increase shields (or counter to what i was using) BUT did so slowly and would continue to beef up his first choice (matched his weapon). Don't know if this is possible but when i trade with the AI i take not of his weapon techs, could the AI who is planning on going to war with me not do something similar?

= This one was a really bad AI move: Several times we were nose to nose with a high power AI fleet. I was out matched and the AI could have easily killed me (but would have taken losses). Instead of attacking, he move off and disbanded his fleet allowing me to move in and kill the ships one at a time in a single hex.

1. Eliminate the AI's all seeing FOW vision. This will actually make the AI substantially smarter on bigger maps. This seems counter intuitive until you see the weaknesses I pointed out. It's better for the AI to only "see" stuff that actually matters so that it's not sending ships across the map or building starbases where it has no business doing so.

1. Eliminate the AI's all seeing FOW vision. This will actually make the AI substantially smarter on bigger maps. This seems counter intuitive until you see the weaknesses I pointed out. It's better for the AI to only "see" stuff that actually matters so that it's not sending ships across the map or building starbases where it has no business doing so.

Yes, thank you Frogboy is the King!!

Yup, glad to see it on your list. It it the one bonus (note i did not call it a cheat ) that bugs me.

Yup, glad to see it on your list. It it the one bonus (note i did not call it a cheat ) that bugs me.

The main thing that bugged me was the starbases half way through the map...

Frogboy,

Does the AI currently get free ships on their planets ever so many turns? Just asking as in my current game some enemy planets (Benevolent in nature) appear to be getting 2 ships magically on their planets after so many turns and I was trying to see if I just missed them being placed in orbit or if they just appeared...

Wondered about that also, or did they just start with a bunch on $ and buy them, Haven,t taken the time to use the console and check it out yet.

Mine are appearing when their is no shipyard so you can't buy them and put them in orbit as no shipyard to produce. However, shipyards also seem to all of a sudden have 2 ships in orbit too... If they are that's fine (sucks) but understandable. Especially at higher difficulties...

Wondered about that also, or did they just start with a bunch on $ and buy them, Haven,t taken the time to use the console and check it out yet.

Mine are appearing when their is no shipyard so you can't buy them and put them in orbit as no shipyard to produce. However, shipyards also seem to all of a sudden have 2 ships in orbit too... If they are that's fine (sucks) but understandable. Especially at higher difficulties...

That's just the Paranoid ability in action. Drengin have it by default I believe for example.

For what it's worth, i think the GC3 AI is already better than it was in Twilight. I'm watching races knock the snot out of each other, planets change hands repeatedly, and smaller empires are getting gobbled up by ever larger ones.

The only time i saw this happen in Twilight was when the Korath went nutsy with their spore ships.

It's already off to a decent start, but i look forward to the improvements.

It appears the AI has a chance of getting free credits, technology and ideology points (on top of income bonuses etc). It also appears the AI gets huge bonuses to ship mass, range, hit points and accuracy. Will these be changed as the AI improves as well?

Obviously the AI needs plenty of bonuses on Godlike but it's also important to be immersed in the game. While I really enjoy Gal Civ 3, it's difficult to be immersed in a Godlike game after playing a lot of Distant Worlds on Extreme difficulty where 1-1 combat is indeed 1-1 combat.

With respect to extreme exploits that are too tempting to ignore, Carriers using small assault fighters (looks like an xml error as some places suggest they should be tiny) are an example. In my current game, one of the AI was on the back foot and going down, but as soon as they started building Carriers and fighters with 200 attack and decent defenses ... nobody even scratched their paint. The only option for the AI and myself was to use Carriers to counter Carriers. But none of the other AI did counter so it was a cakewalk. As a human player it seems a viable strategy just to rush Carriers using small assault fighters with no viable counter beyond applying the same strategy. So it certainly seems to fall in the "too tempting to ignore" category.

I am playing Gigantic, Abundant everything, Tight Clusters, Tough, 5 random opponents. My observation is that the AI does not handle large voids well. My level of helpful suggestion is to encourage them to chase relics and resources a little more and see if that helps them build stepping stones of influence. To my understanding, that kind of behavior can get some insects across large obstacles. Is that the type of feedback wanted?

It has gotten better at filling its original cluster. It is getting harder to sneak in behind them and steal planets, for example. Any other feedback has been at least mentioned by others. As always, thanks for asking!

A note on logistics. It would help if the autosave kept a rollover set of savegames. It is very possible to have AI behaviors appear that actually started several turns earlier. It is even more possible for AI behaviors to be there for several turns before I notice what they are doing! Things like ships appearing from nowhere could be backtracked if needed.

"3. Pre-war build up. This is something I'll be working with the Civ IV and Civ V AI developers on. This is something they're good at that I haven't done as much on. So I'll be implementing some of those systems (not source code of course, I'm just going to talk to them about it) into the AI."

I want the AI to act like an asshole towards the human player.

Put it this way: if I'm in first place, and I've giant empire of 87 planets, and each AI on average only has 20, I want some system where the AI SECRETLY bands together (secret diplomatic modifiers).

For example, the AI would PRETEND to go to war with one another according to the diplomatic screen. But in reality they're massing their troops to attack YOU. Then suddenly on the Turn of Doom, they ALL make peace with one another and attack YOU (because you're the biggest threat to them).

Or another example: you see a strong AI and you try to appease them with techs. But instead of seeing that as a good thing, the AI instead sees it AS A SIGN OF WEAKNESS. So then shortly afterwards it attacks you BECAUSE you tried to appease it (You're too weak, which is why you're trying to appease us. Now we invade you because you're a juicy target. HAHAHAHAHA).

In other words, I want the AI to act towards the human as the human acts towards the AI. I want the AI to be an asshole. The diplomatic screen should be FULL OF LIES and there should be many more secret modifiers that aren't present there (more realistic that way). That would make the game much more unpredictable and therefore fun. Also, it would make espionage MUCH MORE IMPORTANT.

In other words, while many of you are talking about improving the AI's tactics, what I'm talking about is improving the AI's STRATEGY.

Add ways for the AI to understand the state of the galaxy on a HOLISTIC level, and for it to react accordingly. The AI might be smart on a tactical level, but on a strategical level it's freaking stupid because it doesn't recognize things like how the currently EXTREMELY peaceful and EXTREMELY benevolent 80 planet empire is a threat to them in the long run.

The problem with the AI in these games (including Civ IV) is the diplomatic screen is TOO HONEST. That's unrealistic. The diplomatic screen should instead be FULL OF LIES (especially if you didn't put enough points in espionage). This would not be too difficult to fix. Just add some secret diplomatic modifiers to the AI that pop up under certain (variable- and thus not fully predictable) conditions and you're done.

And/Or make the diplomatic screen GIVE THE WRONG INFORMATION ABOUT THEIR EMPIRES AND ATTITUDES ON PURPOSE.

It would be freaking awesome (and also horrible) if you're sitting around peacefully building up your empire and suddenly 30 transports and a giant fleet of warships appear on your borders from an AI that you've been at peace with for the last 100 turns and who has an EXTREMELY positive attitude towards you.

Then you ask the AI "Why??????"

And the AI is like: "I lied."

It's what humans do to the AI (and to one another) all the time. I believe the AI should be capable of doing the same thing.

I've read discussions about the difference between intelligent AI and realistic AI and the difference seems to be"realistic" (which a lot of people would like to see) means AI will do certain things sub-optimally, will have weaknesses and flaws as any gamer (who hasn't learnt to mix-max to the...well...max) does.

The thing would be what does the AI do to limit the possibility of it's weaknesses/flaws being found and expoited as well as doing things to maximise where it's strengths are - like not declaring war against a stronger opponent and building up it's military instead or using it's diplomatic strength to get others to do the hunting and killing of the stronger opponent.