Jump to content

  • Log In with Google      Sign In   
  • Create Account


RTS AI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#1 d000hg   Members   -  Reputation: 712

Like
0Likes
Like

Posted 29 June 2005 - 12:38 AM

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.

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5067

Like
0Likes
Like

Posted 29 June 2005 - 01:15 AM

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 :-)


#3 d000hg   Members   -  Reputation: 712

Like
0Likes
Like

Posted 29 June 2005 - 03:42 AM

gamasutra doesn't seem to have any kind of index, just a huge list of every article in a big list?

#4 xEricx   Members   -  Reputation: 564

Like
0Likes
Like

Posted 29 June 2005 - 03:46 AM

Check out AI Wisdom.com

Hope this helps

Eric

#5 d000hg   Members   -  Reputation: 712

Like
0Likes
Like

Posted 29 June 2005 - 08:23 PM

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.

#6 xor   Members   -  Reputation: 516

Like
0Likes
Like

Posted 29 June 2005 - 08:35 PM

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.

#7 Daniel Miller   Members   -  Reputation: 218

Like
0Likes
Like

Posted 30 June 2005 - 03:34 AM

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

#8 me22   Members   -  Reputation: 190

Like
0Likes
Like

Posted 30 June 2005 - 04:06 AM

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.

#9 Nice Coder   Members   -  Reputation: 366

Like
0Likes
Like

Posted 30 June 2005 - 03:02 PM

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


#10 me22   Members   -  Reputation: 190

Like
0Likes
Like

Posted 04 July 2005 - 04:34 PM

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 :|

#11 Palidine   Members   -  Reputation: 1275

Like
0Likes
Like

Posted 05 July 2005 - 07:24 AM

A* for RTS games:
the map should be completely visable to the A* pathfinder. Otherwise you get bizarro behavior that frustrates the user. Typically in an RTS game you can see land features through the shroud, it's only the locations of enemy troops that is shrouded. Either way, you always want the A* to be completely knowledgable of the terrain. The amount of knowledge that you give the computer opponent is a lot more debatable and depends on implementation.

Most RTS AI cheats blatently and gives the AI complete knowledge of the board state (essentially the AI always plays without a shroud). You can trick the user into thinking the AI has a shroud by dumbing down it's moves or just simply by introducing random selection into the process.


AI:
I seperate the AI into 2 basic parts:

1) Unit level AI. things like targeting, defending themselves when attacked, firing weapons, playing animations, guard states, move execution, etc.

2) tactical level AI. things like planning where to attack, where to move troops, how many troops to move to tactical targets, when to attack, when to defend, etc.

To make things easier on you in the programming, it's much easier to have the tactical level AI control troops by essentially simulating user input. That way the unit level AI doesn't need any changing to work on both player and computer controlled sides. By simulation i don't necessarily mean simulating mouse-clicks, etc, but rather just hooking into whatever code gets executed by user input.

If you are starting from scratch tackle the unit level AI long before the tactical level AI. The game should be completely playable by a human before you even start to work on the tactical AI.

-me

#12 d000hg   Members   -  Reputation: 712

Like
0Likes
Like

Posted 05 July 2005 - 08:07 PM

Thanks very much for your advice - I like the sound of it. I'm not sure if I'll actually have a shroud - I suppose most players will expect it but I never liked playing that way! One older game let you see the last state of the map under the shroud, including buildings but not units. Letting the AI see that would help it to know where your base is/was while hiding your exact troop strength etc.

I'm still not sure about A* though. If units only know about the explored map they will uncover more of it looking for a path which would make exploring the map early on both easier and more profitable. But as you say, providing a map of the terrain to start with would remove this problem. I remember WarcraftII frequently got units stuck up against obstacles when they got lost, but it seems such behaviour is just not acceptable anymore.

Thanks again.

#13 Pipo DeClown   Members   -  Reputation: 804

Like
0Likes
Like

Posted 05 July 2005 - 08:53 PM

This thread owns! This is how AI gets implemented in game programming, for real.

[Edited by - Pipo DeClown on July 9, 2005 2:53:32 AM]

#14 Nice Coder   Members   -  Reputation: 366

Like
0Likes
Like

Posted 05 July 2005 - 10:11 PM

Worse comes to worse, you can always backtrack...

Also, remember to weight squares based on the amount of enemies there... (so our scout party isn't going to run straight through the enemy camp before getting killed).

From,
Nice coder

#15 d000hg   Members   -  Reputation: 712

Like
0Likes
Like

Posted 05 July 2005 - 10:46 PM

Quote:
Original post by Pipo DeClown
This thread owns! This is how AI gets implemented in game programming, for real.
I don't get it. It sounds like sarcasm but about what? Your rating suggests much knowledge, sir - do you have anything less cryptic for this thread?



#16 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

1Likes

Posted 05 July 2005 - 11:00 PM

RTS AI?

Well this is pretty much how the 'professionals' do it:


void rts_game_ai()
{
cheat_a_bit_before_game_starts(resources += 10000000, hugebase++);
send_multiple_weak_and_pointless_attacks();
act_like_youre_actually_gathering_resources_not_cheating_to_get_them();
cheat_some_more();
lose_building_to_enemy(OH_NOES);
cheat_more(CHEAT_INFINITE_RESOURCES | CHEAT_FAST_BUILD);

while(still_alive() == true)
{
send_multiple_weak_units_to_defend();
}

die();
}



#17 d000hg   Members   -  Reputation: 712

Like
0Likes
Like

Posted 05 July 2005 - 11:24 PM

[smile]

But seriously is RTS game AI still generally poor, relying on perfect knowledge and additional resources? I'd got the impression modern games didn't do that.
What are the recent games which follow the style of warcraft2 and C&C, and how is the AI different in terms of unit AI and tactics?

#18 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 05 July 2005 - 11:53 PM

Hmm, C&C Generals and Age of Mythology are the newest RTS games I own. Can't say a lot about AoM because I didn't play it a lot.


I'll make a comment on the C&C Generals AI though. This is just roughly what I can remember from playing recently.

I have heard that the Generals AI does cheat for resources and such but I can't say I've really took any notice, you generally don't when simply playing a game. I might fire up a quick skirmish and take control of all resource gathering methods to see how it goes though. I'll let you know if I actually do do this.

I haven't played any skirmishes against the AI yet, I've been playing through the campaigns on the hardest difficulty (though with 2 missions left on the 3rd campaign I'm finding it quite easy). The AI does seem to be constantly sending the same types of units in the same sized groups constantly over and over. Every now and again it might just send in a couple different units but again these are the same every time (usually "artillery" style units, long range units meant for taking out structures).

So lets take a look at an example scenario. I'm settled in with a base and defences.
1) AI sends it's first attack consisting of 10 machine gunners, 2 tanks and 1 humvee. I destroy it quite easily.
2) AI repeats first attack and I win again.
3) After roughly the same amount of time between attacks, the AI repeats the first attack yet again and I win again.
4) AI sends another attack this time consisting of 10 machine gunners, 2 tanks, 1 humvee and 1 cruise missile launcher. I have to send my army forward to take out the cruise missile launcher and I suffer a few losses but I still win.
5) Repeat until AI wins or AI loses.

So yeah, it seems C&C Generals does stick to the general cheat and execute weak attacks method of RTS AI.

#19 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 06 July 2005 - 12:00 AM

^^Note 1: Someone else who has played C&C Generals may be able to comment further.

^^Note 2: It would be quite interesting to start a very simple RTS project just to attempt making a decent AI that doesn't cheat (ie ~3 building types, ~3 unit types, barebones minimalist RTS. Surely the AI could then be scaled up to a more realistic situation in a full blown RTS?). But then is a single unprofessional person could make a decent RTS AI then why don't the professionals do it? Maybe it's just a hell of a lot easier to make cheating AIs. I might just make this my next project :)

#20 d000hg   Members   -  Reputation: 712

Like
0Likes
Like

Posted 06 July 2005 - 01:33 AM

It sounds from that like the latest game is no different than the original C&C from the days of the 486, but with better graphics then?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS