AI in RTS Games

Started by
2 comments, last by skap20 20 years, 10 months ago
I am working on an RTS game and right now I am just brainstorming ideas for how I will handle the AI. If anyone could comment on my ideas and also, let me know if you know of a better method! I''d like to figure out how I will do this before I get halfway through it and realize it doesn''t work very well. (this is my first project with AI so I''m not very experienced with the subject) Base Defense: Each base will be centered around the Military Headquarters building. This is basically like the Construction Yard from C&C. It also serves the purpose of determining what constitutes the "base". The base can extend for up to a ~50 tile radius around the HQ. But the actual base is determined by counting out about 5 tiles from each structure. This way, the base perimiter won''t be too far away from the actual base early in the game and it will prevent any gaps between buildings that would otherwise not be defended without the use of the HQ method. The area that makes up the base is basically the set of all tiles taken under consideration when making defense decisions. I think influence maps are the best way to determine where an enemy concentrates most of its forces. So the more enemy units that pass over a particular tile within the base will have a higher defense threat. Thus, when considering where to build a defensive structure or place a unit, it will look at this influence map. After enough time has passed without any enemy activity, the tiles defense threat decreases. Resource Gathering AI: I think an ant-based algorithm would be the best for this part. The resource units will wander around the map looking for whatever it is they gather. When they find it they will leave the pheromone trail to the resource location. Then, other resource units will follow the trail, just like the standard ant colony... I also think an evade algorithm would work well with these units. I always hated when my harvester would wander into an enemy base in C&C! > Attack AI: I really have no clue. Please help me out with this one! Other Stuff: Units will just be FSMs, battalions will be the next command level up, consisting of up to 5 units. A platoon will vary in size. When the user selects a group of units, that is a platoon. I don''t know how I will get the computer to pick a good size for its platoons (unless I just make it constant for the AI but that wouldn''t be very fun). And finally, the main command runs everything at the General level. But this is the other area I''m having trouble with. Right now I haven''t put too much thought into the upper level functions. Start off slow, get the batallions to work effectively as a team and build from there I guess... Well, let me know if you have suggestions or new/better ideas. Thanks! -------------------- Nicholas Skapura skapura.2@wright.edu http://skap.8k.com AIM: skap35
--------------------Nicholas Skapuraskapura.2@wright.eduhttp://skap.8k.comAIM: skap35
Advertisement
You may very well be doing much too much for RTS AI. In my RTS I use almost exclusively message based "AI" with ''scripted'' actions for things such as build order, etc..

I have a general chain of actions for every unit. Namely:

1. Have I taken damage since my last update? If so, do I stand a 30% chance or more of destroying the weakest enemy unit within 2 tiles of me? If, no or there is no enemy within 2 tiles, return towards nearest "base location" and set my retreating flag. If I do, then attack that enemy.

2. If any flags are set for my actions, do that.

3. If I haven''t taken damage, are there any enemies within 5 tiles of me? Do I stand a 30% chance or better of destroying the weakest one of if their are? If so, then attack weakest, otherwise continue..

4. Can I create another source of income for the resource we are lowest on? (Generally builders in other games). If so, is there a location for me to do this within uncovered map? If so, then do it. Otherwise - Are more than 15% of all of these types of resources left? (CHEAT ALERT). If so, go exploring with flag set designating I am looking for that type of resource.

etc etc etc

Attack AI is very similiar. I insure I have a total unit strength (within 5 tiles) of a value that is based upon how much time has elapsed in the game (more times means I want a stronger minimum attack unit). If I do then I set all of their flags to aggressively move towards one of the three most recent locations where an enemy building or unit was located (stored in a list each time an enemy building/unit is seen). If there are no recent siting they move aggressively towards one of the three points that is furthest away from where they currently are. So, as a general idea, if they are in the bottom right of the map they will aggressively move towards the upper left of the map in a slightly random way if it has not been explored.

I think if you try to do "Real" AI you''re games going to come to a crawl when you get 300+ units on the map. And not only that, but the AI will likely end up much weaker than a simple message based AI.

My AI system is still very rusty, but it can be extremely effective. The most difficult task I am facing is reacting to destruction. Since my building is primarily scripted if the AI has no "base" left and they are low on resources they do not do a good job of rebuilding.

Good luck. If you do decide to go forward with actual AI, let me know how it turns out. I decided against it at an early stage.. simply because most other RTS''s also use a similiar message based approach and their AI is relatively beleivable and always effective. So I''m not creative!
Thanks for the advice! I didn''t mention it in my post, but I do plan on using a similar system for the individual units. I came up with it to resolve collision detection among units. If one unit is in another''s way, he moves out of the way by sending a message to the other unit. But that could easily be expanded with more commands to control how the unit attacks and defends.

Your method for attack AI is a good idea. It would still be pretty believable but won''t kill your speed (like some of the other ideas I had). I am more interested in building a really good defense AI anyway, so using a simple method like this will allow me to concentrate on AI defense instead of having intelligent attacks. Besides, this is really my first AI project and using real attacking AI just seems too hard for me to tackle right now.

I just finished the tile engine today, so I should be able to get started on the AI stuff pretty soon.

--------------------
Nicholas Skapura
skapura.2@wright.edu
http://skap.8k.com
AIM: skap35
--------------------Nicholas Skapuraskapura.2@wright.eduhttp://skap.8k.comAIM: skap35
Sit down and think about how you, as a person, would play the game. Now adjust that methodology for how you might play the game if you had access to the information that the computer has. Remember that the computer doesn''t see the screen. It has arbitrary sets of data to make sense of. Finally, determine an appropriate technique for encoding this knowledge into your game. If you can achieve that, you''ll have a formidable game. It doesn''t necessarily take AI, just Game AI...

There are plenty of threads on AI for RTS games in the archives of this site. A quick search using AI RTS revealed at least 50 threads... that should keep you busy and give you some of the information you seek!

Once you''ve read them, check out the articles and resources section of this site.

Cheers,

Timkin

This topic is closed to new replies.

Advertisement