Sign in to follow this  

basic ai for rts

Recommended Posts

hi im doing a rts in a similar setting to colonization/civilization/total war (each team has cities on a map and moves armies around) but in real time (in c++) Im new to ai and need to get some "ai-players" going, acting not completely brainlessly. Some actions/decisions they need to ponder: when to build new towns when to attack nearby enemies or far away enemies or invading enemies what to build in/how to manage towns what to buy from the "market" look for ships to sink for treasure! i know this is a pretty big issue, but what would be a nice way to begin tackle this? My idea is to have situation trigger events like if gold and bla bla >200 and 5 years since last expansion = build new city if ships less then power*SHIPS_PER_POWER = buy new ship but how to balance all possible actions out in a nice manner? Thanks a lot Erik

Share this post

Link to post
Share on other sites
Sounds like classic finite state machine at the top level atleast. You can have states like "expand", "explore", "attack", "defend" etc and what the player does causes these states to change and each state has a set of hardcoded instructions like :
expand:find an area with resources and build this building, then that building etc
explore: move units to places that units have not yet been moved to
defend: move units to places that are under attack
attack: move units toward enemy base or units and attack

The states themselves might be pretty basic, but the illussion of intelligence arises in how you model the transition between states.

if gold and bla bla >200 and 5 years since last expansion

might be a state transition from explore to expand for example

Of course you'll have alot more states than that and you might be able to have more than one state active at a time, but you get the general idea.

Share this post

Link to post
Share on other sites
This question has been asked many times on these forums. Check out some of the search results:

"rts ai" clicky

And yeah, you're right that there's nothing small or easy about this task. The first time I worked on an AI opponent for an RTS game it took two of us somewhere around 4 months to get a nice framework up and running. 2nd time was much easier -> ~1 month. But this is generally something that is a couple of people's full-time job from start to finish on the project.

There are a ton of "the concept for a solution is simple but the implementation seems impossible" type of problems you run in to. =)

Best advice is keep it as simple as you can.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this