As some of you know, I’ve been working on a lot of the low level systems of Elemental during the Christmas break. With the team on vacation, this is a good time for me to get into the bowels of the game itself to make changes without worrying about breaking other people’s changes.
Computer AI is my passion and in recent years (especially since GalCiv II) I haven’t had the pleasure to do nearly as much AI coding as I’d like (with the whole day job of running Stardock and all). So this is how I’m spending my Christmas break.
Core weaknesses of the Elemental AI
I have a fairly endless list of criticisms with the Elemental AI so I won’t go into more than a few major ones.
The most significant one is that unlike GalCiv, Elemental isn’t able to simulate future turns. In Galactic Civilizations II, the game would, in the background, play forward a few turns based on its best guess of what other players would do and then react to those future moves as if they were in the present.
Unfortunately, Elemental is a much more complex game (magic and all) from an AI point of view so it’s reactive. In time, as machines get faster, I hope to eventually create a more general land-based AI that can, like GalCiv, play turns into the future in the background. But for now, we’ll have to stick to reactive AI with future planning capabilities based on pattern recognition.
Now, before I go into the basic weaknesses here, it’s important to understand that Elemental is not a scripted AI. That is, I don’t program in to tell it to build this or that in some sequence. That would be easier to do to be sure but it would, in the long run, result in a game that would eventually become very repetitive.
Instead, my job is to teach the AI how to play the game and have it try its best to “win” the game based on a set of rules and conditions that it is trying to optimize. The problem with this is that until I get really good at the game, there’s going to be glaring holes.
In GalCiv, I was pretty good at it so I could teach that AI how to play pretty well. With Elemental, I’m still learning. When I read on the forums what people are doing I get the distinct feeling I used to get when playing Civilization and thinking I was doing well when I built my first musketmen only to have the Mongols land with tanks.
So here are the basic problems with the AI that I’m working on:
1. What techs are the ones it should get. You modders out there can help if you want to. The tech tree has an AI General section in the XML that I’ve started making more use of to tell the game what techs the AI should value more than others on researching.
2. The AI has a hard time planning ahead on resources. This is a classic issue for any game and it’s typically solved with directives. Essentially, the AI has a hard time saving up citizens to build things like Command Posts which in turn keeps it from building squadrons of soldiers. This is a high priority.
3. The AI is not yet good at specializing cities. It does specialize but some APIs I don’t have easy access to yet. For instance, the upgrade options when a city levels up have no AI data attached, they’re they might as well be random numbers.
4. General FOW issues that people tend to forget. I miss the guard tower. The AI was much better at seeing approaching armies with that.
5. How many soldiers should be left to defend a city? How close should a protective army be left?
6. What spells should be used when? There’s no AI data yet connected to spells (that’s a high priority to v1.2) so the AI has to pick things based on general classes. It’s gotten pretty decent at it but it could be way more optimal.
7. Unit design is very challenging in general.
So after, a week and a half of working on it, here’s where it’s at:
Me vs. AI.
TURN 5
ME: Malice

Starting position.
In my private build of tonight I made some significant improvements to how resources are distributed. I got very lucky here that I found a lost library so close. So this should give me a significant advantage.
AI 1: Altar

They picked a farm to build right away.
AI 2: Umber

They too chose to build a farm. They’re not hard coded to build farms, they just both decided this.
TURN 20:
ME: Malice

On turn 20, I’ve got my Beacon of Hope done, farm is built, I’m building a hut and I have a workshop. I’ve trained 1 defender and I have a Pioneer in training.
AI: Altar

So here I have my first problem. The AI is not constructing anything.
They’ve got a farm, a hut, a study, and a workshop. So they look pretty good. The city is lightly defended.
AI: Umber is doing better, they’re already level 2 on their city and they’re building their second labor pit.
So let’s go look at the code…
What is Altar…thinking?

Altar isn’t building because it’s saving up materials to build their highest end soldier.
Now, the thing is, that’s probably not necessary this early on. The problem is, the AI isn’t looking at threats very closely, it’s just “preparing for the worst”. A smarter strategy would be to have it scout a little bit better, find out the level of threat. If no threat, build up the economy. If only a minor threat, built a weak soldier and if the threat is significant then build up. Right now, it’s basically prepping to get “rushed” by either people or monsters.
So I’m going to work on this…
…
[3 hours later]
Side note, why do saved games take a long time to load on bigger maps?
Answer: All those fancy city improvements use 95% of the load time to regenerate. Going to see what we can do about that in the future. If you have a quad core (ahem) it’s much faster. But still, if we’re ever going to have sick sized, 64-bit maps, and we are, we’ll have to optimize this.
…
Now what does the AI do?

Better.
Let’s move forward a bit.
…

Learning spells. I always got for alchemy. Early on, money is an issue so I tend to try to get that right away.
I do think that the amount you get should be based on your intelligence and it should get more expensive each time it is cast by someone of your faction.
Turn 50
On turn 50 let’s see how things are going.
ME: Malice

The bear has me a bit nervous. I have a couple of guards in the city. I’m sending out my pioneer (escorted).
AI: Altar

They have 3 cities right away. Impressive if they can hold them.
AI: Umber
Here’s an issue I’ve been trying to resolve, the overdefense of a city.

No nearby threats and they’ve got a defense of 40. Let’s see why…
It just determined that it needed those units. I could quibble, but I will keep an eye on it.
TURN ~100

So Umber thinks they can take me. Let’s see if I can steam roll them still.

I have 3 good cities.
Umber has 4.


And here is when things get problematic. First, the unit’s weapon is pretty weak.
Second, it’s building individuals.
So we have some questions here:
1. Could the AI be training better units?
2. Is this the best possible design the AI is capable of on turn 100?
3. Could the AI build the war council and thus train multiple units? If not, why not?
So let’s look at those 3 questions…
To the question of whether it can build a war council, it does have the tech.
The problem: The War Council requires 35 citizens. As players know, that’s a lot of citizens and will take several turns of doing nothing empire wide possibly to get to that many free citizens. And that’s one of the big challenges – delayed gratification. It’s one of the things I’ll be working on that will make a big difference coming up.
If only the AI could cheat, it would be so much easier. 
So let’s try steam rolling them with my squads…
Ok, lost that battle.
They are building squads (teams?).

But they’re in no condition to go after me yet.
…
After much AI tweaking…
[5 hours of coding later]

Umber is closing in on me with their army but I have a pretty formidable defense.
Now, I could have taken them out earlier but I kept updating the AI. Tweaks here. New API there. Bug fix there.
I haven’t decided the best way to have the AI “save up” in order to build more powerful improvements yet when it requires several turns. In GalCiv, the AI simulated future turns and thus could just wait. Here, I have to come up with something different. Strategically (from a military point of view) this is the AI’s most significant weakness.
As you can see in the above screenshot, the AI will build groups of units. It just doesn’t do it when it really should.
I also need to get the AI to be far more aggressive about combining up. It has 6 armies in my territory but it would do well to combine those into 3 major army groups.
One of the big tweaks has been the AI taking a larger view of the battle field. It’s a more expensive calculation but with threading, it doesn’t’ slow the game down.
As a result, the AI is willing to send its forces much further away from home base.

[Another 3 hours of programming]

The AI is starting to get its act together on forming a more cohesive military strategy.

Combat rating of 155 means they’re ready to conquer.
Sadly for me…

Umber is fighting two wars at once as they slowly crush Altar.
So after many tweaks, the AI was victorious. But could it win without me giving it lots of second chances to get it right? Not in this game. The question will be, can it do it better in a fresh game?
We’ll see.
## UPDATE ##

The AI has gotten better at storing mana for future…use.