Deprecated: Function create_function() is deprecated in /home2/rpgdlcom/public_html/wp-content/plugins/php-code-widget/execphp.php on line 62

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home2/rpgdlcom/public_html/wp-includes/load.php on line 649

Notice: register_sidebar was called incorrectly. No id was set in the arguments array for the "Sidebar" sidebar. Defaulting to "sidebar-1". Manually set the id to "sidebar-1" to silence this notice and keep existing sidebar content. Please see Debugging in WordPress for more information. (This message was added in version 4.2.0.) in /home2/rpgdlcom/public_html/wp-includes/functions.php on line 4246
RPGDL » Blog Archive » Enemy AI, Why I stopped worrying and learned to love the RNG
Deprecated: Function get_magic_quotes_gpc() is deprecated in /home2/rpgdlcom/public_html/wp-includes/formatting.php on line 4365

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home2/rpgdlcom/public_html/wp-includes/formatting.php on line 4365

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home2/rpgdlcom/public_html/wp-includes/formatting.php on line 4365

Deprecated: Function get_magic_quotes_gpc() is deprecated in /home2/rpgdlcom/public_html/wp-includes/formatting.php on line 4365

RPGDL

An unparalleled source for RPG information and discussion

Enemy AI, Why I stopped worrying and learned to love the RNG

Posted by Grefter on March 24, 2011

A discussion about a few different ways to think of Artificial Intelligence. All of which doesn’t discuss much of anything, but is a lot of words. Do you want to read someone call Final Fantasy 6 enemies dumb and praise the suicidal Final Fantasy Tactics as far smarter? Well you can do so here.

Disclaimer: Post does not contain your daily quota of vulgar content. You will have to go elsewhere to get your hard swearing today. Read at your own peril.

 

Constructing a well made piece of AI either for an enemy or for uncontrolled party members has got to be a daunting prospect. It is certainly a piece of scripting well beyond my meager skills in that area. So as is a bit of a theme here, how does it effect the player? Lets talk about a few basic kinds of AI. Dumb party AI, smart party AI, stupid to average enemy AI and smart enemy AI. Also we might touch on just straight up Randomised enemy turns.

 

Dopey Party AI


Not particularly well constructed party AI is very frustrating for players. The definitive example that floats around seems to be Dragon Quest 4, it was the last game in the series to play with completely uncontrollable party members. You were in control of whoever the main character for a given chapter was and when everyone was in the party the AI would take over everyone but the lead for you. Now following on a series that originally was a single player character controlled game it makes a fair bit of sense, to a modern player it is a fairly dramatic shift from the norm though. Some modern games have done this also, Persona 3 for example which will come up in the next example, but Dragon Quest 4 is going to be our shining example of why bad party member AI can make for incredibly frustrating gameplay (I am sure I will win an award for stating the patently obvious with this paragraph). Some games have barely competent AI that will just scrape by like Star Ocean 2, where it can cast attack spells over and over no problem but couldn’t time a healing spell to saves itself and has no qualms whatsoever about spamming elements that the enemies absorb. That is dumb, but at least it is competent enough to get by. Dragon Quest 4 makes it a habit to have your healer spend MP trying to cast Instant Death spells against the final boss. The rift between semi competent AI and terrible AI is astounding there. It really doesn’t help that one is able to be fine tuned (You can manually turn off the ability to fast Fire spells in the Fire dungeon in Star Ocean), Dragon Quest 4 is bad enough to the point where the only way people really seem to have had a truly positive play through of the game is if they owned a Game Genie and could put in the code to control the whole party (or they played it on an emulator). I know first hand that it is more than possible to play through games on the caliber of Star Ocean 2 without fussing with the AI that much to have to control their every action. My understanding is that the way to play the original was to pretty much not trust the AI to do much of anything useful and if it did something smart then it was a bonus. It wasn’t that it was completely random. It was just that it was dumb as a sack of bricks and you have so little say over what to do. This unsurprisingly makes for a pretty terrible play experience. It isn’t to say the original was an unplayable mess that no one liked, just that given control of the characters directly in a Turn Based game massively improved it to the point where you can kind of understand why the series is such a long standing staple of the genre. So yeah, pro tip: If your game is turn based and you have written an incompetent AI then make it optional. You will alienate less people. This is your obvious statement of the day.

That isn’t to say there isn’t a place for party AI that is dumb. As long as it is entirely optional then it honestly isn’t a problem. Suikoden has amazingly terrible AI that all it does is basic attacks. It doesn’t even prioritise who attacks what particularly well (there is some of that though), but auto-battle there is a godsend when going through old areas or just plain in areas that are stupidly easy like Suikoden games tend to be at times. So feel free to keep writing basic dumb scripting, just apply it where it is useful.

Another one that springs to mind with varying success is one we will touch on more with enemy AI, but there is even optional modes for some characters where you forfeit control of the character to the whims of the Random number generator. Final Fantasy 6 is the one that comes to mind most prominently, of which there is three character choices that have the player forfeit control of the character and leaves actions squarely in the hands of weighted randomised actions. It is certainly not a method I personally prefer, but it is in game with varying degrees of success from terrible to middling to quite potentially game breaking (from my understanding Umaro, Mog’s Dances and then the top end broken that is Gau’s Rage options in that order). Not really an option that I personally like to use (much like self inflicted Berserk in some games), but it is an interesting trade off of power vs control that is nice to see experimented with. I can’t really say much on the success of it, since it is so varied in game. It is a path I tend not to take when offered, I like control. An interesting option regardless.

 

Smart Party AI – Vote 1 for 2012


There has actually been a few noteworthy games to come out in the last 5 years that use AI controlled party members, Persona 3 is definitely the first one that comes to mind as being fairly noteworthy for it. You have some degree of control over what sorts of things the characters will try to do and they seem to generally actually stick to it. They will capitalise on elemental weakness, which is an important element of the battle system as it ties up the enemy turns and exposes their weak point so that you can dispatch them easily. It isn’t always perfect, there is times where they should use Multiple Target weakness spells to tie up more than one enemy that they do not, but generally they are reliable enough to get you through the game. The main is still sort of dragging them through the game, but you can at least rely on them a pinch to not try status on status immune targets for example. On the third iteration of the game in as many years they let the player control the party members and it made the game far easier. I haven’t heard as strong a response from Persona 3 Portable as the other two releases, but that is what you are going to get with three releases of the same game in three years. I can’t say first hand whether it improves the game exceptionally, but I know I did read complaints that it made the game way easier (shock), but this is also from people that played each release of the game that came out in three years, so I do question the rigor of taking statements like that at face value. Regardless, so you can still make a game these days with uncontrolled party members and get away with it. Persona 3 is something of a cult game, generally well accepted by wider audiences and it goes completely counter to what I say above about bad AI. I honestly can’t tell you what else Persona 3 brought to the table that made it so acceptable, I wasn’t part of that wider audience that it appealed to (because I hate fun as discussed previously). Regardless of what it brought to the table though, the AI controlled party members in a Turn Based game clearly wasn’t a complete and total turn off for everyone and I understand that it isn’t a complete and total abject failure.

Another game that it has come up in is lately is of course Final Fantasy 13, the game that not only has AI controlled party members, but lets the player have the game automatically select attack options for them on the one character they do control. The auto-select and team mates will automatically target weakness as well. If you set the AI characters to status moves they will use only the ones that the enemy is vulnerable to or at least stop trying once they are immune. That leaves it so the player only is required to interfere during a critical moment or to change paradigm. Otherwise player involvement is just rubber stamping whatever the best attack is. Press X to let the AI win this war for you. I will let up on Final Fantasy 13 one day, but for now it is a shining example of well done AI pushing the boundaries past the point that I consider acceptable. The game is real time and the AI certainly helps keep the flow of battle nice and consistent, but it is not a net positive effect on the game. That such a hands off approach is not only a good idea, but already optimal irks me as to why this is even a game. It is a sequence of boring combat sequences chained together with boring combat sequences with even less interaction, in that you can’t skip the alleged gameplay sequences like you can the plot ones. I can’t really fault the AI for this, it is will constructed and functions at a fairly high level of AI. I certainly do blame the design choices that lead to such an AI system being required to keep the game flowing at the already amazingly slow snails pace that it does (see statements about how it gets good at Chapter 10 of 13). So smart AI isn’t always going to make an action based system amazing. It is entirely at the whims of the rest of the gameplay.

So there are times where a good strong AI can make or break a game, but I would definitely say with some confidence that good AI isn’t going to save a game. This puts it in something of direct competition with some of the polish I was talking about in World Building. World Building is far from integral to making a good game, but it can save a bad game from the trash heap of obscurity. Having a strong AI though, if it is necessary is something that you absolutely must invest a great deal of time into. I don’t think it is necessarily a bad thing to create a system that is entirely reliant on the AI being in direct control of characters, but it is definitely a restriction in design that I wouldn’t want to put a great deal of confidence into for an untested programmer or designer. So just something I would hope that companies are aware of, just how much this effects player experience in the game. This is yet another situation where Persona 3 kind of breaks all my rules though. It is a system that quite clearly does not need the party AI. It is something that I would argue would be vastly improved without it, but in spite of this it apparently works quite well for enough people to make it the successful game that it is. To be honest I am still absolutely in awe of it and the whole phenomenon.

One interesting little option that is kind of rare but neat is a smart (Or at least competent) AI that is entirely optional. The game that springs to mind the most here is Final Fantasy Tactics. Now I know long time players will have some horror stories where it does the dumbest thing on the planet, it is after all the enemy AI functionality, but the fact of the matter is that it is competent enough to beat itself at its own game. Final Fantasy Tactics has a complete enough AI system that there is challenges that have been done entirely utilising the AI system. You utilise some generalised commands (heal, attack, that kind of thing) and the AI will buff itself and allies up, work as a team and is fully capable of beating most of the missions as far as I am aware (I think you have to manually move units onto specific square to open Sluice gates or something on a map? My familiarity with it is limited). It is a case where it doesn’t really bring anything to the table, but it wasn’t something custom created for the party either. It is little more than a neat addition, but it is a fun option to have and one that I thought was noteworthy while on the topic.

 

Dumb enemy AI


Dumb enemy AI is fairly common, it works, it gets results, doesn’t challenge players to an astounding degree. It makes mistakes and is easier to write. Most of the time you won’t really notice it other than to go “Hahaha that was dumb let me put this pike inside you now ok?”. The place where amazingly simple AI stands out the most to me is SRPGs. Now this is far from the only example I will note here, but one that has a fair bit of play and is definitely in the limelight is Disgaea. Enemies in this game are dumb as a sack of bricks. They will group up so you can AoE them down like nobodies business. They will all charge in and berserker rush you at a hold point to be crushed. There is no long term planning, very little buffing once a target is in range. All there is to it is KILL KILL KILL. It is amazingly exploitable when you know what you are doing. At a basic level though? It is functional. It gets the job done. The enemy doesn’t just sit there and let you punch it in the face. It is responsive and does something. Dumb AI isn’t necessarily a game ender. It can go a long way to making the game boring, certainly, but this is mostly about a level of difficulty when it comes to enemy AI. It may give you moments of disdain from the players at times, but it isn’t going to be hugely impacting on the experience for the player unless they were expecting the AI to be something amazing. So pro-tip, if your AI is dumb and all you have done was add ways for them to jump out of cover then you should be fine. This again isn’t really a flaw in having bad AI so much as marketing handling customer expectations, which is a huge part of the customer experience. This might tie back into my preference for a game to be easy over a game being soul crushingly hard (Challenge is good, unreasonable challenge is bad), but generally speaking for me bad AI isn’t completely detrimental to a play experience for me. It may however just be the part of me that does enjoy the power fantasy in some games (see Grandia 2 article).

Another example of what I am going to lump into dumb AI is unresponsive, but highly scripted enemies. Final Fantasy 6 is going to be my go to AI here since it has a big audience and a decent hacking community as well, so the knowledge of the scripting in this game is fairly in-depth and easy to track down at a high level. Enemies in this game are completely and totally unresponsive. They will sit there and do their own thing unless explicitly coded to counter things. You can note this by things like the lack of offensive dispels and whatnot. How much harder would Magimaster be if he would counter your Life 3 with a dispel? Sure you could still beat him through many other methods, but it would keep you on your toes. Same goes for almost everything in the game and Haste. This is fine and perfectly functional, Final Fantasy 6 is balanced for it. For newer players the game is still interesting and even difficult, for advanced players it opens up all kinds of interesting pathways of abusing the game to completely dismantle it. It makes for a diverse set of options and is a big part in helping the longevity of the game. It is a good way to put a deceptively complex enemy AI into a limited space. At its clockwork it is dumb as a sack of rocks, but it works really well here. I list it as dumb because it honestly is and it doesn’t take a great deal of scratching beneath the surface to expose how simple it is at heart. There is an effectiveness in its simplicity which has some added benefits as well, not only did it take up much less space, but it makes for a very malleable set of code. Easy to implement on each enemy and allowing for greater diversity in enemy tactics. On top of that it has certainly done no harm in helping to support the modding community that Final Fantasy 6 has. Not necessarily a revenue generating component on the last part, but it does help to keep the game relevant and is a small win for the brand.

So dumb AI seems to be good to me, at least for enemies. It doesn’t add a great deal to the game unless you have chosen a design model that fits for it, but enemy AI is certainly less a hindrance to game quality like it can be for allies. For the majority of games it is certainly the more prominent one as well, so it is less impacting, but higher prevalence.

 

Smart enemy AI


I suppose I should really take the time out to justify by what I mean by Smart and Dumb AI, especially for the enemies. Since I went and praised Final Fantasy 6 for being stupid, I think it really deserves qualifying. What I am looking for in the AI is not responding directly to moves the player has done, but responding to the environment or things that could be incoming. It isn’t Dumb as in it is bad. It is just fixed in the way it handles situations. That is something to not be daunted by. Dumb simple solutions are often a good one. Complex important things are prone to break more easily.

Smart enemy AI is a bit more on the rare side, so I am going to be restricted a bit in this. I will be reusing one I noted earlier in Final Fantasy Tactics. The AI certainly isn’t up to snuff here to compete directly with a human, enemies tend to be working with some kind of advantage (Normally positioning I would argue), but the enemies are quite capable of functioning as a unit, using buffs (I believe they do this as a priority even). They will break your equipment if possible even if they could just directly attack you (net greater benefit of breaking a bow early over attacking an Archer directly for example). They will heal and even revive party members with some modicum of intelligence. There is always something left open for a player to exploit. It is smart enough to stand up as a challenge and varied enough given Final Fantasy Tactic’s class variety to keep what is basically the same level of competence in the AI different throughout the whole game. This makes for a fairly interesting argument, the AI in Final Fantasy Tactics though. Is it to smart for its own good? I think it likes to hit a happy medium where for new players it is a challenge and on replays the variety it brings still keeps it fresh. It takes a fairly experienced player with an analytical mind to really start to peel down the layers of the AI and just blatantly abuse it. Chapter 1 might be a bit much for new players I would argue, the AI has more in its toolbox than a new player does and starts with all the normal advantages. Get a player rolling with some skills and more to pick from than Attack, Tackle, Throw Stone and Potion and it picks up fairly fast. Honestly this was the first example and the only one I thought of for a while and I think it is a pretty good balancing act that it plays.

The next example is one that is pretty close to my heart, I love this game. It honestly has a fairly smart reactive AI when you dig into it. Sadly it is also a fairly negative attribute all truth be told. Baldur’s Gate 2, it is a great game. It is clunky these days with its approximation of the AD&D rule set jammed into a real time environment and pausing. The AI on the other hand is reactive. It is chock full of scripted sequences it runs through first, but it does respond to the environment. The classic scenario is the facepalm worthy Time Stop to pause time so they can cast a long spell uninterrupted, Gate to summon a demon. Then after Time Stop has worn off the demon attacks them because they haven’t protected themselves from evil. The summoned Demon is the nearest target and the highest priority because it will completely rape the mage’s face like a Sand demon through balsa wood. Mages are really the only point that the AI gets this chance to shine since everyone else is mostly just responding to whoever shot them in the face or punching things. That or just plain old pathfinding which none of the other games here really have had a chance to touch on, but something that needs to be able to be done reactively, therefore kind of inherently fits into what I have lumped together as Smart AI, but I wouldn’t list it as the primary reason. Also the pathfinding is more than terrible though, so lets not use that as an example. The AI does fairly simple things like it will dispel illusion or protection spells if it has relevant dispel moves memorised, it will use Instant Death spells that automatically work on summons. The down side is that it is about as far from perfect as you can get, it has big gaping holes that are open for abuse. It is really telling I think that the mods that make the game challenging and most fun pretty much dump the AI and rely much more on hard scripting of do this move, then this move, counter this with this. Just like Final Fantasy 6 did above. These tend to be more polished than the original boss fights in the game. Not necessarilly more fun to be honest, but they do give you a good challenge for the experienced player. Do I think the smarter AI specifically helps the game? Not necessarilly, it is part of the strange charm it has to it, but it doesn’t make the game great. It is other areas of the game that really tend to bring in the fans. Honestly I do feel the game doesn’t suffer overly much for having the big gaping holes in the AI, but at times it does feel like the AI is just spamming things at random.

You might note that the only games in this section are ones that have to handle not just responding to moves, but movement in an environment as well. This honestly makes sense, the more you need to interact with the more likely you are going to have to write a responsive AI to deal with that, so it makes sense to build on more like it. This isn’t really praising or damning the usage of this. It is just a question of the situation that you need to use it. For most RPGs though when you are just working on the level of abstraction where you don’t have an environment and just have 4 dudes in a row beating up on 6 enemies jumbled around the screen then you don’t have to have a reactive AI, you can just do it based on hard counters or scripted sequences of attacks. It is really a question of working with whatever tool best fits the scenario. That is to say, in most cases enemy AI doesn’t need this level of depth for an RPG. Party AI differs greatly, it does need to be fairly complex if it is forced on you. If it is entirely optional it can be as unresponsive as you want it to be, but it’s usage will tend to be fairly marginalised if so.

 

Random turns, how do they work?


There is really one other way to handle enemy turns, you can just straight up have their turns be randomised. You see this fairly commonly in early RPGs, but it still gets used these days. Good example is the likes of Dragon Quest which I think of the ones I have played has leveraged it best in Dragon Quest 8. I say this uses it best as this is a game where the randomised movesets actually work fairly well into forcing you to change your tactics. The really notable enemies in the game have diverse skillsets cpaable of chipping away at you with multitarget damage or punish with strong single target if you are lapse at healing. The best of the game even introduce Dispel which while a bit infuriating as a player, is certainly effective at forcing you to change tactics. You don’t know if you are going to have to rebuff next turn or not, so do you buff or don’t you? When your healer is one of your primary buffers as well there is some interesting choices that you have to make and unlike a scripted AI you do have to weigh up your options as to what is incoming next turn. This works really well here. It requires a carefully put together skillset to work, but in this case the implementation of it is entirely on the boss designer, rather than leaving some of it the hands of a scripter as well. The overhead for implementation is even less than that of scripted AI. It makes it easier to balance and places most of the onus on the design rather than later in the picture, which means it is something that can have been mapped out early in development, but thankfully it isn’t exactly a basic design principle for the specific moveset, so as long as you aren’t talking about scrapping randomised turns late in the project you are left with a fairly malleable combat system, can swap moves in and out and tweak them as desired, rather than having to remake a script just for a change of boss design. It is the simplest of the models looked at here, but it is still to this day fairly effective. I am glad it isn’t used everywhere like it was back in the day, but I am pleased to see people still utilising it.

Dragon Quest 8 though, what makes it work so well? The things that I think work best in it that honestly it escalates. Most of the game you don’t have to deal with Dispels, then in the last quarter plenty of bosses have it, you have a balancing act between limited resources, rebuffing and the potential to deal with a spike in incoming damage higher than the average. It is a mix of good skillset diversity with multiple turns that enemies get. To offset double acting feeling cheap the game likes to throw you a bone and the enemies occasionally have a move in the repetoire that does nothing at all. You always have a risk of higher than average damage, but if you take every turn assuming that the worst moves are used then you are going to run yourself out of resources fairly quickly. It makes the game an interesting balancing act. It also really does need to be emphasised that the game really does easy you into aspects of the battle system fairly smoothly. That isn’t to say that the game starts off easy, the first two bosses are probably the harshest because you have a small party and the only thing in your skillset is pretty much heal and attack. The game doesn’t hold back on the damage during these parts, but it also doesn’t throw Tension building dispel maniacs at you the moment you get your hands on Angelo. It is a well balanced fine line that I remember disliking at the end of the game when I played it, but upon reflection it is pretty well balanced line that it walks. Not every boss spams dispels in the last quarter of the game. The ones that don’t tend to be notoriously easy. It gives you a nice reflection on how far the system has come, a game that actually the frame of reference to have that kind of perspective is fairly rare. I really do appreciate a chance to see randomised turns handled with as much care and precision as this.

That isn’t to say randomised enemy turns is flawless, there is certainly plenty of ways you can improve it. Weighted chances are always a good thing, Breath of Fire 1 does that, with certain moves being used at higher ratios than others, that goes a long way to helping players deal with the incoming damage, but still keeping them wary. Keep your boss fights short though and there is a chance that they will just never see a specific move that you have at a low rate because of how dangerous it is. Another fun thing to do is bring in some scripting and have multiple actions, but have each action only capable of pulling from a smaller pool of moves than all the ones you want to use in a fight. It can help restrict the damage incoming or stop using specific moves together. This can be really fun when there is some overlap in the movesets and with differing speeds that moves come out. A small bit, but it helps mix it up. There is still certainly ways you can completely and totally screw up randomised turns, screwing up your weightings or just having terrible movesets will go there. So even though I don’t have a “bad” example for this one, don’t take it that this is my preferred method. I think bad examples of this are not overly hard to find if you have a visit from RPGs of Christmas Past. I really just wanted to highlight that this still happens and it is still worthy of a place in the market.

 

A conclusive statement of nothing.


So that covers a whole pile of stuff there. I don’t really think there is one way to do this stuff. It is refreshing to see all these kinds of things done when used properly. My personal preference does honestly trend to the fairly late 90s pairing of controlled party in a turn based system, so no real party AI there mixed with low fi scripted combat. That is just my preference though, I do enjoy a well put together reactive AI sometimes as long as the game calls for it. Well that is a lie, I do enjoy games with a reponsive AI that makes bad decisions all over the shop even more, but that is just where I get my enjoment from gaming. For party AI, if I can’t be in control of it, I am happier if it isn’t spammy and stupid. I don’t need it to play the game flawlessly, I just need it to be competent at what it does so I don’t have to micromanage it endlessly . Nothing frustrates me more than a game where you can’t directly control all actions at the same time, but need to be constantly directing things. Big offender here for me is Tales games on harder modes. It is trying to be an action game, but you end up spending far to much time dicking around in menus for its own good. Totally kills the flow if you aren’t abusively good at the real time combat.

My personal tastes aside though, I think there is a lot out there in the genre that has promise. When your base principles are still being effectively applied and competing with emerging new techniques there is a lot of room for growth. So AI is one area that I actually look forward to seeing how it develops in the genre in the next few years.

I don’t know how to end this article. So this sentence will do.


Notice: compact(): Undefined variable: limits in /home2/rpgdlcom/public_html/wp-includes/class-wp-comment-query.php on line 860

Notice: compact(): Undefined variable: groupby in /home2/rpgdlcom/public_html/wp-includes/class-wp-comment-query.php on line 860

Add A Comment