DarkBlizz

Game On => Land of AI => STARCRAFT II: WINGS OF LIBERTY => AI Development => Topic started by: AlsoKnownAs on April 07, 2010, 03:11:47 PM

Title: Understanding the AI
Post by: 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.


Title: Re: Understanding the AI
Post by: Nissep on April 07, 2010, 03:32:32 PM
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 (http://sc2.nibbits.com/articles/view/10/writing-your-own-starcraft-ii-ai)

Hope you can find some info there :)
Title: Re: Understanding the AI
Post by: hd on April 07, 2010, 10:58:10 PM
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"
Title: Re: Understanding the AI
Post by: 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?
Title: Re: Understanding the AI
Post by: Eskimo on April 08, 2010, 06:20:59 AM
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?  ;)
Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 08, 2010, 06:33:42 AM
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?
Title: Re: Understanding the AI
Post by: Kernel64 on April 08, 2010, 08:38:23 AM
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?
Title: Re: Understanding the AI
Post by: ptanhkhoa on April 08, 2010, 11:15:43 PM
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 .

Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 09, 2010, 05:48:05 AM
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.
Title: Re: Understanding the AI
Post by: ptanhkhoa on April 09, 2010, 07:30:47 AM
 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.
   
Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 09, 2010, 07:55:54 AM
Thanks ptanhkhoa. (http://darkblizz.org/Forum2/../../profile/?u=3649) That certainly helps me a bunch XD.
Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 09, 2010, 09:27:18 AM
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.
Title: Re: Understanding the AI
Post by: ptanhkhoa on April 09, 2010, 10:32:27 AM
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 ).

Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 09, 2010, 11:31:40 AM
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?
Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 09, 2010, 12:23:51 PM
I've solved the first problem  :D , now what's left is the second one  :(
Title: Re: Understanding the AI
Post by: hd on April 09, 2010, 06:47:22 PM
While this is a forum for helping people develop AI's, what's the point in making one if someone else is actually doing the work for you? I can understand if you can't find a const or are trying to figure out how a blizzard function properly operates but to consistently ask people to essentially write code for you is pretty counter productive for everyone else.
Title: Re: Understanding the AI
Post by: Kernel64 on April 10, 2010, 03:04:30 AM
Indeed. TBH, my gripe is when people don't share, at least promise to give credit, nor simply just offer to group up with someone.

Nonetheless, I trust in the process, in that maybe, just maybe, someone might just get a good solution figured out, a module or something that he/she would share now, or eventually when it's working.

AKA, you can always scan through HexBox AI, it contains the stuff you are looking for. They are prototypes, but you can add a few lines and it's all done.

Controlling armies is much like the MutaControlTest function. Determining units is there in IsThereEnemysWithinRange function.

It's all there, but I understand that it takes time to learn how things work. Maybe throw in a few thanks here and there, that should be enough for me. It makes me feel confident that somehow, I'm not operating with a knife poised at my kidneys, and that someday, we might actually be able to create a decent AI separately, or together even if there wasn't an official agreement.

After all, it's the same engine and there's only much about it we can do ATM.

Thanks.
Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 10, 2010, 03:29:01 AM
hd,

So here comes the "pros" eh? I believe you do assume that everyone has the same amount of knowledge or perhaps who has dedicated that amount of time as you do, judging on the statement that you've made.

If I've not recalled wrongly, I think I've only started posting on this forum a couple of days ago, read through the entire Base.SC2Data just to know that "pros" here are quite holistic. My purpose in asking is not to leech on your "valuable" knowledge, but instead to create awareness among those others who may be developing as well, who knows they need the exact thing that I do but don't know where to find within your prototype codes (Worst case, where they don't understand at all). I've made another thread in the section AI Scripts saying that I would post my AI once its done, what's the purpose of posting an AI which does nothing much but to build and attack?

I guess you guys are pretty much aware that there are more viewers then those who actually make concrete replies, I don't wish to argue with any of you, but if you don't feel like helping, then that's fine, it's only a matter of time that I'll figure it out myself, I just wish that you people would help speed up my development so that I could share it with fans of SC2.

P.S. Whichever/whatever code that I may implement within my AI which is from someone else, I would directly state that it is indeed from that person and not from myself.

kernel64,

Thanks for replying in this thread, I'm looking through some other AI at the moment, heard they said that chinese modders had some new stuff in their AI, thanks a bunch  :D .
Title: Re: Understanding the AI
Post by: Kernel64 on April 10, 2010, 04:27:03 AM
Yeah, dude, I will check them out. I wish I had their link or something, my pain though is that most AIs are not compatible with my approach.

I do believe though that in time, there will be more things to get a grasp about, and specifically the XML part of unit control, much like the reapers found in Blizzard's code.

It's very exciting. I'll give you a heads up if ever I find the time and get a decent and extensive squad control function up.

It's only a matter of time that all these AIs will be taken apart and built into one AI, and it might just be your project. That's it. I'll post on this thread as soon as I get something up and running.

Cheers!
Title: Re: Understanding the AI
Post by: hd on April 10, 2010, 04:56:28 AM
Quote from: AlsoKnownAs link=topic=1612.msg15655#msg15655   date=1270888141hd,

So here comes the "pros" eh? I believe you do   assume that everyone has the same amount of knowledge or perhaps who   has dedicated that amount of time as you do, judging on the statement   that you've made.

  The only one assuming things is you. This has nothing to do with "pros"   or not. No one is a "pro" at AI scripting in Galaxy yet. Do you always   throw a fit like this?

Quote from: AlsoKnownAs   link=topic=1612.msg15655#msg15655   date=1270888141If I've not recalled wrongly, I think I've only started   posting on this forum a couple of days ago, read through the entire   Base.SC2Data just to know that "pros" here are quite holistic.

  For someone who read through the entirety of the Base.SC2Data MPQ, you   sure seem to know very little. Furthermore, how does that make anyone   holistic? No one stated anything about anything being "more" than the   sum of it's parts. Quite the contrary, actually.
 
 
Quote from: AlsoKnownAs link=topic=1612.msg15655#msg15655   date=1270888141My purpose in asking is not to leech on your "valuable"   knowledge, but instead to create awareness among those others who may be   developing as well, who knows they need the exact thing that I do but   don't know where to find within your prototype codes (Worst case, where   they don't understand at all).

  Asking "is it possible to do [insert whatever here]" or "can the galaxy   scripting engine handle [insert whatever here]" is one thing. Asking   "how do I do [whatever]" is something else entirely. You are asking   people to solve your problem. If everyone spent their time solving the   problems of everyone else, they would never get anything done. Get the   fuck over yourself. Just because you're "developing an AI" doesn't make   you special. No one is going to bend over backwards to help you. If you   can't figure out how to do something within the limitations of your   knowledge, then get more knowledge. Don't ask someone else to do it for   you, jackass.
 
 
Quote from: AlsoKnownAs link=topic=1612.msg15655#msg15655   date=1270888141I've made another thread in the section AI Scripts   saying that I would post my AI once its done, what's the purpose of   posting an AI which does nothing much but to build and attack?

  No one really cares if you're going to post your AI or not. If you don't   post it, no one will ever play it, thus it would make no difference, if   you do post it so people can play it, all of your code becomes   available to everyone anyways. This isn't some popularity contest. No   one is hitting F5 over and over waiting for your AI to be released.   Hell, you're probably just ripping off the AI someone else developed   anyways.

Quote from: AlsoKnownAs   link=topic=1612.msg15655#msg15655   date=1270888141I guess you guys are pretty much aware that there are   more viewers then those who actually make concrete replies, I don't wish   to argue with any of you, but if you don't feel like helping, then   that's fine, it's only a matter of time that I'll figure it out   myself,

  Don't feel like helping? Helping isn't doing your work or solving your   problems for you. Helping is pointing you in the right direction, which   we've already done. Who in the fuck do you think you are? You're just   another one of the many people who are "working" on an AI. You'll   probably give up in a few weeks and even if you don't, your "AI" will   most likely have no affect on the SC2 modding community.
 
 
Quote from: AlsoKnownAs link=topic=1612.msg15655#msg15655   date=1270888141I just wish that you people would help speed up my   development so that I could share it with fans of SC2.

  We should speed up YOUR development? What about OUR development? Again,   what makes you so special that you should get any sort of priority over   anyone else? In fact, thus far you've contributed nothing to the "fans"   of SC2. Everyone else here has. Arrogant prick.
 
 
Quote from: AlsoKnownAs link=topic=1612.msg15463#msg15463   date=1270724287how do i make a unit wanders   around an opponent's base instead of running around the whole   map?
Quote from: AlsoKnownAs link=topic=1612.msg15563#msg15563   date=1270810085How do I check the status of a building (e.g. whether   its being build, and when it's creating a unit)
Quote from: AlsoKnownAs link=topic=1612.msg15585#msg15585   date=1270823238how do I get the composition of units in a wave?
Quote from: AlsoKnownAs link=topic=1612.msg15599#msg15599   date=1270830700how do I make a count of units that I'm currently   engaged in battle for a specific wave?
Title: Re: Understanding the AI
Post by: AlsoKnownAs on April 10, 2010, 06:35:28 AM
Ok look hd, I'm not here to spark fire or something, I'm in a team and I'm just trying to make myself useful in that team (I'm not admitting that I'm good or anything special, I have a bunch of interest in AI development, that's all. My other mates are ripping its program (SC2Beta) already and I know nothing about the things that they're doing -_-), I don't know what you're so angry about man, and I'm certainly going to make myself useful in the other threads when I can figure out something that's good to all. At the moment, I admit that I'm new and still looking through different ways of adding codes to our team's SC2 AI, so I'll apologize to you if I offended you or something ok?

There's no need for the word f***.  :D
Title: Re: Understanding the AI
Post by: ev- on April 18, 2010, 04:28:11 PM
@hd:
What the hell is wrong asking if such a function exists?  ???


The hell, I guess every coder went through it. When start working on a new project, wasting tons of time just figuring out how (sometimes simple) things work, when at the same time you could have saved hours if only somebody would have taken some minutes answering your questions...

In the end everybody benefits from a neat new AI.
Quote
No one really cares if you're going to post your AI or not. If you   don't   post it, no one will ever play it, thus it would make no   difference, if   you do post it so people can play it, all of your code   becomes   available to everyone anyways. This isn't some popularity   contest. No   one is hitting F5 over and over waiting for your AI to be   released.   Hell, you're probably just ripping off the AI someone else   developed   anyways.

BTW I am looking forward to his AI and i bet some people will look at his code if his AI is neat.
Title: Re: Understanding the AI
Post by: Eskimo on April 19, 2010, 07:28:41 AM
Quote from: AlsoKnownAs on April 08, 2010, 06:33:42 AM
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?
HAHA i just relieased how dumb my answer was. cos i was like wtf? who doesnt know how to scout? lol ;D