Thursday, October 23, 2014

AI

Since I got the path-finding working, I've been thinking about how the AI will make decisions in the game.  I've thought about measuring each nearby path-node based on its offensive and defensive value, and then testing all the different possible moves it could make and picking the best one.  It could be done, but it wouldn't be very efficient.

Today, I had an idea that might work.  The AI will have different goals and each goal will be given a priority based on the current situation.  For example, If the enemy is close to the AI's base, defense is given priority.  If the enemy base is found, and the AI's base is safe, then offense is given priority.  If the enemy has not yet been found, then scouting is given priority.  The AI cycles through each goal in order of priority and determines if it wants to make another move toward that goal.

Scouting mode will look for nearby fog of war and build nodes near it to clear it out.  Offensive mode will do one of two things: if the enemy is close, attack it; if the enemy is far away, close in on it.  Lastly, defensive mode will either fortify the base or fend off attackers.

Whenever a goal is examined, it determines whether another move needs to be made or whether it should wait for something to be completed first (a segment to finish building, for example).  In order to determine what move to make, it needs to assess how good its current state is, and what can be done to improve it.

Today, I've been focusing on how the defense assessment could work.  For the most part, a decent defense just means that there are nodes on the outer edge of the base with segments to spare.  In order to see how the current defense is, I need to determine which nodes are on the outside of the base.  This is tricky, but I think I came up with a solution.  Here are a couple screenshots.  I'll explain them afterwards.



First off, I'll find the left-most node, draw a horizontal line to the left and rotate it counter-clockwise until it hits another node.  Then, I'll duplicate that line and rotate counter-clockwise again from the second node to the third node.  This will repeat until the entire system is outlined.  These are the nodes I'll test.  If I find too much space without a node that can attack, I'll try to fix that problem.

You'll notice that there's a big pink object in the middle of the base.  Obviously, I won't need to place defenses around it.  That would be a waste.  So I'll probably let the line hit these objects as well and rotate around them until I hit another node.  Of course, anywhere the line touches the object will be considered well-defended.

Also, this outline will envelope all scouting and offensive routes as well, so I'll have to find a way to section it off.  Sectioning off the scouting routes might be easy.  The segment length requited to build a scout node will be longer than the line, so the line will pass straight through the segment and hit the next node in line.  Offensive routes however, will need to be separated somehow.  I'll cross that bridge when I get there.

Thanks for reading!

clevceo

No comments: