Learning the SC2 AI - An Intro

Started by adaptive, March 03, 2010, 03:17:10 PM

Previous topic - Next topic

adaptive

To get started with AI programming you will first need to be able to extract the mpq files. This is because Blizzard packs all of its files into these mpq archives. Go get MPQ Explorer: http://darkblizz.org/wiki/doku.php?id=mpq

Once you have that go and extract the file "Program Files\StarCraft II Beta\Mods\Liberty.SC2Mod\Base.SC2Data" To a folder somewhere. I extracted it to a folder on the desktop called "AI Testing".

Now in that folder there is now 3 folders: GameData, TriggerLibs, and TextureReduction. We want to go into TriggerLibs. Now you see all of the galaxy files. You can now edit the AI, then we will work to repack the directory and replace the existing Base.SC2Data.

So, the files AI.galaxy and BuildAI.galaxy(from here on I am only going to refer to the file without the .galaxy ending) basically setup most of the constants for future functions. If you are new to programming then the reasons you want to have constants defined is so that the program can use numbers(which are much faster than words) to define things like which race you are talking about:

const int c_raceProtoss = 1;
const int c_raceTerran  = 2;
const int c_raceZerg    = 3;


The file Computer.galaxy is useful to include new files. Such as if you want to start building API's that all the races can use, then you could put it in a separate file and have it included in computer.galaxy. For people who are not use to programming think of it this way, if you don't list your new file to be 'included' in either Computer.galaxy or another file then SC2 will ignore your file.

Now, the place to get started reading is TacticalAI, it defines many api functions then includes at the end the files TactProtAI and TactTerrAI and TactZergAI. These three files include more specific AI tactical data. Such as when in a battle the code "order AIForceField " will define who should be force fielded first. If you are trying to improve Micro management then you will want to start with these order functions.

If you are trying to improve Macro management for the AI you will want to look in the files called Protoss0 etc. This defines the Early, Mid, and Late game strategies.

Up next will be the definitions of how SC2 AI 'does stuff'.

vitalsine

Great start to this walkthrough of AI scripting.

adaptive

I'm trying to figure out what the conceptual approach they took the executing the AI scripts.

1. Do the scripts just define the desired state, and the AI(in some black box fashion) try to get there? If this is the case, then some of the black box features are given to the script writer to change, such as the api to determine which units should be ForceFielded in the TactProtAI file. If this is the case then we are limited in what we can do for the AI.

2. Does the AI use a polling state? Which means is there an API that is called each 'turn' that the AI script writers can decide what to check on for each turn?

3. Does the AI have 'callbacks' ? Such as if a player attacks the AI is there a way to register that the function 'respondToAttack' should be run. Or will it rely on a state checking check which would mean it is #2 a polling method.