Monday, November 10, 2014

AI Threading, Route Density

The only thing I did with AI today was a quick optimization.  Being inexperienced with threads, I didn't realize that starting and stopping the AI thread with each cycle is costly.  It takes a little time and you could see a little stutter.  At the time, I wasn't sure if that was why it was stuttering, but I decided to change the AI so that it runs on a continuous thread and just loops while it waits for new info from the main thread.  I wanted to see if that would fix the stutter.  Sure enough it did.  It runs silky smooth right now.

The other change I made was to the balance of the game.  Specifically, it had to do with the density of people within the routes.  Before I explain the change, I'll explain the purpose that the people play in Sever.

The little builder people that run through the routes and build new segments exist as a resource.  The idea is that more you have, the faster you can build.  They are produced at a regular rate from the parent nodes, so you don't have to create them yourself like you would in other games.  Instead, it controls the player's pace in the construction of his routes.  If he builds faster than his people can be produced, then the people are too spaced out and don't build as fast.  This is especially crucial when actually fighting the enemy.  The one with the fastest routes has the advantage.  On the flipside, if he expands too slowly, he might reach full capacity and production will stop.

This causes the player to want to protect his people.  Some are lost in defending and attacking, but the less the better.  The more of the enemy's people are destroyed, the more of an advantage the player has.  Also, to prevent the enemy from replenishing, the player will want to keep attacking until the enemy is destroyed.  Otherwise, the enemy could make a comeback.

Having more people also allows for more strategies.  For example, if there are enough people in a segment that is aiming to intersect an enemy's segment, and the player needs to use that segment slot, he can split his own segment, freeing up the slot and allowing the end of the segment to run into the enemy like a projectile.

As long as the player continues to expand, production will likely never stop, so that's a rare issue.  However, density can still get really low.  Sometimes when fighting the enemy, the player can't help but expand quickly and lose lots of people.  In this case, the player can restore his density by retracting unneeded route segments.  Some players might even make a stockpile of them behind their base so that they have them when they need them.

That was the plan for the people when I was first thinking through Sever's concept.  This would only work if I could get the number of people to really matter and make a difference in the game.  Until now, the density made a minor difference.  Expanding fast and overwhelming the enemy with lots of slow routes coming at them was more effecting than precision attacks with a few fast routes.  Changing the rate at which people move, build, or are generated didn't make a difference.

I knew that if I couldn't fix this issue, then I should probably cut the people and have routes build at a smooth fixed rate.  I could do that and make the game work, but there would be alot less depth and strategy in the game.  Overwhelming the enemy with tons of attacks would be the primary objective, and the AI is an absolute pro at that.  But humans can't make issue commands as quickly as the AI can, so that puts the human at a disadvantage.  And besides, it's just not as fun and allows for less variety and styles of play.

I knew that to reward the player for having more people, I'd have to make the difference between a sparse route and a dense route wider.  I came up with the idea to make the people in dense routes move faster and sparse routes move slower.  I've implemented it and it works.  The AI went from unfairly hard to beat to alot easier.  However, the advantage is slightly on the player's side now.  The AI just throws routes at the player without even thinking about density.  Next, I'll have to get the AI to be a bit more picky with construction and retract unneeded segments.  We'll see how it goes.

Thanks for reading!

clevceo

No comments: