Large-Scale Real-Time Strategy (RTS) for the iPad & iPhone 

Twitter LinkedIn YouTube E-mail


Published on September 3, 2012 by

Artificial Intelligence. I still remember when the AI gurus were bragging in the 80ies what AI would be able to do ten years from then. Not even a fraction of these visions have become true, not even 30 years later. AI programming is difficult and none of the IT domains have failed more in achieving their own proclaimed goals than they have.

I remember visiting an international robocup a few years ago. This involves robots playing soccer against each other, or to be more accurate, usually totally failing at doing so. Most of the time, they were erring around on the field, or they were experiencing some kind of hardware failure and were out for “medical treatment”.

A particular humiliating situation was when all players of one team were out but the other team still failed to score. I don’t want to question the countless hours the teams from all around the world had put into these robots but from a mere spectator view, it was truly disappointing.

At least it shows that AI programming is hard. Unfortunately, an RTS game involves a lot of AI programming, on various levels. In addition, AI algorithms can be computationally expensive and a mobile device – despite being a small computer – is no desktop PC or console and only has limited resources.

I had already a lot of AI challenges in my last game, Air Force vs Luftwaffe, when it came to the AI opponents. I had to throw several implementations into the bin because they didn’t provide the game experience I wanted.

For implementing the final AI, I was studying flight manoeuvres, like Immelmann, Split S, and such, trying to come up with a good AI. After all, for a game like that the quality of the AI makes the difference between a boring action game and a challenging, entertaining game.

Eventually, the game had like a dozen different manoeuvres to pick from. All airplanes were constantly thinking how to react in their situation, trying to shake enemies or getting a good angle of fire on them. This is what I usually call the Unit AI.

Unit AI

Unit AI means each unit having a small brain and it’s definitely needed in each and every RTS. After all, in an RTS, you don’t really control every single thing of your potentially hundreds of units. They need to be intelligent enough to do some basic decisions while you concentrate on the big picture. So, each unit needs to be aware of its surroundings, pick a suitable target (knowing its strengths), fire at it and generally come with some common sense.

While as a player, you often don’t notice the unit AI, it clearly gets noticeable when it is lacklustering. Nothing is more frustrating than a stupid unit AI where you really have to micro manage every single unit or it would stand there and get shot looking stupid or chase targets it isn’t supposed to go after.

Ontop of it, multiple units must act as a group. If I select a couple of units and issue a move command, then they should not move around like headless chicken and then end up stockpiled ontop of each other but move in formation. This is typically referred to as the steering AI. Pathfinding is another well-known AI challenge. This sounds easier than it actually is and needs some AI brainwork put into the game so units behave in a sensible way.

Some units also have special needs, like strikecraft in my game needs to dogfight other strikecraft. They are not stationary in space but constantly moving, evading enemy fire and hunting down targets on their own. Ships also need to aim and lead, taking enemy ship movement into account. Large ships with multiple weapon mounts must pick different suitable targets. A destroyer will be firing a heavy homing missile at a nearby frigate, working on the ship in front of it with a front-mounted ion beam cannon while trying to take down fighters with a rotating turret. So even the weapon mount points have their own brain!

In addition, unit AI is also a performance factor. The more units on the field, the more valuable CPU time is used up for controlling all these units.

Skirmish AI

Obviously, in a pure multiplayer game, you can get away with just a unit AI implementation. After all, everything else is done by human beings playing against each other. However, if you plan on a single player experience then somebody must take over the opponent – or things tend to be rather boring I’m afraid.

Making a good Skirmish AI is more than a challenge. Actually, if you look at today’s RTS games, they often come with a pretty good opponent but overall, it is pretty apparent that a lot of things are scripted.

I now have come up with a Skirmish AI implementation that makes for a worthy opponent. Sure, RTS veterans will be able to crush it with ease but if you are new to the game or genre, then you are in for a challenge. It uses a multi-layered system with different AI submanagers fighting over the resources. The Military AI’s goal is to come up with a good fleet to counter the enemy. It doesn’t care about the rest. The Construction AI works on buildings and also tries to boost our economy (by building more eco buildings). The Tech AI wants to advance in tech.
All these individual AIs are very one-sided so an overall Strategic AI controls how to distribute the available resources to the sub managers. If we want to be aggressive, then the Military AI gets a lot of resources at its disposal. If, however, it finds out that we are not able to keep up our production, then it will decide to boom, then the Construction AI will be preferred so it can build more metal mines and crystal processors.

The AIs will also flag their needs to each other. The Military AI will request factories to be constructed or request a new supply depot to avoid running out of supply. It may also ask the Tech AI to research new ship types it wants to use against the enemy.

Internally, all these AI parts are rule-based. There’s also some kind of battle simulation going on behind the scenes that tries to find out what units are needed. A lot comes down to fine tuning some key values to give a credible behaviour.

For example, one of the hardest decisions is what ships to build or whether to build any at all (and tech instead for example). In this case, each spaceship will get a utitity and a threat calculated. The utility reflects how useful it would be to have that ship around, the threat basically sums up how hard that ship is countered by the opponent.

The AI must now straddle the fine line between not building ships when it should do so (overvaluing the threat against them) and building ships that get owned instantly (overvaluing the utility).

There’s a lot more to it like deciding when to build more factories to double produce, resource management and what to tech to, all about decision making. With a bit of tweaking and adding exception rules, the AI now plays pretty reasonably in most situations.

Tactical AI

While the Strategic AI and its subordinates operate on the strategic level, the Fleet AI operates on the tactical level.

The Fleet AI is controlling fleets on the map trying to do damage to either enemy ships or infrastructure, scout or expand. To do this job, it needs to have good info on the map so the game maintains an influence map that knows how much influence each faction has at a particular location, separated into different ship classes. That way, the Fleet AI can plan effective attacks.

A Battle Simulator simulates battles between teams on a regular base. It doesn’t do an accurate simulation taking position into account but compares stats and tries to guess the outcome of a confrontation. This information is used by the Military AI to build the right ships or ask the Tech AI to research new ships to counter the enemy.

Campaign AI

I haven’t started on that one yet, the campaign may introduce additional challenges to the AI ontop of what the pure Skirmish AI does. Campaign AIs are usually more scripted but may reuse parts of the Skirmish AI but impose restrictions like certain tech not being unlocked.

 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 

© Bitmen Studios