Advertisement

RTS AI help

Started by February 23, 2007 09:24 PM
14 comments, last by Jurney 17 years, 8 months ago
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?

Greatly depends on what kind of RTS you are developing. Either way, I encourage you to attempt some form of learning AI. However, do also remember that too though AI isn't fun.

Perhaps you can define some tactics, for example:
1. Build largest army ever, then attack up front
2. Take out all resource gathering
3. Attemt to fool your enemy that you are attacking one area, then send your real troops to another area
4. Sneak in from behind

Defensive:
1. Have a defense force ready to move around
2. Set up defense towers/building everywhere
3. Attempt to block all paths except one, and defend that one with everything

Bases:
1. Build one base, and protect that one at all costs
2. Have one real base, and many outposts
3. Distribute everything, so that an attack wont take out everything you've got at once

And so on. Then attempt to analyse what the player is doing, and then try to decide on whats your best move. If you can't do that, you can pick one, then try to play that one as good as possible, and learn from all misstakes.

Should be *fairly* easy to implent, should create fairly varying play styles for the AI (depending on implentation), should be fairly easy to generate scores and stuff so that the AI can learn.. The more different strategies you can define, the better.
Advertisement
Quote: Original post by DvDmanDT
Greatly depends on what kind of RTS you are developing. Either way, I encourage you to attempt some form of learning AI. However, do also remember that too though AI isn't fun.


I doubt that'll be a problem. I suck at RTS's, but I can beat any non-cheating AI hands-down. RTS games are one kind of game where the best AI still can't beat an average player without having the rules bent in his favor.

I wouldnt encourage anyone to do a learning AI for an RTS. I would rather aim for an adaptative one, that can change tactics depending on the situation, that would be great. But your AI should already know how to play an expert game before the first one start.

edit: whats with my grammar tonight.
Well, there are different RTS's out there.. I mean, compare the Settlers 2 with the Settlers 4 or Red alert or warcraft 3..
Quote: I wouldnt encourage anyone to do a learning AI for an RTS

largely depends on what development phase you use the learning AI. the learning process involves thousands of games (or strategical/tactical situations, if you like), at the end of this process the AI is tuned up for efficiency in certain aspects of the game (minimize losses, maximize unit loss/kill factor, efficient resource gathering, economic efficiency, whatever other targets you have in mind). in real life, how many rts matches (skirmish, single player campaign) has anyone played against AI in a game? 15 in campaign mode and some other 50-100 skirmishes? (i'm not a maniac, i've played starcraft and warcraft 2/3, but i dont remember playing 100 matches solely against AI). anyway, even 100 matches is nothing (i'm talking about adapting to the player style) - it wont affect the learning process anymore, since it was tuned to be efficient as said before, all mistakes have been already sorted out and the AI is ready to be a challenge to all but the hardcore players.

if you want to do it and go with a bang (and make happy the marketing people who'll have more words to write on the box) [wink], try emergent behaviour/complex system dynamics theory combined maybe with genetic algoritms or neural networks to check against your goal. this will make your AI develop in a natural way (that is, in the rules of your game), without hardcoding a global finite state machine.

besides, as stated above, a (rts) game should be fun and challenging, not realistic. leave realism in the academic world, where the eggheads will surely deal with it in the next century [wink]

The early game in most standard format RTSes is most easily handled with a fixed script, or set of scripts, just like an opening move book in chess. Unless your design differs a lot from the standard, there will be a very small combination of moves that are "good" for the first 2-5 minutes of play.

After that, RTS AI is all about budgeting. How much of my resources should I allocate to building units, upgrades, tech, etc? How many of my units should I dedicate to attack vs. defense vs. resourcing vs. whatever other mechanics you have? The trick comes in how to drive the budgeting, and how to determine the priorities. All the production RTS player AIs I've seen have not used any learning, decision trees, or neural nets. It's all about finely tuned heuristics, prioritizing goals, and effective budgeting of resources.

A neat trick in all this math is to base all your costs on time. In most RTSes, all your decisions costs can be traced back to seconds... it takes you x seconds to collect the resources, or move the unit, so you can compare costs based on this.

Good luck,
Chris

This topic is closed to new replies.

Advertisement