Quote: Original post by e64
Hi,
I'm writing my first RTS, and I'm looking for some starting pointers on how to go about implementing the computer-player AI.
So far I have basic behaviours such as path finding, obstical avoidance, formation movement, finding&gathering resources, etc. implemented, but I don't know what kind of approaches to use to do the overall planning for the computer player.
I'd be hoping for something better than this:
if (not enough attacking units)
gather resources;
build units;
else
send all units to nearest enemy base. (and hope they destroy everything)
Thanks!
You'd probably be best off using some kind of goal-based system. First, pick a goal (like maybe kill all of the human player's units or take over X% of the map or gather all the gold resources). Next, figure out how to go about doing that.
For example, killing all the human player's units requires building some of your own and sending them to attack. Building your own units may require new buildings and gathering resources.
Drill down until you have a specific task that you know how to do (like gather 100 units of gold) and then perform that task.
It may seem simple, but there's a lot of detail hidden in there. There's also some interesting side questions like what do you do if you've been saving resources to build your cool ultra unit and realize you need defenders for your base? Do you stop saving and spend now or stay the course?