Thursday, October 30, 2014

AI Decisions

I've noticed a few issues with my current setup.  First off, path-finding with distance approximation creates a similar path to the Manhattan Distance Heuristic.  In other words, the fastest way from point A to point B is more like an L.  First you move at a 45 degree angle in the general direction of the target until you are parallel to it either horizontally or vertically, then head straight for it.  This works, and it works fast, but I really want my AI to move in straighter lines.  So, unless I change my mind, back to the original heuristic.

Next, taking a snapshot of all state info for the AI every few seconds takes alot of time and memory.  I knew this would come, but I wanted to focus on it later.  Unfortunately, it kills the performance already, when there are only 8 nodes on screen.  I've decided to merely keep track of changes to the world and sync them with the AI.  The data transferred to the AI will be things like 'segment id 2's length changed to 150' or 'node id 7 removed'.  Of course, it won't be passing text, but you get the idea.  It will pass minimal information and it will be up to the AI to do all the processing involved to update its current snapshot.  This means alot less processing on the main thread and alot less information passed to the AI.  The AI will have to do a little more thinking, but that's okay.  As long as the player's experience is smooth, I'm happy.

I've been thinking about how the AI will plan his routes as well.  I've been entertaining the idea of using genetic algorithms again.  I'm pretty sure they'll be too slow, but I want to give them a try.  I may as well try everything, you know?  What if I'm surprised or it leads me to a better idea?  I may even end up doing a hybrid of multiple different techniques.

Today, however, I focused on trying to get one path built from the enemy to the player.  I wanted to use actual pathing rather than a fixed route that only works on one map.  In other words, I want the AI to be just as effective as my last one on any map I create.  Now, remember that it's only building one line of nodes and segments, it doesn't defend itself, and it only tries to attack the segment connecting the player's parent nodes, nothing else.  It will still be stupid, but once I get it working, I'll be a step farther in route planning.

Ultimately, I want the AI to be able to make up its own mind about the map's layout.  I don't want there to be any map-specific scripting that aids the AI's strategy and tactics.  I want to be able to drop it into any map at all and have it still be just as effective as any other.  What attracts me to genetic algorithms is that I don't have to think up every strategy beforehand.  It can come up with them itself.  It still has its limits (besides inefficiency), but as long as I can tell it what's a good move and what's a bad one, it can come up with more creative strategies than I ever could.

I may create the genetic algorithm alongside any others I work on and see which turns out best.  Initially, I'm pretty sure the genetic algorithm will be the slowest, but that's because I've never actually built one and there are so many different ways to do it.  I'll have to experiment and try to optimize it until I either decide its fast enough or it will never be fast enough.  I'm crossing my fingers for the former.  I'd love to create an emergent AI.

Anyway, thanks for reading!

clevceo

No comments: