• Advertisement
Sign in to follow this  

RTS AI

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For the 4E4 contest, I'm going to do an RTS entry. While the graphics and general game stuff shouldn't raise any suprises, I've got the problem that I've never really done any AI programming before. I've a little knowledge from some courses at university about different searches like depth/breadth - first, A* etc but I'm looking for some articles/tutorials specific to a RTS world. I had a look at GD's article lists but can anyone recommend the best resources they have used? I've got as far as realising that there are at least 2 distinct AI 'levels' for an RTS game. In a broad sense there's the game logic AI - equivalent to me deciding what to build and where, when and who to attack with what etc - and the unit AI to do with avoiding obstacles, responding to attacks and so forth. Is this the kind of architecture others have/would use, or would there be many separate levels of AI behaviour? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
www.gamasutra.com has a number of articles on different topics. I remember the AI of an RTS from a few years ago (Age of Mythology?) being described in detail by its author, for example.

In general, game AI is more of an "agent" problem and less of a "search" problem. You can also google for "planning," which is an interesting research area that's starting to become relevant to game AI.

Typically, you'll need a database of all facts the AI has discovered about the map; a database of rules of the game; and a database of strategies to accomplish various tasks. Agents then query and update this database as the game progresses.

An agent, typically, has some desires ("kill enemy" "stay protected by friends" etc), some beliefs ("enemy is there" "friends are here" "my ground weapons won't work on enemys air units") and from those, formulate a goal ("stay behind friends"). There's lots more to it than that, of course, but that ought to set you looking in the right direction (I hope :-)

Share this post


Link to post
Share on other sites
So I've revised the A* algorithm now. But there's an issue with this - to plan a route using A* don't you need the whole map to be 'visible' to the search? If you have the concept of exploring the map then what happens when you attempt to send units to a far-off unexplored place?
I suppose my first thought is that A* can be used to find a route to the edge of explored space, and then a simpler approach of just trying to get to the destination by avoiding obstacles could be used. This is more realisitc, butdo players want realism or the ability of units to always find the best route between locations?

One idea I had was that instead of getting too concerned on making unit AI good enough to get around any obstacle (including groups of enemy units deliberately placed to block your path), units can report to you. In Total Annhilation they told you about being under attack; units could also report if they get stuck or lost - this way you could quickly sort them out rather than find out 10min later that your strike force never made to the enemy base. As long as the individual units aren't really dumb I think this could make a big difference.

Share this post


Link to post
Share on other sites
About the parts of the map you can't see, you just assume they are all crossable, and have all the same level os difficulty to cross.

Then you can either check whenever a unit is moving to a different tile if that tile is crossable, or, you check at regular time intervals if the next n tiles of the path for a given unit are all still crossable. I preffer this last one, because as the unit uncovers more terrain, it will decide to take a different route before actually hiting is face against a rock.

Share this post


Link to post
Share on other sites
I don't think it is a problem that units know their way around a map; it would be much too frustrating otherwise because units would take years to get where you told them to go. Unless, of course, your maps are generally open.


I have a question for you: How are you going to handle splitting the pathfinding over several frames? I was thinking: if you give the pathfinding routine a set amount of time per frame, people with slower computers would see their units taking longer to find a path.

I haven't done any RTS AI (or any for that matter...), so I don't speak from experience. :P

Share this post


Link to post
Share on other sites
One idea I've had, that I still haven't really tested, is keeping "pheremone" levels for the different areas of the map. Every ten seconds of so, you'd go through and multiply the pheremone levels by, say, .9 ( so they decay ). For example, a "base" pheremone would be generated periodically by your resource structures, so positive "base" would be your area, negative would be the opponent's. Then perhaps a "damage given" and a "gamage taken" pheremone, which would be adjusted at the obvious time. Then, for example, defensive units would want to be in areas of slightly-positive base pheremone, and more concentrated in "damage given" and "damage taken" areas.

Share this post


Link to post
Share on other sites
Quote:
Original post by me22
One idea I've had, that I still haven't really tested, is keeping "pheremone" levels for the different areas of the map. Every ten seconds of so, you'd go through and multiply the pheremone levels by, say, .9 ( so they decay ). For example, a "base" pheremone would be generated periodically by your resource structures, so positive "base" would be your area, negative would be the opponent's. Then perhaps a "damage given" and a "gamage taken" pheremone, which would be adjusted at the obvious time. Then, for example, defensive units would want to be in areas of slightly-positive base pheremone, and more concentrated in "damage given" and "damage taken" areas.


This is good in a per-unit basis. (it also comes in handy for deciding where to attack in battles, just pick the weakest spot in there defences to charget through.

Also, the pheremone should be proportional to the strength of the unit. (so your little guys won't go running towards the giganto-people-killer 9000)

You would also need a segmented ai.

What does that mean?

It means that you have one ai for each soldier (really really simple)
One ai for a group.
Then one for a squadran. (so you would have one squadran ordered to protect building X or defend space Y, or attack space/building Z, which then takes all of its groups and decides who will go where, ect.)

You would also have one high level ai, which will figure out the orders for its squadrans.

As well as another one which decides what shal be built. (it. a logistics ai).

From,
Nice coder

Share this post


Link to post
Share on other sites
Nice Coder: I call that "Heirarchical" AI :P But regardless of name, it'd be a good additional layer. Somewhat logical too, since it's how modern armies work.

( Commander-in-Chief says "take over Europe". Generals say "move into Poland". Lieutenants say "ok, we're going in from these two flanks in 3 days". Sergeants say "ok, use these hills for cover". Privates say "yes, sir!". Same thing works the other way too, just getting abstracted instead of specified. Private says "Taking mortar fire!". Sergeant says "need covering fire". Lieutenant tells different Sergeant to help out, perhaps. )

Disclaimer: I know that's not how responsabilities work in a real army, but it's a reasonable separation for a computer model in an RTS AI. Also, I probably got the ranks in the wrong order or spelling :|

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement