DEV DIARY: AI Walkthrough of 1.84

Published on Sunday, November 27, 2016 By Brad Wardell In GalCiv III Dev Journals



For the first series of these I’m going to put these up so that those of you who have no idea who I am don’t get too concerned that there’s this guy endlessly criticizing the game (and other people’s games) in the most unprofessional way. 

Who I am: I’m the founder and CEO of Stardock. I wrote the original Galactic Civilizations for OS/2 back in 1993 largely as an AI simulator in which humans were allowed to interact.  It took off from there.  I designed GalCiv I and GalCiv II.  For GalCiv III, I consulted and helped here and there but most of my time was spent on Ashes of the Singularity and my day job of running Stardock in which the game stuff is a minority of our overall business.

To be candid, I’m here for you guys.  I write games for people to play. I don’t care how popular the genre is.  I want to play what I want to play and hope you feel the same.

Now, let’s get started.


There are two pieces of starting up the game

  1. The first is that pretty little start-up window.  I’d like to see it have a different graphic than the main loading window.
  2. The main loading window

I lowered the load time of #1 by 2.7 seconds on my machine.  I did this by having the language validation put onto another core and moving other validation to being a background thread becuase it doesn’t matter when it happens.

I lowered the main loading by 11 seconds on my machine by having the main game textures loaded on different cores.

Note: If you have a dual core machine there’s nothing I can do for you.  I’m not changing algorithms here (that is called optimization).  I am re-architecting it to run in parallel.


Before you get the next update, load up the game and open up task manager.  On my machine, a couple of my cores are pegged.  I’ve fixed this by using different APIs for measuring time (they’re less precise but much cheaper) along with reducing the number of threads that game sets up for its job system which I’m in the process of scuttling entirely to replace something more similar to what we did with Nitrous over at my other job at Oxide Games.

Bottom line, this updated GalCiv III architecture which will likely show up in 1.84 should use a lot less CPU, be a lot faster and be more stable.  I hope to see this released as an opt-in early next week.

Game Setup



Memory Use on start of game (via task manager)

  1. v1.84: 2.9GB (my modified version)
  2. v1.83: 4.8GB (current Steam version)

How: Updated the DDS file compression to use one that is new to DirectX 10 (I was able to avoid a DirectX 11 one and get nearly all the benefits). I am still in process of doing this so this will keep getting better.

Total Time from launching the game to being in the game via “quick start”

  1. v1.84: 22s (my modified version)
  2. v1.83: 36s (current Steam version)

So on my machine, 14 seconds of boot time reduced.  This is due to re-architecting, I didn’t “optimize” any algorithms.  I’m just using your hardware a little more completely (parallel computing, my friends at AMD and Intel would be pleased).

Defaults I recommend

  1. Tech Brokering should be disabled by default

Features I’d like to see

  1. I’d like to be able to add components to Mercenary Ships. I think this is very VERY Important. Literally, let me just click upgrade and add and remove individual components.
  2. I’d like to be able to do the above to any ship in fact.
  3. Planets that aren’t class 0 should be given some very subtle atmospheric effect
  4. I think embassies should have to be founded by Diplomatic Envoys. Gives players a lever to improve relations.
  5. GNN report on where the universe stands that comes up every say 20 turns on a particular topic.
  6. In diplomacy, Civs with neutral and then less than neutral relations should get their own circle.  Right now, a player with unfriendly relations occpies the same ring as someone with cordial which isn’t helpful.


  1. I haven’t gotten to play a lot of GalCiv III since it launched.  It is most definitely a lot better of a game than when it was released.  It wasn’t “bad” when it shipped but I felt it was a bit too much like GalCiv II with a re-skin with a lot of rough edges.  Today’s game shows a lot of nice, and often subtle, refinement. 
  2. Playback speed of battles should be 2X by default
  3. Too many cigar shaped ships.


Part 2: Duel

I feel like the performance is good enough to really start digging into the AI strategies.  I already fixed a couple of things I thought were not ideal. 

Disclaimer:  Writing good AI is more art than science.  People who know nothing on programming imagine that we can somehow just brute force calculate out some perfect strategy.  No, you really can’t.  People will pick short terms with decent AI over massively long terms with great AI.  My job is to make a really good AI with short terms. 

Every few years I do a rating of the AIs I’ve written.  Here is how I’d rate them on a scale from 1 (terrible) to 10 (ideal). And my opinions change a bit over time as I learn new things.

Galactic Civilizations OS/2: 9

Galactic Civilizations I: 8

Galactic Civilizations II: 6

Galactic Civilizations II: Dark Avatar: 8

Galactic Civilizations III: Twilight of the Arnor: 7

Galactic Civilizations III: at launch 4

Galactic Civilizations III: at end of 2015: 6

Galactic Civilizations III: today: 5

For other references:

Most other 4X games I play go between a 3 and a 6.


  1. The governor system really hurt the AI.  I can only imagine what they do to humans.  But it’s not ideal.
  2. The ship design system needs to be improved. Before Crusade.
  3. The planetary improvement system needs to be improved: before Crusade
  4. The strategic fleet AI needs to be improved. before Crusade
  5. Spacing of stars in star generation needs to be changed (hurts AI, makes game less interesting)

Other problems:

  1. Catering to forum “experts”.  I see a lot of code in here that was put in clearly to assuage people on the forum’s pet peeves. It’s good to listen to feedback. It’s bad to implement their advice as they suggest. Computer players aren’t people. When you try to make an AI play like a human like this, you end up with a very exploitable AI. 
  2. Exploits.  I see a lot of systems in here that I, as a player, could exploit.  Any time I play a game, I exploit it.  It’s a game.  I can choose not to exploit it but the more often I have to do that, the more fun I lose.  You can’t plug exploits easily.  You need to have a better AI system in which exploits just don’t come into the picture in the first place.

That said..

I’m going to do a 1 v 1 game and exploit the hell out of the AI as best I can.

Lots of improvements made today.   But also some significant game design changes to how the economy works that is sure to create some discussion.

The area I’m not that familiar with (in terms of exploits) is diplomacy stuff. Feel free to chime in below with any good diplomacy exploits you want me to look at.

Big problems

So 400 turns in on a massive map I’m running into a couple different problems here. 

First, the AI is reducing its priority on building colony ships even though there are many many worlds available (I modified the internal settings so that there are thousands of worlds to test this). 

Second, the AI is slowly reducing its priority on technology which is causing it to fall further and further behind me.

Part 3: LESS CPU Usage


So after my tweaking, the idle CPU time is, well, idle.  I mostly play GalCiv III on my Microsoft Surface Pro 4 so I’m pretty sensitive to battery use. 

Sheer Performance difference:


Thanks to Jon (a GalCiv player who likes to play insane maps with 50+ players) I have access to saved games with hundreds (plural) of hours put into them.  I used these saved games to help carve down some of these costs.

Now, my machine is a monster so my turn times are already short.  On his machine, it was taking multiple minutes to get through a turn while on mine, even on the public version, it’s “only” 13 seconds.  So then it’s question of whether it’s a CPU or memory thing. 


Part 4: A better, smarter AI

I ended up having to jettison a lot of the way the AI decides what ships to build.  It’s not that the code was bad or that a lot of work hadn’t put into it.  The problem was a fundamental issue of strategic priority: What should the AI do at a given time?

As the game progresses, more and more things compete for resources and this is where AI’s tend to fall apart in complex strategy games.  GalCiv III struggles with this as well.

For example, what type of ship should an AI facing 50 opponents, 14 it’s at war with that also has 4 unclaimed resources within range and 9 nice planets but is also facing money issues but has 3 trade route slots available and has a very vulnerable enemy that can be attacked if it builds a starbase to increase its range unless, instead, it decides to produce a fleet of longer range Frigates?

What I can tell you is that building a colony ship kept getting  knocked lower…and lower…and lower in the priority list.  The result was that as the game went on, the AI, which expanded well early on, would get slower and slower at further expansion.

There was no way to “tweak” this.  It had to be re-done and moved away from bottom up priority system and instead be looked at from the opposite direction: A top down.  The AI player needs to know what its goal is, globally, and pursue it decisively.  That’s where AIs are good.

Another area it struggles with is when it should, post-haste, send a unit to a troubled area versus rallying them up.  I see people on forums saying that the AI “just” needs to build bigger fleets.  Duh.  They’ve put a lot of effort (almost an insane amount of effort) into trying to do this well.  In GalCiv II, my code for handling this was a lot less sophisticated in the sense that the answer was ALWAYS just build the damn fleets. No nuance. Just do it. 

Test game



Sunday night check in:

Just before midnight, I have my second check-in (first check in was all performance, this one is balance and AI)


# Memory #
New Compressed Textures: (DirectX 10)

Starbase minimum distance reduced from 5 to 3 tiles
AI tends to focus more on tech (generally) than previously
AI will build survey ships late in game
AI provided with a much wider variety of ship designs to choose from with the various strategies
AI weights units much more closely than previously in order to not make one virtually impossible to build
Opposing culture diplomatic penalty reduced from 1.25 to 1.1 if AI is benevolent
Opposing culture diplomatic penalty increased from 1.25 to 2 if AI is mercilous
Opposing culture diplomatic penalty increased from 1.25 to 2 if AI is cruel
Close to victory diplomatic penalties increasedf rom 1 to 5
Ripe for conquest diplomacy penalty reduced from 0.75 to 0.1 if AI is benevolent
Ripe for conquest diplomacy penalty increased from 1.25 to 1.25 if AI is aggressive
Minimum planet class to be a manufacturing world reduced from 7 to 4
Max number of colony ships the AI will construct at once increased from 2 to 3
Max slider focus reduced from 95% to 75% (to deal with coercion penalty)
Coercion forgiveness eliminated (there is always some coercion if you move off from center)
Maximum coercion reduced from 50% to 35%
Colony Capital production points reduced from 5 to 1
Civilization Capital production points reduced from 5 to 1
Influence Radius root increased from 1.75 to 4 (i.e. influence ZOC will start out much much smaller now)
Tech inflation penalty significantly reduced
Penalty for switching a constructor to a colony ship increased from 50% to 75% (yea, you know who you are)
Pirates moved further away from starting location
Increased the variance for the various settings (minors, , pirates, etc.)
Modified the governor script to provide a bit more flexibility based on planet bonuses when building improvements
Colony capital maintaince eliminated
Colony capital hub  provides a 2 (was 1) level bonus to adjacent buildings if they are population or manufacturing or research
Civ capital hub provides a 3 level bonus (was 1)
Reduced maint. slightly on research buildings
Rare habitable planets decreased from 30% to 25%
Nebula and black holes and anmalies made much less common on all settings
Occasional planet frequency amount doubled from 1X to 2X
Common stars modifier increased from 0.9 to 1
Common planet frequency amount increased from 0.75X to 3X (this also fixes a bug where common was less than occasional)
Abundant stars increased from 1X to 1.5X
Planet Frequence increased from 0.25X to 3.5X (also fixes bug)
Tiny map size decreased from 30 Sectors to 18 sectors
Tiny map base objects increased from 32 to 120 (i.e. tiny maps will be a lot more filled)
Small map decreased from 40 to 32 sectors
Small map base object count increased from 64 to 150
Small map max habitable planets increased from 32 to 40
Medium map size decreased from 60 sectors to 40 sectors
Medium map Base object count increased from 110 to 200
Large map size decreased from 75 to 60 sectors
Large map base object count increased from 155 to 300 (i.e. over twice as many stars/planets/etc. in a particular size)
Huge map size drecased from 95 to 70 sectors
Huge map Base count increasded from 250 to 350
Gigantic map size decreased from 180 to 80 (but number of objects remains the same -- more stuff)
Immense decreased from 240 sectors to 120 sectors (but same object count)
Excessive decreased from 290 sectors to 160 sectors
Max camera zoom on excwssive increased from 16000 light years to 30000 light years
INSANE map size decreased from 380 to 320
INSANE map object count INCREASED from 1200 to 1400!
INSANE map maxhabitable planets INCREASED from 600 to 640 thanks to memory reduction in this build
Max camera zoom increased from 18.2k light years to 40,000 light years.
Sensor cost components reduced slightly
Cargo module cost reduced from 27 to 10 (cheaper colony ships -- but remember, planets now rely more on population for their production)
Tiny hull cost reduced from 11 to 10
Small hull cost reduced from 25 to 20
Medium hull HP increased from 100 to 120
Large hull cost increased from 128 to 300
Large hull HP increased from 250 to 600
Large hull storage incresed from 100 to 120
Large hull logistics cost increased from 7 to 10
Huge hull cost incresd from 432 to 500
Huge hull HP incresd from 500 to 800
Huge hull storage increased from 250 to 300
Huge hull logistics increased from 10 to 16
Cargo hull cost reduced from 42 to 24
Cargo hull HP reduced from 10 to 1
Cargo hull logistics incresed from 5 to 6
Max AI improvement queue reduced from 3 to 2

# Bugs fixed #
Fixed double counting of trade routes for AI diplomacy purposes
Placed a critical section around the D3DX11CreateShaderResourceViewFromMeory call (random, late game crashes)
Placed a critical section around m_textureSets.PushBack( pGC3TextureSet ) (fixes random load game crashes on large games)
Fixed bug that could cause the AI to see tiles in the opposite map position of where they were exploring
Fixed a bug that could cause the AI to reduce the priority weighting on colony ship production based on the # of targetable planets

# Optimization #
Removed legacy stopwatch code from the sound system
Moved old profiling junk
Reduced CPU usage of the particles thread
Reduced CPU usage of main graphics thread
Removed redundant debug output

## AI ##
Added UpdateColonies and UpdateShipyards as seperate functions
Eliminated the UpdateColoniesShipyards (readability)
AI builds scout ships later in the game to keep exploring very large galaxies
Dramatically reduced AI >normal economic bonuses (no longer needs them)
Re-designed the way the AI expands into the galaxy with colony ships so that its expansion no longer stalls on large maps
Dramatically reduced the amount of time an AI will interact with a player if they are not within ship range
AI doesn't try to bribe other players to go to war unless they and the other players have a decent military already
AI will no longer give tech gifts to players with a different ideology (i.e. no more Drengin giving you tech if you're a nice person)
AI now scales the number of similar ship projects based on number of colonies rather than a flat number
AI pumps up colony ship production priority if there are a lot of nice planets laying around
AI pumps out fewer Constructors in general
Re-designed the eway the AI determines which planets should get a shipyard to be more (way more) intelligent
Updated AI's handling of adjacency bonuses to be more intelligent
AI values planet quality more when picking planets to colonize
AI somewhat more heuristic on tech research
AI somewhat quicker to war


This will take some testing.  When you boost perf like this, you uncover timing issues that were well hidden before.