Understanding the AI

Started by AlsoKnownAs, April 07, 2010, 03:11:47 PM

Previous topic - Next topic

AlsoKnownAs

Hi everyone,

I've worked with different forms of AI and bot scripting, but I'm unfamiliar with the SC2 AI script as I'm still new to it, I've read through most of the topic and I have some questions that I hope you guys would help me in answering them.

1.) Where in the first place does the execution of the script takes place? Which function is called first when the AI is first loaded?

2.) Does the script runs in a linear fashion which checks from top to bottom? If it does, is it limited to the boundary of one main function or one or more .galaxy files?

Thanks.



Nissep

Turdburglar wrote an excellent guide for how to write your own AI for sc2.

http://sc2.nibbits.com/articles/view/10/writing-your-own-starcraft-ii-ai

Hope you can find some info there :)

hd

Quote from: AlsoKnownAs on April 07, 2010, 03:11:47 PM
Hi everyone,

I've worked with different forms of AI and bot scripting, but I'm unfamiliar with the SC2 AI script as I'm still new to it, I've read through most of the topic and I have some questions that I hope you guys would help me in answering them.

1.) Where in the first place does the execution of the script takes place? Which function is called first when the AI is first loaded?

2.) Does the script runs in a linear fashion which checks from top to bottom? If it does, is it limited to the boundary of one main function or one or more .galaxy files?

Thanks.

To answer your questions:

1.) We don't have access to the functions that are called first but an alternative is AIMeleeStart in MeleeAI.galaxy. As far as the scripts go, it's about as close to the start as you're going to get.

2.) All code runs in a linear fashion. Lines of code are executed from top to bottom, always.

void Example(int player)
{
    AIClearStock(player);    // * this line is run first
    AISetStock(player, 1, c_ZU_Hatchery_Alias);    // * this line is run second
   
    TestSomething(player, someVar);    // * all code in this function is run before any code after this line

    // * you can control when something is handled through logic checking
    if (intReturn > 0)
    {
        // * do not run this code unless the IF evaluates to true, if it does not, this code will be skipped until it does return true
        AnotherTest(player, anotherVar);
    }

    AISetStock(player, 10, c_ZU_Zergling);    // * this won't run until after AnotherTest if the IF evaluates to true
}


You can use as many galaxy files as you want with as many lines of code as you want. You just need to include them via

include "path/file"

Notice it's a forward slash (/) and not a backward slash (\). Also note you do not include the file extension (.galaxy).

include "TriggerLibs/mycustomstuff"

AlsoKnownAs

Thanks for the reply people, I'm developing my first AI now.

O ya, about scouting, how do i make a unit wanders around an opponent's base instead of running around the whole map?

Eskimo

Quote from: AlsoKnownAs on April 08, 2010, 05:58:07 AM
Thanks for the reply people, I'm developing my first AI now.

O ya, about scouting, how do i make a unit wanders around an opponent's base instead of running around the whole map?

if u don't know.... Have u tried holding on the shift key and right clicking in the route/ direction u want u'r scouter to go?  ;)

AlsoKnownAs

Lol Eskimo, I'm not talking about the player itself, what i meant was how to make the AI wanders around an opponent's base, which function should i call, and if it's possible, can i design my own route?

Kernel64

The solution to this is obviously making a custom function that picks one unit for a scout and give it an order.

Here's personally where my problem comes up: Path finding, or simply choosing the proper/decent point to where we cast the "move" order.

Anyone got a solution to this? An algorithm or what not that chooses points around a certain unit? From point A to B, maintaining a distance of N away from an enemy unit in the path?

ptanhkhoa

#7
Yup, I also want my Ghost to come near to enemy base but don't "Attack", so he can cloacked and using "Nuke" on enemy base. So the probem here is how to make them stop the attack function when they near the enemy base and using other command, or using at the appropriate place ( ex : Dark Templar will not attack the army defense outside and attack the worker inside the base instead, harassment force will focus on the enemy worker, rather than attack building ( only when necessary ))

I also wonder about the code of the scout, ( don't know where it from) how to make them close to the enemy base but don't come near them. It will good to gather a big force in front of enemy base than attack , rather than come one by one .


AlsoKnownAs

Here goes another question of mine :D, How do I check the status of a building (e.g. whether its being build, and when it's creating a unit)

Thanks.

ptanhkhoa

 I don't know too :P, but instead i using AITechCount Function, so you can count how many unit has been built or in Progress.
    For example.   
  AITechCount(player, c_PB_Gateway, c_techCountCompleteOnly ) >= 2
  && AITechCount(player, c_PB_Gateway, c_techCountInProgessOrBetter ) <=3

That mean already have 2 gateway are build and 1 gateway are in build progess

   You can use AITechCount for unit and research too, so you know how many unit has been built and how many are in queue.
   

AlsoKnownAs

Thanks ptanhkhoa. That certainly helps me a bunch XD.

AlsoKnownAs

Hi again everyone, I've stumbled across another obstacle XD. Anyway, how do I get the composition of units in a wave? Many thanks again XD.

ptanhkhoa

The AiManageWave function in the Melee Ai are pretty useful, you can add what kind of unit, how many to your wave.

void AIManageWave (int player, int wavenum, int min, int target, int max, string type)

There are 7 type of wave
c_waveMain,     
   c_waveAttack,   
c_waveDivert1,   
    c_waveDivert2,   
c_waveClearObs, 
    c_waveHome,
   c_waveDefend

for you to manage. ( All of it can be modified in the MeleeAi.galaxy )
The Attack force should be wave_attack while the divert 1 and divert 2 are using for harrassing. ClearObs are for destroy Rock, You can use it depend on your strategy ( for example, let the Divert 1 and Divert 2 attack first to diverse the enemy while the main attack force will attack the main base ).


AlsoKnownAs

Thanks again for your prompt reply, but unfortunately that is not something I'm seeking for  :D .

I'm sorry for not making this clear in the first place, what I wanted is the composition of units in different waves, (e.g. what units are in the divert1 wave and what kind of units are in the divert2 wave). I know there are ways to keep track of the units by manually adding units to a specific wave by creating one or more, but what if I wanted to know the composition of units in my enemies wave'? Is there a function or custom function to do so?

On top of that, how do I make a count of units that I'm currently engaged in battle for a specific wave? I can do a count of units, but that would compose of the units that I've counted earlier if they are not dead already, so that would exaggerate the count. Is there some kind of function which does a count of units for a specific wave which falls within its radius of sight?

AlsoKnownAs

I've solved the first problem  :D , now what's left is the second one  :(