Why FE&rsquo;s AI is good but not as good as GalCiv&rsquo;s

Why FE’s AI is good but not as good as GalCiv’s

I’ve ready a lot of comments on Fallen Enchantress: Legendary Heroes AI. I feel confident in saying that most people seem very satisfied with it overall. But I think most people would say it’s not quite as good as GalCiv II’s.

In some respects, the GalCiv series is an anomaly. I’ve been programming AI on GalCiv games for 20 years. Let’s put that on the table for a moment and consider the ramifications. Can anyone think of a game, any game in the history of game development, where the same individual programmed the AI for the same franchise for 20 years. That’s why the AI in the GalCiv games is so good. I’ve had 20 years to digest people’s ideas.

Similarly, a couple weeks ago we released FE: Legendary Heroes 1.3. As many have observed, the AI improvements in it are nothing short of spectacular. But that’s not because I suddenly became a better programmer (I wish! <g>). It’s because I’ve had just that much more time to play the game, read the forums, watch “Let’s Play Videos”.

Probably the biggest advantage the LH has had in AI is that pretty much everyone has multicore setups. I can’t promise this but I think LH may be the first truly native multicore AI that’s been developed (it certainly won’t be the last). That is, every AI player gets its smarts spawned out to a different CPU core. That’s why the turn times are much shorter than in most games even though the AI plays pretty well without having to cheat.

Why we don’t like cheating

I’ve gotten a lot of email from people asking why I don’t just have the AI “cheat” on the challenging and normal difficulties. And I think there may be an age thing. People of my age (around 40) really really hate cheating AI. I think it hurts the game. I think it hurts the game because when I play a game, I want to feel like the AI is playing the same game as I do.

Even on the harder levels in Legendary Heroes, the AI doesn’t just conjure up units out of thin air. We just give them more gold or more HP and other things that players can understand and react to. We don’t, for instance, spawn enemies out in the FOW (a very common trick on our industry). The AI has to have the resources, even on “ridiculous” to create those units. That matters because players want to be able to knock out iron mines and stables and know that this is going to impact the AI’s ability to create those units (same for wiping out shards and spell casting).

What’s next

I still think of Legendary Heroes as a new game. New DLC is in the works, new updates (1.4 and 1.5) are in the works. The success of the DLC allows me to pay developers to keep enhancing the game.

So how do we make the AI better?

There’s just no substitute for time on this. When people play the game and post, I read. And I conspire how to thwart their plans. Like many of you, I enjoy playing the game and thinking of ways to wreck it. I’m a lucky guy that I get to spend time with you guys and brainstorm new strategies for the AI. I do feel bad for the amazing experts who won’t get to see the expression on those new players who suddenly see the AI doing something clever.

But I think, you and I, together are doing something really fun for next-generation gamers who will realize that 4X games are, actually, pretty darn amazing.

Can you have a look at the AI not summoning in tactical battles, or rather as may be, not summoning period? Even if some kinds of summoning (such as strategic) are quite hard to program, monsters that can summon should be pretty easy to program because they are not using mana and they are much stronger when they summon (like the Ritualists summoning death demons). But tactical summoning by AI players does need to be looked at, because a tactical summon can sometimes be the difference between winning and losing (at least in human vs. AI battles). This summoning problem I see as the core weakness area that still needs to be addressed, in most respects the AI is quite okay. Can you have a look at it?

The problem isn't the summoning part (that's easy). Getting the AI to think that it's worth the casting time for that summons has been the hard part. The AI tends to calculate that summoned creatures aren't worth it. Which begs the question, is that true? are we summoning creatures because it's fun but not tactically effective OR is the AI miscalculating?

Summoning is definitely worth it, but it's highly situational. It's probably a pretty big task to teach it positioning and timing. When is that warg going to die after one attack, and when can you use it to smoke multiple units.

If they can't understand the role of the particular unit being summoned, I don't see much hope for it. You'd summon something tanky to absorb damage and protect other units, while you'd use a fragile high attack unit to assassinate a dangerous ranged unit, or act as a second strike on something out of counters.

Doesn't the summoned unit die if the caster dies? If that's the case with Ritualists, it wouldn't be much use to summon a Death Demon and then get killed. Although with the low amount of damage the ritualist can do normally, it probably wouldn't hurt for it to start summoning the Death Demon at its first turn. Also, the summoning artifacts (Burning Wraith, Air Elemental, Skeletons) could be used by the AI players, since they don't cost any mana, and when to use them is not so important, unless they are going to sell them.

I think Ritualists placing a higher priority on summoning Death Demons and AI players placing a higher priority in using summoning artifacts would help the game feel like the AI is not missing an important part of it, even if the AI can't cope with the rest of summoning that well.

With regard to the summon being worth it, I think perhaps there needs to be a chance to get a critical success on the summoning and get two or more creatures instead of one, or a more powerful creature, or one that takes a turn immediately. Then the AI can weigh the possibility of the summoning turning the battle in their favour - as psychoak says, at the moment summoning is very situational.

Imho, casting summons is ALWAYS worth it if you're fighting a balanced or dangerous fight for your own settlement. A 40 mana summon is a much smaller price to pay than losing a settlement and its connected outposts. Most settlements at the very least have a shard connected to them any way.

In some ways, summoning is a bit like having a carrier which can launch a wave of fighters.

They have the advantage of being numerous, fast and presenting a smaller target. On the other hand, once they're launched the enemy can pick them off if they so choose, destroying that advantage. You have to weigh the benefit of launching now versus the benefit of launching later, when you may have taken some losses of your own and need something to turn the tide of the battle.

The problem isn't the summoning part (that's easy). Getting the AI to think that it's worth the casting time for that summons has been the hard part. The AI tends to calculate that summoned creatures aren't worth it. Which begs the question, is that true? are we summoning creatures because it's fun but not tactically effective OR is the AI miscalculating?

I'd rather the AI spent time summoning, than buffing other units with useless spells during battle. Especially when they have high attack/defense and could actually be scary to fight. Also, no not every summon is worth it, but Earth Elementals etc. usually are, until very late game.

(I somewhat fixed that problem myself by making custom sovereigns without magic paths, they were quite harder to fight than the vanilla ones)

Summoning is definately worth it. It's a guaranteed tactic for me when I'm outnumbered. Summon an elemental or some other reasonable hit point creature in the middle of the A.I.s army and most of their melee units will focus on it. Ranged A.I. units still focus on my ranged units for some reason. This gives my hero a few turns for spells and my units time to swarm and pick off enemy units one by one. Can't remember the names, but Celestial Warrior and Wisp (Mage class options) are very useful to turn the tide of a battle not going your way at early levels.

As others have said summoning is very worthwhile, if only for the fact that it distracts some of the enemy and helps either delay them or at least delay some of them so that they arrive at your front lines piecemeal.

Of course that might not work as well for the AI vs the player but there are still plenty of reasons why the AI should try summoning.

As another sideline, Frogboy might want to adjust the A.I.s behaviour so that it doesn't react to summoned creatures the same (i.e. instant focus) as that would reduce summoning as a useful player tactic. If it can make a threat assessment and say allocate one or a couple of units to deal with the summoned creature as apposed to its entire army.

Chiming in late, but I agree on what Sjaminei, Heavenfall and others have said. Summoning is worth it. All good players will rather summon that extra 'fighter' as MarvinKosh said then buffing a unit. The AI seems very fond of buffing. While buffing can be nice, summoning gives you an extra creature and thus extra attacker or diversion (aka cannonfodder). I hope the AI can adjust to that, cause with the great summoning mods out there, summoning is not only effective but fun too. I'm sure the AI would like to have some more fun too.

I agree with others, one of the main advantages of tactical summons is the way it increases the total size of your army, with all the implications that has for swarming etc., and also because it reduces the damage your permanent units take, increasing their survivability and chance of going up levels. Earlier in the game I summon units strategically because in most circumstances that saves mana, and it saves you a tactical turn with your spellcaster, but certainly when you have a full stack with other units it makes sense to summon tactically.

The fact you can summon anywhere on the battlefield means you can also attack ranged units you might not otherwise be able to reach. Conversely you can summon a unit defensively to stop their melee units reaching your ranged units.

Summon Skeleton Horde and Summon Lightbringer are always good. Some tactical summons with additional side effects are also good, if the AI understands how to use them (i.e. cast positive ones on maximum numbers of friendly units, cast negative ones on maximum numbers of enemy units). The Death Ward effect of Summon Grave Elemental has won me a battle against dragons almost on its own. Summon Air Elemental and Summon Ice Elemental can be good, although both are quite fragile, so you have to be careful not to summon them in too exposed a place where they can be killed quickly by the enemy.

There are several AI specific tactical summons such as Summon Death Demon or Assassin Demon which I worry that the AI will cast but it never does. It is a valid point that you still only have to target the summoner to kill the summoned unit, however in practice you would probably have to split your attacks because of being unable to move through the summoned unit's zone of control to get to the summoner. If the AI understood defensive summoned unit placement it would be helpful.

Other tactical summons are a bit more debatable, they can be helpful but it would depend on what alternative actions were available. In general however I don't think the AI casts enough spells which have a global effect (including summons) vs. spells which only affect one unit. The AI casts Burning Blade so much it's ridiculous! Burning Blade is almost certainly not going to significantly affect a battle; Mass Curse and Summon Grave Elemental, on the other hand, could affect the course of a battle. In terms of effectiveness for the mana I tend to think of global spells (Mass Curse, Titan's Breath, Wellspring, Wither) first, area effect (including Fireball etc.) spells second, summons third, initiative affecting buffs (Haste, Slow) fourth (with a preference for Haste because Curse might be resisted), and other buffs last. There are of course exceptions to this when you target one particular unit with Heal or Diamondskin or whatever, but I think that's a reasonable rule of thumb. The AI almost seems to follow the exact opposite rules! It casts very few spells except damage spells and self buffs such as Burning Blade. A high level spellcaster with sufficient mana would be a very scary thing if the AI understood how to cast tactical spells better. As it is, apart from Fireball and Horrific Wail, there is currently very little to worry about.

I belong to the minority who feel that the AI, even in 1.3, is significantly inferior to GalCiv2. I have not noticed a significant jump in AI behavior in 1.3 vs. 1.2, although I have noticed some changes, such as the AI's improved willingness to take unguarded goodie huts and to hunt monsters, and a somewhat higher willingness to produce Pioneers and escort these to better sites. The AI still fails to be more aggressive in warfare, select appropriate targets, and have a plan regarding what to do to facilitate victory against those targets. (The AI does not use magic well, nor does it design units well, nor does it perform nearly as well as it could in tactical combat.) Strategically, the AI's greatest weakness is its failure to plan and build cities. The massive bonuses the AI gets in "cheating" do, however, make the AI fun to play again up until the Mid Game is done. That being said, the game is very well thought out, and if the AI were to be significantly improved and the serious problems in unit pathing solved (including letting non-hostile units be allowed to occupy the same tile), this game will be as legendary as its name.

If you wanted to make a formula out of what the best spell to cast in a particular situation was you could probably come up with something based on hitpoints, attack, defence and initiative. So a damage spell is better the more damage is done to higher attack, defence and initiative units. For non damage spells, a Haste spell which boosts initiative by 50% gives you 50% of that unit's value, a Slow spell which decreases initiative by 50% but has a 50% chance to be resisted gives you 25% of that unit's value.

For spells which cause units to miss a turn, get 50% of the value of that unit, multiplied by the chance of success (i.e. if there's a 75% chance of success then get 37.5% of the value of that unit). Clearly if chance of knocking a unit prone is 0% then casting the spell on that unit has no value. 50% of a unit's value for missing a turn might be a bit high, but forcing units to miss a turn is generally pretty devastating as battles are over quite quickly. The automatic hit on prone units is significant, as well.

Mass Curse gives you the armour value of all the enemy units (taking into account their chance to resist). Wither gives you the attack value reduction multiplied by number of enemy units, taking into account their chance to resist.

For summoning units just add the value of the summoned unit. Arguably it should be less because the summoned unit will die if the summoner dies, however arguably it should be more because of the swarm effects.

Death Ward should give you at least 50% of the value of that unit. So Summon Grave Elemental should almost always be a good idea if you can get Death Ward on three units.

For buffing units add the amount buffed (depending on the relative weighting for attack, defence, hitpoints).

Divide values by two if it takes two turns to cast the spell, divide by three if it takes three turns to cast the spell.

The idea behind these changes is to promote the AI behaviour I've been talking about, i.e. encourage it to cast spells which affect lots of units, and reduce the number of times it casts minor buffs on individual units.

I don't generally think it should worry about conserving mana; if the tactical AI is running then it's fighting a human and is going to need all the help it can get, it should just cast the most devastating spell it has the mana to cast in each round.

The problem isn't the summoning part (that's easy). Getting the AI to think that it's worth the casting time for that summons has been the hard part. The AI tends to calculate that summoned creatures aren't worth it. Which begs the question, is that true? are we summoning creatures because it's fun but not tactically effective OR is the AI miscalculating?

Thing is.... I don't get how it's (much) more complicated than other spells.... such as buffs/debuffs. For example the AI casts something like Shrink a lot. There is some complexity around whether it's worth it using the mana, when to cast it, which target to choose etc... but sure enough the AI does cast it. I don't see how something like Summon Shadow Warg is a great deal more complicated. It's always going to be of use. Just cast it straight away if the spell is available.

I think something definitely isn't right right with whatever priority calculations for summons are currently used. The AI *never* casts tactical spells going by the feedback in this thread:

http://forums.elementalgame.com/447685/page/1/#3393328

It's almost like the AI calculates the priority for summons as always zero. This seems to happen regardless of the <AIPriority> tag.... even if you crank it right up, no summons.

Summoning units in strategic and tactical is fun. But it's also effective. We want the AI to drop Air Elementals and Lightbringers and Skeleton Hordes on us

This seems to happen regardless of the tag.... even if you crank it right up, no summons.

I agree, the fact that tactical summons seem to never happen, even after modding, suggests that it is at least possible there's a bug involved. Either that or the priority tag does not work as people expect.

If you battle a guy and it looks like he has 3 troops but is able to bring in a 4th that's a bait and switch on you and you have to adjust when you realize you are overmatched.

A summon can significantly alter the course of a battle and make a close contest into no contest. Even if you forced summons to occur in the first turn instead of working the calculations to decide a time tactically when it could be used to swing a battle it's still better than no summons at all.

Where to summon? There are a few options. Generally I'd say right next to the most dangerous target out there although they could be used as meat fodder to slow an advancing enemy and provide a caster additional time or to appear behind enemy lines and harrass archers in the back row.