20091026

Next Evolution of the Cloud

                Before you read this one, I would like to point out that I’m going to get a little out there.  It discusses the direction I think technology will be taking, and the future that computing will be leading.        Its hard to discuss such radical shifts without sounding like a fanatic.  ;D

                The cloud is an ever growing change to the future of technology.  Lightly spoken, the cloud is many computers acting as one, and while such technology has been around for decades, it has not taken on such a common place in our market until now.  But to really understand the future of computers, you have to understand what the current limitations are, and how to hurtle past them. 
                Cloud Architecture’s current nature is that of having your application duplicated across many machines, and when different users log in, they get passed to a particular machine.  Essentially, the machines think they are standing alone, as the only server hosting that website, and connected to the only database providing it with information.
                But in another major shift in technology, we are seeing a new birth in Thread/Parallel based programming.  Making singular applications being able to spawn multiple threads and multiple processors.  Similar to cloud computing, threading has been around for a while, but with the shift from singularly powerful processers to an array of processors, the direction for threading has become front row in all major applications now.  Even games are starting to jump on board. 
                What the future will hold will be fragmented applications.  Application pieces that can interact with each other over networks, to form singular cohesive units.  A single application as a whole that spans unlimited machines.  Each fragment containing the ability to be upgraded, replaced, called on to do things, and referenced for information.                
                Already, we are starting to see hints of databases becoming dinosaurs.  I know, those are bold words, but think about this.  To deal with databases living in a cloud world, Microsoft is putting a base limit on their database size to 1 gig per database.  It makes it easier for database servers to stay synced, updated and failsafe.  But that means that the database is no longer this giant source of data, but multiple sources of data spread over the network, and multiple machines. 
                The next logical step is to realize that with all this redundant information so easily available to the applications, why not let the applications hold on to it.  Having a reference directly tied to the data is often easier and faster than having to look it up.  a powerful server with 16 gigs of rams can be purchased for as little as 2000$. 
                Databases are tried and trusted, and it will be a long time before you start seeing the right mix of investors, architects and developers really stepping foot into this.  It is sort of scary.  But not to different from the internet itself.  What it naturally grew into.
                Long ago, on the first systems that were stably networked, there was only a couple applications that could speak to each other.  You had to know specifically what you wanted, where to get it, and have the right tools.  But that branched out.  It grew to the point where there was no longer a limited number of applications that could be managed in a central repository of systems.  Eventualy it became millions of systems, billions of IP’s and as much data as we have to give it.   It grew into hundreds of systems living on their own, but yet all interacting, referencable, reacting, changing. 
                Applications will take a similar path.  Now, the developers are comforted by the fact of knowing that another system is maintaining the data for them.  That there are other means of recovering it than the applications we build.  But it will shortly become a crutch to more than just our minds.  Soon it will hold back the walls of progress, until more developers are willing to release their ties, and start moving to a different future. 
                What searches are needed, when everything already has it’s appropriate references.  How will we model the data, when we can have it all as flexibly shaped as XML?  I urge you all to start exploring possibilities that can extend to a database-less world, one where reference superceeds lookups.  At least keep your mind open to it. 

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. 
               

20091012

Starting out with AI

                I remember how AI appeared before I had the opportunity to really learn ways to make it work, or even, what qualified as AI.   It was scary.  It was one of those impressive things that you have to be a genius to build.  Of course most things either seem too easy, or too complicated if we don’t know how they work.  This article is a little introduction to AI, and how to apply it in games and applications.
                The most basic purpose of most AI’s is to turn everything into a number.  Place a value on it.  Then the AI simply chooses the highest or lowest number.  The trick is deciding how valuable things are.  Let s pick tick tac toe for a starter.  AI in tic tac toe is pretty simple.  For 1, you could literally record all the possible moves, and give your AI the solution it needs to always win or tie, but never lose.  But that’s no fun, and every move is pre-programmed.
                To turn it into a metric, look at the paths needed to win.  First move, When you place your X, where will you place it.  I recommend taking a look at each space on the board, and counting out how many possible wins you can have from it.  For instance, placing one in the middle gives you 4  combinations to win.  And reduces any move your opponent could make down to 2 possible wins.  The next opponent AI has only corners and sides to play on.  By reviewing the side pieces, they realize that it would give them only 1 chance to win with it, and only reduce the opponents possibilities 3.  The corner allows for the AI to have 2 possible directions to win, while the opponent also gets reduced to 2. 
                That was a simple suggestion.  Comparing the number of possible wins a move will give you vs. your opponent.  In more complicated games this gets tougher to define.  Moving on to Chess for instance, where there are many possible moves, and many of them are very different.  In the first ten moves alone, the total number of possible moves = 169,518,829,100,544,000,000,000,000,000.  So, unlike tick tack to you really can’t just record all the possible variations. 
                So how do AI’s do it?  It’s not reasonable for a computer to step through that many moves, and that’s only ten.  And there are times where humans can identify a checkmate in 10+ moves in advance.  So how on earth is that possible?  It’s is more achievable when you place values on moves you make.  For instance.  Your opening move can have 20 possible moves.  (each of the 8 pawns can move 1 or 2 spaces, and both of your knights can go forward to the right or left.)  Each move can be measured for different things, like are there any openings to attack your king?  Is your king directly exposed?  Are any of your pieces in immediate threat?  Are any of your pieces able to attack?  Is your queen in jeapordy?  Are any of your threatened pieces leaving an opportunity to check the king if attacked?  Essentially, you write small scripts or methods that check these values, and assign threat and reward levels.  For instance, you putting their king in check is a good reward level.  Your king being in check is a stronger threat level .  For instance, lets say that if your king has an opening to direct attack, (not in check, just an opening) it adds 100 to the threat level.  If your queen is in check it adds 300 to your threat level.  If your pawn can remove an opponent’s power piece, reward level is up by 250. 
                Once you have all your comparisons done, subtract the threat from the reward level and you get your final score.  The AI will test each possible move it can immediately make and identify which of those moves have the most reward.  Then it compares the next rounds.  For the top 3 most valuable moves, and one random one and tries to test each follow up possibility.  Adding each move to a list.  Then the list is checked again for which 3 have the best score, and check again with another random one.  A chess game may easily step through 100,000 moves before it’s settles on the best possible one found after that many considerations. 
                To add difficulty levels, each move has a random value added to it.  For easy, that value could be a random from 1000 to -1000, where sometimes it would make really smart moves, but mixes it with other moves that really aren’t so great.   A middle ground AI might waiver by 250 points for the end number. 

Movement AI’s
                Movement is another great AI.  Making a path from point A to point B when there are lots of random obsticles in the way.  The most common starter AI is called A* (A Star).  Essentially, it takes every possible move you can make, (upwards of 8 at the beginning) and say which is the closest.  Then adds that to its path, and adds every surrounding possible move, and how close those are to the goal.  Then from the total list of possible moves it grabs the next closest one, until it finally gets to point B.  Then, it uses only the list for the path, and uses the same AI to make its return path.    Every step is taken by using numbers, and comparing for the lowest possible value. 
                I will mention that I only touched on some perspective ideas for how chess AI works, and there are some other problems with A* that have simple solutions regarding time.  But that’s another can of worms.  I primarily wanted to give you a simple perspective into the world of AI, and the hopefully give you the theoretical knowledge to get started with it.               

20091005

The Future of RPG's

             As any of the avid game players may have noticed, the art behind RPG’s is dying.  They are all about lots of quick rewards.  Literally, click this, then click that and repeat 100 times.  It’s only addiction is the constant state of achievement, and the fact you always feel the next is so attainable. 
In a previous post, I discussed possibilities of how “Fun” can be defined in video games.  While RPG’s depend on the feeling of rewards, I would ask that more RPG developers and designers start putting that as #2 or #3 on their list of things to cover.  What the future holds in RPG’s is something that todays world is far more equipped to deal with.  Players that can leave lasting effects on the games.   In RuneScape, You mine ore from a rock, until the rock disappears.  A minute later, the rock reappears.  What if it didn’t.  What if mining for ore literally expanded the map?  What if your character could walk around somewhere, and randomly start mining.  Find gold, and start a settlement.  What if your military people could control X number of NPC military  soldiers and take over villages, or clear out forests?
In games, the What If’s can be a painful thing to live with, as there are so many.  Seriously take a look at this though.  What if you could damage things like buildings and bridges.  What if there was a finite amount of gold in the world.  What if the monsters learned?  In a later post, I’ll be discussing how to build a dynamic hard coded (interesting phrase no?) spell casting system can be linked with an effective AI that builds your world, enhances your monsters all without human interaction.
So the idea of mining literally modifying the map.  First off, you need a living map, or supporting a constant state of change.  Second, your map must be true 3D, not just a height map based on a black and white image.  These are tough tasks, that do exist in the world, and will require some heavy proofs.  Build your bridges, your houses, your mines and your mountains from stretching a single piece of ground and reshaping it.  Then it will only take one modification system to handle manipulating it.  Houses are simply predefined modifications.  Mines can actually grow.  You can knock someone’s house down.  Naturally, you can give materials different strengths, indicating its more difficult to damage or work with.
                Then you can create a real bounty system, and have NPC’s and PC’s hunting players who damage certain property, like the entrance to the goblin cave, or a bridge out of town, or someones house.  This is one of those systems that once it’s built, it becomes putty in the hands of the rest of your programs, AI’s and players.  Build real societies.  But make an evolution.  Don’t just write another click this, click that application.  Be the next wave.

20091001

Proof of Concept

     In my years of experience, one of the biggest problems I've found is a disconnect between management and programmers.  One that says that both sides really know what their doing.  As soon as a programmer says a timeline looks good, they are telling management that they decisively know everything that needs to be done, how it will all work together, but in truth they do not.  Most don't.
     Most all programmers don't realize they deceive management, but its true.  I'm guilty of it, everyone I know at various companies, including Microsoft does it.  The problem is that we think we've built something like this before, so we know what needs to be done.  While our past experience does give us clues to how things will pan out, when is the last time that a request came down from management to "rebuild" something EXACTLY like what you have done.  The point there, is that all these projects may be like something that previously existed, but they always have some new, often strange, way of doing things.  Some new feature, or method of control.
     The problem that we face, and often blame feature creep entirely for, is once we start building something, we come to a cross roads; either we go back and rebuild part of it to work with some odd portion of the project, or we need to hack a small portion of the project to make it fit into the whole.  The reason this happened, is because we are facing something we were not prepared for.  Despite the fact we had an idea of how it could work, once we are here developing it, it almost always deviates from that original plan, some of it being made up as we go.  If we really had our head wrapped around everything it would take when we submitted a timeline, we wouldn't be surprised by this;  our original architecture would work fine for all this.
     So how can we fix this?  With Proof of Concept!  Why yes, its the magical solution that solves every problem!  ;)  Or not.   Proof of Concepts are the key here, but I want to emphasize that no amount of experience can fully prepare you for the future.  Respect that, remember it and apply it.
     To really understand what is involved in the project, start stepping through the requirements, and existing design.  Create a list starting with the most basic abilities to be used.  Even if you've already know them really well.  Then start adding on the layers.  "Show a text box" > "Limit the amount of character" > "validate they are in a phone number format" > "Check if the number exists in the database" > "geocode the region for the number" etc...  And as you start to look at this list, find anything in it that you have not built before, and go build it.  For instance, Validating a phone number format, when you start considering that, you have to ask yourself what formats are acceptable.  Well, there are many, and other countries.  So, the requirements either need to list what type of phone number's are acceptable, or you need to accept all of them.  That's immediate feed back on the requirements, and if you waited until you hit that point to start asking these questions, you may already have database options limiting against what you need, and other parts of the project that already work with one style of phone numbers.  You wouldn't know this until you actually address it.  and by then, having to go back and change everything leaves a lot more openings for errors to occur.
     So, always outline a list of what approaches you need to use in the project, including how things interact.  This will also help for feature creep.  When someone says, "now I want you to add this", you can break it down, and see if you have any proofs existing to cover it all.  Chances are, that you do not.  And chances are, it might require changes to the architecture or hacks to make it fit.  This makes the things you do much more clear.
    
     Argument, "Management would never let us spend that much time defining something out".  You are possibly correct, but that is only because of the first sentence about the disconnect between management and programmers, followed by the idea that they don't know what they are doing.  (given the paragraphs that followed it would be easy to assume I was leaving management blameless. :) )
     By demonstrating to management that using proofs will make timelines far more accurate before the project even begins, is a huge value.  How many projects have you been on where everything was on time, and under budget?  While a few might get through like that, in general, that is not how it works.  Things get pushed out with bugs, pushed out late, or dropped altogether.  Often a combination of all three.
     Yes, this will take more time up front.  but, as time goes on, and this practice is adhered to, everyone will start gathering more proofs, more practice, and the proof of concept stage will get smaller and smaller.  (depending on what is being requested)  Eventually, the companies become very streamlined, and the proofs help shape exactly what areas the company has real experience in.
     Also, a proof can be used as a reference to say, "it can work like this", or "here is another option to try for it"  Also, proofs help shape additional questions, like "What phone number formats?" and "What security levels?"
     Again, I don't expect every company to just jump up and start acting on this. but do take a serious look.  Watch when projects fail.  Watch when those cross roads reach you.  Once you start keeping track of it, it becomes more clear, and you'll see why this practice, or something similar is absolutely necessary in the real world.