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

Started by
15 comments, last by techpage 22 years, 2 months ago
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!!!
Advertisement
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
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.
Trying is the first step towards failure.
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.

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.
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
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.
#ifndef (Goldsword_was_here)#define (Goldsword_was_here)cout << "Goldsword was here" << endl;#endif
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...
The Department of Next Life - Get your Next-Life Insurance here!
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!
"If I knew where I was I wouldn't be here, believe me!"
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

This topic is closed to new replies.

Advertisement