Technical commentary on Civ/game AI

Civ 6 is not a classical, well defined game like TicTacToe, GO or Chess.

There are several fundamental differences :
- Fog of War : In classical games like Chess and GO, you have full knowledge of the state of the game at any time. No Fog of War, no uncertainties about current player positions, only about future player actions. In Civ, you don't know where your opponents start or what terrain they start. You need to scout to see at least some part of the map. You do not see enemy armies approaching when they are covered by the Fog of War.
- Map sizes : TicTacToe 3x3, Chess 8x8, GO 19x19 (already too big to calculate the game tree.) Civ up to 100x200 (or more?)
- Terrain : Classical Games : only one type of terrain. Civ : different maps with different terrain types and different movement restrictions to tiles like with water, land and impassable mountains. (Air, Water, Land units)
- Simplicity of Game Rules and number of objects. Compared with Civ, GO is a simple black & white game with only one type of stones (unit) in 2 colors and a few rules. Civ is much more complex than all the classical games with the different levels/layers of play like Science, Culture, Religion, Economy, Military, etc. and hundreds of different terrain-types, improvements, Natural Wonders, techs, advances, buildings, units and 30+ different civs/leaders and City States with their unique rules. Rules of an actual game depend on participating civs, leaders, CS.
- Exponential effects of early game decisions (or bad luck) : e.g. Do not build a settler early or loose the 1st settler or build a 2nd city (in a good spot) early may result in completely different games.
- Constance of Game Rules : Civ Game Rules change in rather short periods. Every patch usually modifies the Game Rules. Each small mod may modify the Game Rules.

Especially since Civ Game Rules are not constant (due to patches and mods), it is not usefull to develop a perfect AI for a fixed set of rules. (-> No fixed algorithms or self-leraning Neural Network approach.) There can only be a general approach with rather robust strategies who do not fail when some Game Rules are changed.

If one thinks that AI is too weak, first try to play without save/load cheat. Start a game and play it to the end without reloading when something does not work out as planned.
 
Last edited:
This is ridiculous..

Nobody's asking for deep learning.. Just basic level decision trees that make sense.

Like:

Do I have less than 2 tiles of rainforest in this city? Ok don't build Chichen Itza..

Am I being attacked by another Civ that has 3 times the military strength? Ok I'll build military units as a priority.

Fact is mate, even the basic weightings of priority are WAAAAYYYYY off. I don't work in game AI but I have a strong enough background in procedural animation and coding to know what you're talking is condescending pap.
 
Last edited:
Allow me to address the elephant in the room. Any improvements in the AI would have to be balanced against the performance costs, so even if it were a simple matter to improve the AI it might still not be worth it. A casual player who finds prince difficulty challenging isn't going to notice better AI, but will certainly notice longer turn times, especially if he or she plays on large maps with many computer players.

This is missing the fact that the Civ AI is actually horribly unoptimized. We've seen the Civ 5 code, it spends 95% of its time on useless code executions. Considering the Civ 6 AI still takes way longer than it should for how competent it is, this is likely still the case.

To illustrate. What the civ 5 AI spend most of its time on was unnecessary pathfinding. They used a badly optimized pathfinder that was called way more often than it had to be. For example, in civ 5, units used to randomly patrol their terrain if they had nothing better to do. The way they did this, was to randomly select a point in the owners terrain, then calculated the fastest path there, and walked in that direction. Repeat this for every unit on every turn. If you're patrolling randomly, there is no need to be able to calculate the fastest path to a random point, especially not every turn and if you decide to do that anyway, you need to use caching, which they didn't.
Just stopping the units from walking around randomly every turn reduced turn times by as much as 40% for me.

There is no need to take endless time to make a good AI. You can make solid bots that do turns with hundreds of units in 10ms. Having it take several seconds with like 20 units is just a result of unoptimized code, not some kind of result of some law that better AIs need to be slower.
 
Yeah that's basically it right now. Unless you figure out a way to change AI behavior through lua. My own investigation failed to deliver anything worthwhile on lua side, but I could've missed something. Annoyingly it does contain methods to move units, which could've been awesome, but it doesn't seem to contain anything to overrule AI behavior and it disregards movement points, so it ends up moving units and attacking twice etc. Haven't found a way around that yet
And that's frustrating as we could do that in civ5 from day one, long before the release of the DLL source code...

But, on that subject, have you tried to use those ?
Spoiler :

Code:
Player
     GetAi_Military
         PrepareForWarWith
         HasOperationAgainst
         SetRival
         StartScriptedOperationWithTargetAndRally
         ScriptForceUpdateTargets
         AllowUnitConstruction
         StartScriptedOperation
         CanConstructUnits
         SetScriptedTargetAndRally
         SetScriptedOperationReady
         AddUnitToScriptedOperation

from NubiaScenario.lua, where I suppose that "Attack Enemy City" refers to the AiOperationDefs table
Code:
local function InitiateInvasions( player, currentTurn )

    if (g_eInvasionReadyForPlayerID == player) then

        -- Script them to attack nearest city
        local pAttacker = Players[player];
        local pNearestCity = FindClosestTargetCity(player, g_iInvaderX, g_iInvaderY);
        if (pNearestCity ~= nullptr) then
            local pMilitaryAI = pAttacker:GetAi_Military();
            if (pMilitaryAI ~= nullptr) then
                local iOperationID = pMilitaryAI:StartScriptedOperationWithTargetAndRally("Attack Enemy City", pNearestCity:GetOwner(), Map.GetPlot(pNearestCity:GetX(), pNearestCity:GetY()):GetIndex(), Map.GetPlot(g_iInvaderX, g_iInvaderY):GetIndex());
                local pUnits :table = pAttacker:GetUnits();     
                for i, pUnit in pUnits:Members() do

                    -- Special check for Sea Peoples so we ignore the Libyans coming from the west
                    local bSkip = false;
                    if (currentTurn == iLibyaInvasionTurn + 1 and player == eLibyaPlayer) then
                        if (pUnit:GetX() < 14) then
                            bSkip = true;
                        end
                    end
                    if (not bSkip) then
                        pMilitaryAI:AddUnitToScriptedOperation(iOperationID, pUnit:GetID());
                    end
                end
            end
        end

        g_eInvasionReadyForPlayerID = -1;
    end
end
 
The AI just ruins all the immersion in this game. It's obvious that Firasix doesn't care to make good quality games anymore, only cash-milking games. CivBE and CIV VI shows how low the bar can fall in Firaxis, so don't spect anything better from them in the future. This is a new CIV era, the era of decline.
 
There are two contradictory points that are both true: The AI isn‘t good enought for the civfanatics that play to win. The casual players who prefer to roleplay by building an empire that stands the test of time don‘t care about the AI. Add to that commercial concerns you arrive at the situation we have. This will accentuate further, but they could solve it quite easily.

What creates the complaints and fire storms on the forum are ‚obvious mistakes‘ by the AI. Things like not escorting settlers through barbarian territory, not taking cities at 0 health with melee units, building Petra on the single desert tile of the city. If you can eliminate these, you make many people happy as you give them the illusion of a competent AI. What happens in the fog of war in turn isn‘t of interest. It is funny that by eliminating those obvious mistakes, you make the game also harder as some people can‘t exploit the AI any more. Especially with repeated patterns (like the example of taking CS mentioned above) I don‘t see the allure, but it is all about winning the game.

Now see I haven‘t stated how one should cure these obivous mistakes. That‘s a technical discussion. But the goal is a totally different level than „create a competitive AI“.

Spoiler Tangent :
The second thing I want to mention as a solution is more for the next civ version: simplify. Civ 6 has too many systems for me to track which means instead of optimizing or playing, I often just click on. There are systems designed for the human player, giving her or him decisions every turn. But most of them require quite a steep learning curve, f.e. You have to know all adjacancy rules by hear to micro-plan your cities. (And then they make the civilopedia horribly to read by having mountains be 6 different versions all listed as their own...). That‘s just not fun and makes it harder for both the casual player as well as the AI (not for the „play to win“ gamer). Other such builder games (like Sim City) don‘t have AI opponents for a reason it seems, as it allows for people to learn the system better. Thus I would advise them to radically simplify the number of yields with which in turn you can do more with. Less Decisions are more.
 
The AI just ruins all the immersion in this game. It's obvious that Firasix doesn't care to make good quality games anymore, only cash-milking games. CivBE and CIV VI shows how low the bar can fall in Firaxis, so don't spect anything better from them in the future. This is a new CIV era, the era of decline.

Play 6, then play CivIII, then play 6 again.

Then tell me again that it's gotten worse.
 
Play 6, then play CivIII, then play 6 again.

Then tell me again that it's gotten worse.

Or Civ IV, even. The AI was pretty bad until some fans fixed it and got those mods included in BTS. Frankly, Firaxis has never been great at Civ AI. It's passable, which is good enough for most players.
 
And that's frustrating as we could do that in civ5 from day one, long before the release of the DLL source code...

But, on that subject, have you tried to use those ?
Spoiler :

Code:
Player
     GetAi_Military
         PrepareForWarWith
         HasOperationAgainst
         SetRival
         StartScriptedOperationWithTargetAndRally
         ScriptForceUpdateTargets
         AllowUnitConstruction
         StartScriptedOperation
         CanConstructUnits
         SetScriptedTargetAndRally
         SetScriptedOperationReady
         AddUnitToScriptedOperation

from NubiaScenario.lua, where I suppose that "Attack Enemy City" refers to the AiOperationDefs table
Code:
local function InitiateInvasions( player, currentTurn )

    if (g_eInvasionReadyForPlayerID == player) then

        -- Script them to attack nearest city
        local pAttacker = Players[player];
        local pNearestCity = FindClosestTargetCity(player, g_iInvaderX, g_iInvaderY);
        if (pNearestCity ~= nullptr) then
            local pMilitaryAI = pAttacker:GetAi_Military();
            if (pMilitaryAI ~= nullptr) then
                local iOperationID = pMilitaryAI:StartScriptedOperationWithTargetAndRally("Attack Enemy City", pNearestCity:GetOwner(), Map.GetPlot(pNearestCity:GetX(), pNearestCity:GetY()):GetIndex(), Map.GetPlot(g_iInvaderX, g_iInvaderY):GetIndex());
                local pUnits :table = pAttacker:GetUnits();    
                for i, pUnit in pUnits:Members() do

                    -- Special check for Sea Peoples so we ignore the Libyans coming from the west
                    local bSkip = false;
                    if (currentTurn == iLibyaInvasionTurn + 1 and player == eLibyaPlayer) then
                        if (pUnit:GetX() < 14) then
                            bSkip = true;
                        end
                    end
                    if (not bSkip) then
                        pMilitaryAI:AddUnitToScriptedOperation(iOperationID, pUnit:GetID());
                    end
                end
            end
        end

        g_eInvasionReadyForPlayerID = -1;
    end
end


Oh wow..holy ****.. that could actually be insanely useful, thank you! I hadn't seen those yet.

Like game changingly useful.. Unless there's some weird issues preventing it, this should allow me to override the entire macro troop movements and possibly even war declarations, settling spot choices and some micro movement. That would allow for an entirely different game!

Do you happen to be able to see if there's also a way to remove units from operations/ end operations manually?
 
Oh wow..holy ****.. that could actually be insanely useful, thank you! I hadn't seen those yet.

Like game changingly useful.. Unless there's some weird issues preventing it, this should allow me to override the entire macro troop movements and possibly even war declarations, settling spot choices and some micro movement. That would allow for an entirely different game!

Do you happen to be able to see if there's also a way to remove units from operations/ end operations manually?
No, I've not tried to use them myself yet, even if it's also on my "OMG I must test this ASAP" list since I've read that scenario file.

edit: just checked, but I have not seen anything looking like that in the lua functions for the units.
 
No, I've not tried to use them myself yet, even if it's also on my "OMG I must test this ASAP" list since I've read that scenario file.

Alright, will report back when I know more!
It's just too bad civ lua is such a pain to develop with long reload times and without the ability to easily tell what parameters functions take..

Also, have other functions been added recently? I had been using your google docs sheet before as a reference and these were still missing from that
 
Last edited:
There are two contradictory points that are both true: The AI isn‘t good enought for the civfanatics that play to win.

I haven't read anyone complaining that they win easily and consistently at very
high levels against >25 civs on ludicrous size (200x100) maps at epic or
marathon pace. Admittedly, many people can't play at that level because their
rigs aren't powerful enough. However, if they lack the patience for long games
against many AI opponents, or if that type of game doesn't suit them, then that's
their considered choice and they can cry bitter tears.

The casual players who prefer to roleplay by building an empire that stands the test of time don‘t care about the AI.

Agreed. If the AI gives them a fun time, its flaws are largely irrelevant.

Add to that commercial concerns you arrive at the situation we have. This will accentuate further, but they could solve it quite easily.

Not if the problems are far too difficult to solve satisfactorily with limitations
on RAM and CPU speed.
 
Not if the problems are far too difficult to solve satisfactorily with limitations
on RAM and CPU speed
Dude, there's a conversation regarding AI improvements going on right above you that involves the current limitations enforced by the game itself.
Performance isn't preventing anything. The AI isn't even optimized.
 
Play 6, then play CivIII, then play 6 again.

Then tell me again that it's gotten worse.

Civ III was a fantastic game, and continues to be a good game. The graphics are dated, but the gameplay is OK, and the AI is good. I liked the good old times when an Empire was something more than 5 cities, and when you where afraid of your neighbours armies. And the amount of mods and scenarios was awesome.
 
Not if the problems are far too difficult to solve satisfactorily with limitations
on RAM and CPU speed.

If you had read further, you would have realized that I was talking about "the obvious" problems. Not even the 80% in the 80-20 rule, but the glaring obvious failings that gets people to open threads in this forum or post "Lol, look at that" on reddit (no specific example in mind though). The problems that didn't exist in earlier civilization games. The exploits that let you game the AI or ignore certain mechanisms because you know how the AI will act. We are not talking about good here, just better. Things that mods have already achieved.

And I'm really not sure who can even play such big games on such big maps you mention above. How long would that take? 5 hours for one game? I only play on small maps as I want to see the late game once in a while... But again, I'm clearly a casual role-player type. But even to me, it irks me to see frozen AI settlers and I could never use a unit to block a tile the AI wants to settle on to prohibit the AI to settle. That's optimal gameplay, but it's an exploit, no? Where is the fun in that?
 
This is missing the fact that the Civ AI is actually horribly unoptimized. We've seen the Civ 5 code, it spends 95% of its time on useless code executions. Considering the Civ 6 AI still takes way longer than it should for how competent it is, this is likely still the case.

To illustrate. What the civ 5 AI spend most of its time on was unnecessary pathfinding. They used a badly optimized pathfinder that was called way more often than it had to be. For example, in civ 5, units used to randomly patrol their terrain if they had nothing better to do. The way they did this, was to randomly select a point in the owners terrain, then calculated the fastest path there, and walked in that direction. Repeat this for every unit on every turn. If you're patrolling randomly, there is no need to be able to calculate the fastest path to a random point, especially not every turn and if you decide to do that anyway, you need to use caching, which they didn't.
Just stopping the units from walking around randomly every turn reduced turn times by as much as 40% for me.

There is no need to take endless time to make a good AI. You can make solid bots that do turns with hundreds of units in 10ms. Having it take several seconds with like 20 units is just a result of unoptimized code, not some kind of result of some law that better AIs need to be slower.


I concede that the Civ VI AI might be horribly optimized. I haven't noticed longer turn times, but its possible that I've simply become more patient over the years. Frankly though, my point still stands, because even if what you say is true then the AI must be optimized before it can be improved and Firaxis currently has little incentive to do either at the moment.

I do remember the Civ V AI constantly shuffling its units, it was especially noticeable and annoying with the city states, but I really don't see how it is relevant, because I have not noticed this behavior with the Civ VI AI. Though, I have noticed that the Civ VI AI places far too much emphasis on scouting to the point where some civs leave themselves vulnerable to invasion because their armies are busy scouting the north and south poles simultaneously.

I'm not trying to bash everyone who wants better AI, because I want better AI as well. A super smart AI would make conquest ten times as enjoyable and keep a peaceful player honest with the threat of mid and late game invasions. The thing that bugs me is that everyone says creating an intelligent AI is so easy. If that is true then why is it that no game I've played in my life, except chess, has had genuinely good AI?
 
I'm not trying to bash everyone who wants better AI, because I want better AI as well. A super smart AI would make conquest ten times as enjoyable and keep a peaceful player honest with the threat of mid and late game invasions. The thing that bugs me is that everyone says creating an intelligent AI is so easy. If that is true then why is it that no game I've played in my life, except chess, has had genuinely good AI?
It's not about ease. It's the fact that it can and has been done without much cost beyond time. This is a problem that Firaxis hasn't even acknowledged, so if they could at least recognize it we'd be getting somewhere.

Several examples of good AI have been raised already in this thread.
 
And coming from my background as a competitor in bot coding tournaments, the top 50 or so bots in these competitions easily blow the civ AI out of the water, while build by hobbyists in their spare time in timespans as little of 1-3 weeks. The Civ AI for example frequently just ends the turn on units/cities that can fire, and it frequently ignores cities at 0 health with adjacent melee units. The Civ AI frequently has 50%+ of its units just stand around doing nothing while a war is ongoing. It will miss the opportunity to capture civilians or make its own civilians walk out right into visible enemy units. It settles a tile away from rivers instead of adjacent to them. It declares peace with others at no cost while surrounding the enemy capital at no health. It will send high promotion units in to die for no good reason. It builds wonders it has no use for, picks policies and beliefs with no benefit. None of these issues are by any means hard to solve using classical AI systems.
With errors like these, you couldn't even hope to compete in a tiny bot coding competition, but somehow we're expected to consider this normal for a big budget studio which had years, and which delivers a game bought by millions. It's just an incredibly dumb business decision to not focus more on this, because it should be obvious by now a lot of people are not buying into the game at all, or aren't buying into DLC/expansions because the way games get stale without good AI (and because people aren't recommending games they don't really enjoy). They could've easily gotten 5-15% more revenue by just putting a second skilled employee on AI full time, which would've paid that employee back many times over.

Yeah I think this is much more on the mark than the OP. When you see the AI consistently making boneheaded blunders time and time and again that are completely obvious to a human then this is an implementation failure. It would be like a chess AI moving their piece into range of direct capture for no rhyme or reason and just giving me a free piece. Civ 6 is obviously more complicated but IMO the AI is still pretty atrocious. There has been some signs of improvement but very minor. The AI+ mod helps a lot by the way and I use it regularly - so thanks for putting in the effort to improve this aspect of the game.
 
Heya, I love these AI discussions so thought I'd butt in again. While I don't work in AI, I've made several game AIs and regularly compete in bot writing competitions where I tend to do fairly well.

LOL @ self-assessment. Firaxis probably believe their AI is doing quite well too.

Finding 10% (say) of the many tasks where the AI performs poorly is not the same
as getting the other 90% to perform at least satisfactorily and transparently.

If you had read further, you would have realized that I was talking about "the obvious" problems. Not even the 80% in the 80-20 rule, but the glaring obvious failings that gets people to open threads in this forum or post "Lol, look at that" on reddit (no specific example in mind though). The problems that didn't exist in earlier civilization games. The exploits that let you game the AI or ignore certain mechanisms because you know how the AI will act. We are not talking about good here, just better. Things that mods have already achieved.

Don't confuse finding the many tasks where the AI performs poorly with the
difficulty of getting the remainder to perform well. Optimising the AI before
all the other many components required up to R&F would have been a
ludicrous waste of time and effort.
I hope that they live up to their promise to release tools to help modders
because that will enhance the game in many, many ways, including the
improvement of the AI for the many different styles of games that people like
to play.

And I'm really not sure who can even play such big games on such big maps you mention above. How long would that take? 5 hours for one game? I only play on small maps as I want to see the late game once in a while... But again, I'm clearly a casual role-player type. But even to me, it irks me to see frozen AI settlers and I could never use a unit to block a tile the AI wants to settle on to prohibit the AI to settle. That's optimal gameplay, but it's an exploit, no? Where is the fun in that?

It can be played on a fairly standard PC with 8Gb RAM and at least a GT960 card.
I can finish a game at marathon pace in about 20 - 30 hours. As I said, not everyone
has that kind of patience (or the rig), but it is a far tougher game to beat at high
levels because glaring mistakes by some of the AIs are more than countered by
the other AIs making good choices and exploiting their bonuses against human
players.

But even to me, it irks me to see frozen AI settlers and I could never use a unit to block a tile the AI wants to settle on to prohibit the AI to settle.

I'm not saying it's anywhere near perfect, but to think of it as finished is just
as ridiculous. (Not that you did say that!)

That's optimal gameplay, but it's an exploit, no? Where is the fun in that?

People get their jollies from Civ in many, many ways that I don't care for,
but that's their prerogative.
 
Last edited by a moderator:
OK I'm completely ignorant when it comes to AI programming, not my field at all. However, I have played a lot of Civ over the years, and I have to say the AI in Civ VI is bad even compared to previous Civ games.

I don't expect it to be actually intelligent, I know we're not there yet (and tbh I'm frightened by the very idea - wouldn't it be hilarious/terrifying if Skynet started as a gaming AI?) I don't expect it to learn and I don't expect it to be able to out-think me.

But come on:

(1) Unescorted Settlers, even while they're at war!
(2) NEVER building or using air units (except maybe one biplane towards the very end of the game).
(3) Hardly building any kind of navy (even Harald Hardrada, he of the naval chauvinism, seems to consider two frigates a "strong navy").
(4) Not taking cities that are at 0 HP (barbarians and hostile city states never seem to have any problem taking and razing cities so clearly they can do it, they just often don't for some reason).
(5) Building wonders that are completely useless (the infamous 1-tile-desert Petra).

Surely fixing such obviously idiotic behaviour wouldn't be so hard as to completely drain the resources of Firaxis or the processing power of my computer?
 
Back
Top Bottom