Advertisement

Base-building AI for RTS games

Started by October 20, 2005 06:25 AM
13 comments, last by d000hg 19 years, 1 month ago
If you have warcraft 3, you can extract AI scripts from the mpq files that include base building, exploration, etc, to see the kind of thing they did. I'm fairly certain it'd be close to what you call 'cheating' except that it isn't map specific and there is some AI in the engine that selects where to build stuff so that resource drop off buildings are built near the appropriate resources, but the script decides what to build when (iirc in a fuzzy sort of manner so it isn't an absolute script it just adds several things to a queue and makes sure it has enough of each type of building).

You'd have to look at it yourself to see xactly how it works, though, because I'm not all that familiar with it's AI system.

Even if you don't have the game, reading a tutorial on creating AI for it might be enlightening.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Quote: Original post by d000hg
Your rating has been bumped up another notch. If you're helpful again I've run out of notches!


Ah! I better watch out! =)
but hey, thanks!
----------------------~NQ - semi-pro graphical artist and hobbyist programmer
Advertisement
What about a weighted Map or tree of action nodes?

You define a set of action nodes and then give them a default weighting of 0 to 1 and a modifier weight. You then create a path connecting nodes to a particular goal state. The AI then divides its resources amongst the various goals based on the goals weighting modified by the weighting of the current action node within in that path.

So let’s say there is a Goal build 10 Infantry
The path might look like this:
-Tier 1-
Build Town Center -1
-Tier 2 -
Build Barracks -.5
Build Munitions Plant - .5
- Tier 3 -
Have 10 rifles - .5
Have 1000 credits -.5
- Goal -
Build 10 infantry

You don’t need the node the weighting if you want the AI to take one step at a time approach meaning that for each goal it only performs one action at a time. However if you want to be multitask that’s where the weightings come into play in each tier. For each node the AI checks that it has what is required and then performs that action if it doesn’t it either creates a new goal or increases the priority of the existing one.
Quote: Original post by NQ

A working example
Building the AI's strategy:
Write some values like this:

// globals
low_resources = 100
high_resources = 2000
weight_army = 0.6
weight_base = 0.3
weight_defence = 0.3

// unit weights
weight_soldiers = 0.1
weight_tanks = 0.2

Data driven AI like this is very fun. Allowing players to custimize it, learning through Genetric Algs, and writing scripts to pit the AI against each other finding the best values are only the most obvious of these fun things.
Taking that goal-based method, how about a constant set of goals, but each can only be done if the lower-level / higher-priority are true?

Ie
<Goal>NumCommandCentres >= 1</><Goal>NumMines >= 1</><Goal>NumTankFactories >= 1</><Goal>NumUnits >= 4 </><Goal>NumMines >= 2 </><Goal>NumUnits >= 8 </><Goal>NumMines >= 3 </>...
Then it just works down the goal list until if finds one which is not met. This would in theory mean that if you destroy the enemy command centre or go after its mines then it will try to respond.
This would just be a base/army construction AI - a separate AI would decide to launch an attack, or set a 'defcon' value which could be used by the base-building AI to alter the base structure depending on the risk of an attack.

I think it's similar to what the last two suggested? Of course rather than a linear list of goals, the list could split into two after a controlcentre and a mine are built - one list controlling the resource side and the other what units to build.

This topic is closed to new replies.

Advertisement