As some of you know, I’ve never written tactical battle AI before. Galactic Civilizations and Stardock’s other games didn’t have tactical battles. War of Magic had tactical battles but I wasn’t involved in that portion of the game.
This series of journals will take you through the journey of how to write AI for tactical battles. In my experience, games have tended to have pretty crummy AI when it comes to tactical battles (War of Magic no exception).
So for starters, I’ve got help. Seasoned developer Charles Lentz, who has been at Stardock for some years now, is assisting me on this project. The first thing I asked him to do is make it easy for me to do mock battles. When I was working on War of Magic v1.4, which was the first build I even got to look at how tactical battles were done, I noticed that there was no way for me to conduct mock battles. I’d have to “get lucky” and find an AI player who could cast spells to see if it even worked which was time consuming.
So for Fallen Enchantress, I asked Charles to set up a cheat key that would create opposing armies and that it would read from an XML file that I could mod to decide what powers those units would have. That way, I could test out all kinds of combinations.
Since I come from the modding world, I prefer to have my games let me, the player, mod as much as possible. My AIs have not been very moddable in the past because, frankly, the coding necessary was far outside my area of expertise (i.e. making it read variables and data from external XML files rather than just hard coding it in C++). But with Fallen Enchantress, Charles is going to take care of that for me.
So one of the things I intend to do is stuff as much data as I can in XML files. I want to be able to have the AI gather as much data as it can about who it opposes and then look at the XML data to help it decide what to do.
That means I want to make it so that every spell, ability, weapon, etc. in the game has in its XML AI data that I (or others) can mod with good things to go against it.
Does the enemy side have a spell that rains down a fire storm on me? Then I want that spell to include in its XML what spells are good counters to it. Then, the player comes in with his fire mage and the enemy casts a frost shield on her first turn.
Moreover, this gives me the excuse to request the UI team to let both sides see what spells/abilities each other have easily because a good tactical battle, in my opinion, should be a real battle of wits making use of terrain, spells, counter-spells, and maneuver. And the more data the player gets to see, the more data I can let the AI see without “cheating”.
Ah, we disagree on that then - I think the more complex but robust system is better.
Consider: if you have spell-name-only counters, then you can still not force the AI to use a specific spell as a counter. Assume you specify "A", "B" and "C" as counters; it could just be that the AI decides to stick to "A" and "C" and simply not use "B". You could implement it that there's a percentage weight indicator with each spell-name specified; or make the order of specification relevant, but that doesn't really solve the underlying problem.
Consider additionally: the [tag] system itself would be part of the AI system; so getting back to "Spread Disease" [disease], [resistance], [immunity], let us assume that the AI knows two spells that would qualify as valid counters:
"Immortal" [all-damage], [immune], [self-only]
"Panacea" [disease], [resistance], [aoe]
The AI can now, based on its sovereigns preferred strategy and the current tactical situation decide whether it wants to protect just one unit perfectly; or all units partially. If it is the necromancer, he doesn't care about his minions (and they (undead) tend to be disease immune anyway) so he uses "Immortal". But the nature-loving hippies from the Rondo mountains have large masses of weak forest creatures that win by overwhelming by numbers - and here the AI prefers the [aoe] spells. Factors like own-army composition, casting time, casting cost, etc could all be captured in the evaluation process and balanced against the options available.
Let us extend the AI's thought process by adding the following tags:
"Immortal" [all-damage], [immune], [self-only], [short-duration], [medium-cast]
"Panacea" [disease], [resistance], [aoe], [permanent-duration], [slow-cast]
"Crystal Cures" [disease], [poison], [resistance], [aoe], [short-duration], [fast-cast]
Suddenly the AI can decide if the spell is a suitable counter given the time available; or the time required for it to be useful. Additionally it can see that "Crystal Cures" provides protection against an additional damage type - and it might know that the enemy uses blight magic (disease and poison). Alternatively, it may know that the opponent doesn't have access to poison magic making "Crystal Cures" less attractive.
The point is the tags allow the AI to develop a form of understanding of the function/purpose of a spell - allowing it to make more informed decisions.
Consider this case: "Purge Unclean" - reduces the targets fire-resistance by 50, but gives the unit immunity to disease. This is a valid counter for "Spread Disease"; but it might be a horrible idea to cast it if the enemy is a disease spreading pyromaniac. A spell-name-only counter list cannot capture this nuance at all; a tag system could be able to.
Of course. The tag system is there to facilitate this process, not replace it.
Honestly, I wish the tactical AI was "good enough", so that AI vs AI tactical battles could be used as quick battles, and units with abilities would be properly valued.
The problem is some of those abilities are only really fun to see in tactical battles.
This is generalising hugely. Battles with bandits and wolf packs, sure - you don't want these skirmishes to last for more than a minute or two. But surely there will be some battles that you DO want to take longer over, and use your tactical abilities to plan and win. To dismiss tactical battles as 'mini games' would be a great mistake, I think. WoM and FE are set in worlds at war - and so battles will be hugely determinative in victory or defeat. Some heroes will have little more of a role than to buff towns and cities, but most of them are there to fight for us, as are the units that we train. And why go to all the effort of levelling up heroes and training better units, if at the end of the day the tactical battles are merely afterthoughts. I know that this will not be the case in FE, but Frogboy's attitude here is slightly alarming.
I agree.
Best regards,Steven.
If they hold that little value why have them in their own little pod at all? Why not just keep the battles with the same AI considerations you're doing on the main map? We'll still be doing that tactical battling but in a more direct response to our strategic metagame. How many battles are expected to happen in a war, how decisive is each battle? Is everything wiped out in defeat?
@larienna
My favourite was RTK6 with its semi-real time approach.
But RTK11 also had good approach to unit skills which had you having units work as a team. For AI to do that, is a very cool thing; especially when it destroys you in epic combo attacks.
I would like to hear Frogboy's thoughts on how the AI will decide to give priority to targeting;
Will all sovereigns will have the same attack priorities and use the same AI rountines?
Will all sovereigns focus on defensive casting? Hopefully not.
Example, where the Trog Sovereign is offensive magic focused and the Mancer Sovereign if defensive focused.
When faced with a Human Player who is preparing to cast Fire Storm the Ai response is;
What I don't want to see is a case where the AI is always casting defensive spells, while the human player is free to rain death and destruction on the enemy.
Hey, can the Frogmeister, when he finishes the basics like counterspells, set up some systems for the AI to play dirty tricks on us? I was thinking that if much of the AI's thought is on countering, so will the human player think. So, say the AI sets up a one-two punch with different elements, going from a medium spell in say fire, only to follow up with frost. That way we of course would want to put up a frost shield to block the fireball that just killed a novice spearwoman, only to be penetrated by Blizzard of Aemon.
Now we realize the AI was only a novice in fire, sneaky monkey. I would think you would set up a minor spell focus and a major spell focus value in the xml tags. That way you can have a less predictable offense to deal with, making it harder for a human or alternate AI to counter.
So is that something that is feasible?
Sounds like King's Bounty: The Legend, which has quick but really awesome and fun tactical battles. If you guys can deliver something like that then Fallen Enchantress will rock.
I assume you're going to retain the auto-resolve feature? If you can get the AI playing a smart tactical battle such that auto-resolve doesn't inevitably screw the player then you'll have the best of both worlds.
I will always do a manual tactical battle. I like to role play during the battles. The units get quite a bit of dialog.
KINGS BOUNTY has the best tactical battles there is.
I never played, but according to the screen shots, it looks neat. Is it only a PC game (any console version)? Not sure my PC could run it.
ON ething for sure, the combat needs to run fast. According to the comments, Kings bounty combat were running fast, which somewhat surprises me for a game that seems to focus on tactical battle.
Else ...
Why not make it a puzzle game like HOMM: Clash of heroes
Am I correct in saying that the game is already made? The content is decided. Changing any of it now unless it is totally broken will certainly derail the project. We should spend less time talking about how other games were great and a little more on the capabilities of this one.
I think the problem is that none of us have seen a tactical battle, or complete spell list. We have some things to base it on from previous posts, but it might be nice to see a play by play that you are running, Frogboy. I keep imagining a scenario based on the new round system and weapons we were shown, but the only spell list I can imagine is the one that was WoM spells, translated to the new game. I realize these are not the only spells, so give us more to see.
I would also like to see some xml tags so that we modders can begin thinking of how to mod spells with the new AI rules. Since there are spells that are great against stacks, can we expect to find a tag for "useagainststack" or "protectstackfromspell?"
I really liked your style of showing us how you built the AI for GalCiv2. I still go back and read them sometimes.
I would prefer a bit more fleshed out battles actually. The issue I have with KB (and similar games) is that you might as well auto resolve, the battle outcome is pretty much given on turn 1 and you always perform the same moves. That kind of Tactical combat is more puzzle game than strategy imo.
Battles in King's Bounty happen at a pretty decent pace with only a handful of units per side (if I remember correctly, the player is limited to 5 units plus the ability to cast spells onto the battlefield). While the game does feature tactical battles very prominently, they're basically used as monster encounters when you're out questing, so it's possible to play as many as a dozen battles in a single hour-long gaming session if you're really aggressive.
You're talking about AI that is capable of "functioning" on the metagame level. IMO this can only be scripted in our AIs with today's' technology.
If you can think of a way to do this in general AI code, and without hard coding the strategy then:
1. You will become famous and rich.
2. SHODAN is watching you...
There is also the case where Kasparov (?) lost a game to Deep Blue (?) - and was surprised to find that the AI did a move that seemed sub-optimal by sacrificing a piece. Only in analysis later they discovered that it hadn't been a sacrifice so much as a move that payed out only 20+ turns later - a point in time where the human player doesn't hold the full board position anymore, but the AI simply brute-forced its way through possibilities and determined that it was a worthy move.
I think you guys are too concerned with the process and not the result. Giving the AI a major and minor spell class and making it choose between them is so simple. The end result is confusing a human that is only ready to defend against one element. You should be able to make this kind of AI choose a suboptimal spell and attack the weakest unit without much trouble. The hard part is what to do once the human or other AI has learned that trick. The AI would only need to do it once, as humans will invariably assume an AI will do it every time. So in the second battle the AI would go straight for his major spell class. The third battle would be 50% chance. as would the 4th. A total randomness would then be used after this. Humans are so predictable.
Admit it, this would have taken all of you down. I can sense you clicking quickload even now. Guys, Frogboy is an AI genius. He can do what I have described. The question is whether or not it is something he wants to put time into.
The best part is that as the game progresses new shards will be acquired, causing new mages to be trained that have a different set of major and minor focus. That means you will never know which spell to expect at any given battle, unless you are mapping out enemy shards and keeping a journal of every wizard you fight. This is admittedly a far cry from what Frogboy is planning I would think, which is why I wanted to know what he thought of it. I am also curious as to why two people think this is so improbable.
The main point is to push for zero information about mages on both sides. The less we know in the first battle, the better. The AI in GalCiv2 was really good at fighting a battle and then coming up with a really good countering ship. This is the same but with many more weapon types.
How does the AI know what a spell does? How does the AI know when to use a particular strategy?
Just wanna chime in that, King's Bounty has the best tactical combat (TC)experience in recent years. Copy 70% of KB into FE's tactical combat system, 20% of your own innovation then it will be great!
Maybe then put some effort on adding Siege and wall related rules, making the TC map tiles matches the strategic map, escape/retreat/subdue rules, basic flanking, basic ZOC, and basic LOS rules.
In KB, they don't have smart AI at all but AI spell casting is still very nice. The reason being that every single spell is designed to be useful, even if the AI is not truly smart, whatever spell it cast onto players will not be wasted. The worst case is just that it does not deal as much damage but it is not a big dealbreaker for the game.
For all we know, the FE tactical is the best...
I've heard rumors that FE battles give you cancer...
The problem is tactical battles are in fundamental opposition to a strategy game. They're fun though, as it's the way to see your neat and cool awesome abilities that you picked.
There's also the issue of different abilities having different weights in strategic and tactical battles, which is unavoidable.
One idea for an option: semi-tactical battles: basically grunt units are controlled by the AI, you only control your champions and what spells are cast. I'd love to see that idea tried. Maybe there would be a trait that would let you control 1 unit additional per turn per level of it.
Generally, I think most people use tactical battles as a shortcut towards winning the game.
I do think tactical AI is a whole lot harder to design for then strategic AI, and I do have doubts about Brad's ability to do a great job there (I've never seen any strategy game do a great job on tactical AI), though I think Brad has a better shot then anyone else in the industry- I just think it's an impossible task.
As for randomness and AI "mindgames"- I think Sirlin's "Playing to win" series is a good inspiration for AI designers- as that is what humans do to each other in competitive environments, an AI needs to be able to handle that through intelligent randomness.
This is my dream for the future. A high-quality total war-esque realtime combat, with hundreds of thousands of units that are mostly operated by the AI after initial battle plans have been laid out. The user controls heroes or possibly legendary units with a few hundred men, operating within the war. All set in a high fantasy environment. The scale is immense - you can view it all from above, see the dragons soar and torch the landscape, see the siegetowers roll up and be torn down. Or you can play one of the heroes standing on the ramparts, arrows flying past you, a hundred thousand orcs and a hundred thousand goblins below rushing forward. Mighty wizards fly across the battlefield to fight the dragons, and unleash nuclear-level devastation when left alone. Assassins dispatched to the enemy command chain - but can you make it back alive? Giant warriors that stand in the thick of it all, breaking the tide. But keep moving, or you won't be able to wield your weapons for all the dead bodies around you. You can break any shield, stomp any snotling. But beware the cavalry, they'll outdistance you, do charges with lances. And if you go too deep, they'll encircle you with spearmen attacking in unison.
Just need the computers to do it. Strategy, in my mind, is the genre that has the most potential for future gaming precisely because of how it can scale. In another ten or fifteen years, FPS games willl probably look completely realistic. They'll surely invent new gimmicks to immerse the player - direct mind to computer linking would be a big step forward. But when it comes to pure computer power, strategy games will see the largest improvements in the future.
There are many great features available to you once you register, including:
Sign in or Create Account