Archived

This topic is now archived and is closed to further replies.

techpage

How do you build the AI for a strategy game (C&C)?

Recommended Posts

How do you build the AI for a strategy game, for example, C&C? Well, inspite of the pathfinding, what other parts of a strategy game that needs AI? Could anyone let me know how to do the tactical and strategical moves for the computer AI? Thanks in advance!!!

Share this post


Link to post
Share on other sites
quote:
Original post by techpage
How do you build the AI for a strategy game, for example, C&C?


Give the computer an unfair advantage

quote:
Well, inspite of the pathfinding, what other parts of a strategy game that needs AI? Could anyone let me know how to do the tactical and strategical moves for the computer AI? Thanks in advance!!!


That''s asking quite a lot!

Read up on Finite State Machines(FSM), Fuzzy State Machines(FuSM), and Neural Networks(NN)

Don''t know if that helps but it''s a good place to start

Share this post


Link to post
Share on other sites
Most of them are actually very simple. There is an inflexible list of things to build, which get built and replaced if destroyed. And then the computer will make half stand around the base and another half or so attack, to attack, they form groups (usually small and ineffective) and then head to the position on your base which seems weakest.

The rest is usually handled by unit level AI, which is more along the lines of attacking anyone near by or attacking any one who attacks you.

That''s about the extent of most games'' "intelligence", so do them one better

Trying is the first step towards failure.

Share this post


Link to post
Share on other sites
You need some form of AI anywhere that you need "intelligent" actions performed, but you don''t want the player to have to handle them (might be things that detract from the fun of the game eg. excessive micromanagement). It''s a lot more important to make the AI smart in these areas, since poor ''friendly'' AI is frustrating and often easily abused in MP.

As for AI opponents, have a look at the other games on the market. It should be fairly obvious that there is no simple formula for creating a good opponent. Most RTS games have shockingly bad AI - you''d probably be better off working out your own style of AI for your game. There''s a fair amount of literature around here on types of AI architecture you can use, but I haven''t seen much devoted to RTS games in particular.

I''m writing something on that topic at the moment which might be helpful if you can''t find anything else.

Share this post


Link to post
Share on other sites
I''m working on an RTS myself (still working on the 3d engine though, haven''t gotten to the AI yet).

Do not make the computer AI anything like Starcraft''s! I can tell you what it does WRONG to begin with =]. The computer automatically knows everything that''s on the map, and exactly what you''ve built even though they haven''t scouted you out, they''ve got they''re own "map hack". The computer also builds things and attacks periodically based on a pre-determined script. There''s also lotsa units sittin'' around at random spots for a weak defense, and no plannings goes into any of their attacks, the units simply walk up towards your front line every time. The only way the computer stands a chance is that they have a fairly efficient build order.

I think a good idea for the AI would be to have it be reactionary, and depending on it''s "style" (it could be defensive, a rusher, absolutely love air units, like to throw in distractions before the real attacks, etc...) it could react in different ways. Let''s say I have a comp AI facing me, and it sees that I have only minor defenses, and it''s already made 5 hydralisks (ill keep using SC units as examples), it will attack with those five. Let''s say that its style also dictates that it likes distractions, it will send up 2 hydralisks at one end of the base, wait for you to get some units attacking them, and then bring up the other 3 to attack your worker line.

A smart AI will have to know the strategies of the good players (attacking the worker line, using distractions, rushing, tech rushing, quick expansion, using chokepoints as defense) and have a good mix of these built into its AI "style". Then rather than having scripted movements, it could simply react based on its style. With enough elements in the AI "style", you could get a very smart, almost player-like AI that would probably run all over a newbie to your game. This is very daunting task, but I think it can be managed if you have a good classification system, ie. the computer would have to classify different parts of the map as (your central base, backdoor to your base, chokepoints, high ground, reachable only by dropship, etc...) and different actions as (rush, drop attacks, distraction, worker killing, etc...) to make full use of this kind of AI.

Share this post


Link to post
Share on other sites
being new to makeing games I do not know if this will help but I like to make mods for ra2 and ts try lookigg at the ai.ini for ts and ra2

Share this post


Link to post
Share on other sites
Yeah, you should make your AI fair. It''s much funnier to play against a fair AI then a cheater. Okay, so how do you really code the ai? That''s impossible to say, since it will depend on your game and how you handle, units, tiles and stuff. I haven''t persoanlly programmed any AI myself, i''m new and I never get to the AI part before moving onto my next project (hate that). However, I''m currently making a civ-clone. School project, so I guess I''ll have to finnish that one, and for that project I''m gonna use ''styles'' as the other guy mentioned above. styles will give your ai a much more realistic look. A style will simply tell the computer what to do when it comes to a choice and when planning. To implement styles I''m gonna use probabilities. Example:

CaptureEnemyWorkers = 0.6
SiegeEnemyTowns = 0.9
RushEnemyTowns = 0.2
BuildImprovements = 0.6
BuildDefensiveUnits = 0.3
BuildOffensiveUnits = 0.5

Just A quick example. The AI above will prefer tactical sieges before rushes, and will build more offensive units that defensive. When it comes to the analysis of the world you could use zone of controll... I''m thinking of using values from 0 - 1 or something (doesn''t really matter) where 0 might be this zone does not oppose any threat, and 1 might be this zone is really dangerous. So say you create different zones of controlls, maybe 3 for each player. 1 zone for defensive strength, 1 for offensive and maybe 1 for tactical advantages. Then your AI might decide it should strike the player. It checks the player''s terratory for a location with low defensive values (each tile has a value attached to it) and might find one, then it might find another zone that is within the players zone but with a higher tactical value. What to do? Well you could result your AI behaviour, does he like PreferTacticalZones more then AttackWeakPositions? or/and you could combine the 3 layers into one using some algorithm. And maybe some algo for the behaviour. Experiment, what happens if you multiply his PreferTacticalZone with the most tactical zone, and his AttackWeakSpots with the weakiest zone? Say the tactical zone has 0.5 and the defensive zone also 0.5, but the computer is more of a tactician. He will get a higher number and thus can decide which to choose. There is so much into AI so it''s endless, though the hardest part of programming. But you should create your game so analysis could be performed easy and efficient. You should also throw in some rand''s when you think they would do good, do you play the exact way every time? No.

Share this post


Link to post
Share on other sites
Not much to say about AI but the fact today''s machines don''t have the memory nor speed to deal with player challenging AI algorithms for RTS games.
I''m sure many people know that, and I''m not saying not to include AI at all and whether or not it will cheat.

The AI should be challenging enough to a player just learning the basics of your game: building hierarchies [technology tree], interface, the different units and what they''re good for, their special abilities... etc.

That''s all the AI will be able to do.
Advanced players might have to play against more than 1 AI players.
Either let the player have more opponents or have the opponent cheat a bit, make it stronger in some way, depending on the chosen difficulty level, so the beginner player could still adjust to the game under the "Easy" mode.
Most of these games if not all have Missions, the missions are not balanced as the AI player begins with many more units resources and whatever. Is that cheating?
Without that, the game would be a piece of cake.


As I see it, these games should have access to the internet.
Becasue once the player has finished all of the single player missions, there''s not much more to see.

Starcraft as mentioned in this Topic before, has poor AI, [better than other RTS games in my opinion but still weak]
what makes it the great game it is, is the internet access.
If getting a server up and running is too much at least allow Host and Guest connection using IP addresses.

Just my couple of quarters...

Share this post


Link to post
Share on other sites
There is no common known concept to writing AI that I knew of, but I once read a really good tip:

Keep your aims low at first and do one step at a time! It is fairly impossible to write a killer AI at once!
Just begin with a siple build-a-few-units-and-send-them-to-the-enemy-base-routine.
Then play the game and and observe what the computer does wrong.
Is his own base uncovered? Well, modify the routine to let him hold a few units back to defend himself.
Doesn''t he keep ENOUGH units in his base? Make their amount dependant on the enemies amount of units! (If he knows the enemies exact amount of units like in StarCraft or if he needs to scout them first is up to you!)

You get the point? Just keep correcting what you think are his mistakes and in the end he will play as good as you!

Share this post


Link to post
Share on other sites
Maybe the games like Starcraft need to know the maps to improve performance of AI functions???

As for making AI, which I havnt yet either, some of the best advice Ive heard is:
-Start with small actions, like building blocks, and build more complex actions from these.
-Check out game programming gems 1. It has some great AI chapters on designing an "event-driven AI system". Or search the web.

Once your basic AI gets going, then you can add a "strategic layer" which would be like the different levels of command in the army. Then set up different Commander styles, like above poster says for interesting tactics. This aint no easy sh*t!

Some Links:
http://www.red3d.com/cwr/steer/
http://www.cs.berkeley.edu/~russell/ai.html

Share this post


Link to post
Share on other sites
Where do you send your units once you''ve built them?

First, you need to identify locations with a high stractegic value. Then you want to capture them. This may include the center of your enemy''s town. I''d build a strategic influence map for this, and look for points with a high local average. Different things add to the strategic influence map, like resources, hills, and chokepoints.

But what''s the best way to attack? From what direction? I''d build an influence map for that (go to http://www.gameai.com and look under Discussions), and find the path with the lowest cost. The more enemy influence, the higher cost. In short, it means get to the mines in the middle of your enemies base but flank the bunkers.

Then you need to know what the enemy is using for offense and what he''s using for defense. A simple FSM, perhaps using certain personality-specific prejudices would be best for this.

Before I mentioned detecting chokepoints. This is very very hard. One way to do it would be to build a traffic map, and find the areas with the highest traffic. Trace outward in circles from the center of each such region to find divisions that span them, blocking traffic. If the division is less than a certain distance long, then it''s a chokepoint and adds to the strategic importance of surrounding terrain.

This last chokepoint-detection thing works fine, but how can you know where to defend before the enemy attacks you there? You need to predict traffic. To do this, simulate expected traffic by finding paths between random points in your half of the map and the enemy''s half.

You need to predict influence in order to do this as well. For this, simply place enemy influence around where you''ve seen him in an expanding fashion, and of course update this when you receive more information from scouts. If you don''t know where the enemy is, expect that he''s in an unexplored region greater than a certain size. Distance from your base may affect this decision as well, since usually in RTS games you''re not put right next to your opponnent.

In short, there are a lot of maps containing values, a lot of use of pathfinding algorithms, and, to be honest, a lot of coding.

You still might find that building tanks as fast as you can and hurling them towards the center of the enemy base works just aas well!!!

Share this post


Link to post
Share on other sites
On a high-level-implementation note...
Find military books and use their strategies.
I`m not kidding.
Then implement them using whatever algorithim.

See...I really hate C&C/SC/AOE-type games.
The AI is lame...it will simply throw weak units at you, often at uncritical areas....etc...

So you need a scalable-difficulty AI that will attack using military sense.

~V''lion

the bugle4D engine;
a new dimension in graphics...
[link]http://members.tripod.com/thefivelions/bugle4d/[/link]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
when I was playing Red Alert, one of the RTS games to begin looking at. I noticed that during a Skirmish game the Computer had a huge amount of flamethrowers and so on.

NOw you may say; "But he, that game is already five years old, can you blame them for giving the computer a unfair advantage?"

But I played also a few games of CivIII and I noticed that on the higher levels the computer was able to place a city every 3 turns. That stinks because in that time you dont hav ea city with 3 inhabitants, so they use the same idea although the game is very new.

Can someone give a game that works differently?

Share this post


Link to post
Share on other sites
I don''t know about Civ III, but in Civ II, you were told about the differences in build formulas for the computer as the play level increased. The amount of food a city needed to expand was lessened was a big one. All you needed to do to verify this was spy on a city and you could see how the food display was different. That''s one change I remember off the cuff. There were others.

This isn''t necessarily a BAD way to change difficulties.

Dave Mark
Intrinsic Algorithm Development

Share this post


Link to post
Share on other sites
are all RTS games use this kind of cheating AI? is any one of them uses honest AI? i mean, what about emperor: battle for dune? what do you guys think? well, i still see the pathfinding isn''t any good, one of the unit can get stuck in the traffic. but what about their tactics and strategies?

do you think the AI in skirmish game is a bit lamer than that in campaign or mission game?

Share this post


Link to post
Share on other sites
There are not a lot of ways that you can increase the computer''s level of play short of adjusting strengths, build rates, etc. Unless you program in the possibility of the computer making an error in judgement, it will always choose the optimum strategy that it finds - which, of course, is limited by your AI programming. The point being, however, that it will generally choose the same logic from game to game... they are based on the same formula. Therefore, the computer''s ABILITY doesn''t change... the only way you can give it an advantage is to change it''s CAPABILITY through other means.

Dave Mark
Intrinsic Algorithm Development

Share this post


Link to post
Share on other sites
(joking)

Here''s an idea: divide time for AI purposes into descrete intervals (eg, pretend its turn-based but with 1/30th second turns), and use a minmax search algorithm. Predict 30 minutes or so in advance (54000 moves), and your AI will be incredible.

Of course, if every atom in the universe were a Pentium III and they all started calculating at the instant of the Big Bang, calculating even one second wouldn''t be done yet.

So it''s pretty unrealistic.

I like my multiple importance/influence maps though!

Share this post


Link to post
Share on other sites