20091019

MMO Spells and AI Support...

                A couple weeks ago (article link), I mentioned that I had a future article that would discuss a Spell System for MMO’s, and the supporting AI for it.  I first wanted to have a general AI discussion first, so there was a little supporting knowledge here.  One of the problems that is faced with AI developers for MMO’s, is how to make monsters think more intelligently.  Usually the AI is supposed to just “simulate” intelligence, not actually learn.  Little Dumb AI’s stay the way they are, and so do the tougher ones. 
                I’m sure most of you have noticed, that after a little while, you learn exactly what you need to do to remove a particular type of monster in a game.   But what if that kept changing?  What if Mario jumped up in the air, and a Gumba decided to step back for a second, then move forward; Mario would have to smarten up as well.
                The problem is that simulating intelligence, and developing a learning system are two very different things.  As I mentioned in AI, one of the scariest things about AI was simply not understanding how to make it work.  So what about Learning AI’s, not just reactive ones?  How do we approach that?  I’ll answer that in a minute.  First I’m going to throw another wrench in the works.

Spell Systems...
                This will apply to more than just spells, but this is a logical place to start.  Spell systems usually come in one of 2 flavors.  1) They are hard coded in to the system, causing restarts if changes are required.  Or 2) A separate scripting engine is implemented so spells can be changed on the fly.  There is a third option, that I’m going to discuss now that is far less employed and a lot more effective.
                Plug-in Spell systems.  Plug-ins that can be added, removed and upgraded without needing to shut down the system.  While there are plug-in systems that exist for most languages, I tend to favor Dynamic Assemblies in .NET.  Where you take code in the form of a string, and it gets compiled in memory (not to a file) and tapped into your program through .NET Reflection. Visit http://www.west-wind.com/presentations/dynamicCode/DynamicCode.htm for a sizable example of it, and http://stackoverflow.com/questions/826398/is-it-possible-to-dynamically-compile-and-execute-c-code-fragments is a very simple representation.  (Of course any plug-in options leave strong security holes that you need to watch out for.)
                This makes it very simple to upgrade and alter spells without affecting the system as a whole.  Allowing for a wider base of users to start creating possible spells.  It already has a language, and you get the source code to review for hacks, prior to submitting it to your system. 
               
Back to the A.I….
                So, AI is one thing, when you have a defined set of things that can happen, and you know them all, but a whole other thing when you are talking about a system that changes and grows.  How is AI supposed to deal with that?  Here is a system you can use to allow A.I.’s to learn and structure themselves dynamically in the game.  This isn’t a small system, but not that large either.  Once built the benefits are amazing.
                First, I recommend developing some sort of tap for your game, possibly using something similar to the spell plug-ins, but I recommend a networked connection, so the processing work is moved to other hardware.
                Establish danger points in your game.  For instance, the deepest point in caves, or the largest room of an abandoned city.  This works best if you can pragmatically define them, like farthest tip of a cave.  Then when Monsters are introduced to the game, they randomly seek out these places as targets.  This keeps your creatures moving for you. 
                Next, when they reach these places, they try to establish paths to the strongest point, like A* path finding.  Then, as long as no PC’s (Playable Characters Vs. Non-Playable Characters) are around, it will engage in battle with any NPC in its path.  During the battle, it will monitor certain values, like Hitpoint/percentage, magic points, damage inflicted, and companions hitpoints.  It will also track changes in the opponents metrics.  Keep in mind that there are different AI’s running at any given time.  Certain characters subscribe to different AI’s, each developing on their own, and maintaining separate recordings of metrics.  Different characters subscribe with different random variations of spells, abilities, experience and difficulty levels.
                So when a spell is cast, it records the affect that spell had, improving your health, your stats, your friends health, your friends stats, and how it damaged your opponent or group of opponents.  Each on being recorded with averages for that spell usage.  An under experienced monster might have bad experiences with a spell, and ignore it, which means that AI won’t learn as much about it.
               
                When the AI is in battle, depending on it’s level, it will try anything at random, and then as it improves, it will choose intelligently more often.  For instance, it will take a look at it’s current levels, for hit points, magic points, and try to decrease the opponents stats, while increasing its own lowest.  If a particular are like hit points is dropped to a certain level, it will focus increasing it. 
                As the AI completes its battle, both characters are returned to default conditions, and the loser takes the previous space, intending to sit for a while.  The winner will move on to the next closest space to the middle, (it should also look at the difficulty of that space compared to another adjacent space and try the easier one first) 
                This generates a standard flow of easier monsters first, and the strongest monsters are always found in the hardest to reach places.  The real system comes down to monitoring the changes in metrics, and comparing which one will bring you to the strongest next value. 

                Weaker characters will roam more, being found at random by your characters.    A great way to structure this is to setup Target points at safe spots in the games, like town halls of inhabited areas,  monsters will be randomly drawn to it, with the possibility of taking it over, if players aren’t working to save it.  Towns can be one and lost by the players.  Having real lasting effects on the game.  What was once a thriving metropolis could become a haunted ghosted town.

                Naturally, there are a lot of angles that this AI can quickly jump towards, and a lot of tuning that may need to occur so it doesn’t become too difficult, or overrun your towns too often.   But certainly adds a nice changing, growing element of your game that will allow your AI’s to learn, and automatically grow to help a game. 
               

No comments: