GT AI Code Wiki
submit to reddit

Page 1
  • I will explain more clearly how the AI Scripst work.
    * When you open the GT AI, there are 3 folder :
    - Some main file:
    + RequirementAI.galaxy => This is where you get the string code of the AI.
    + BuildAI.galaxy => Placement of the AI.
    + MeleeAI.galaxy => This is where the AI Script Begin.
    + TactZergAI.galaxy/TactProtossAI.galaxy/TactTerranAI.galaxy
    => These file to control the ability of some units, but not all. Rest of the
    ability in the xml file of SC2 but not include in GTAI Scripts.
    + Zerg/Protoss/Terran.galaxy => This is where the AI Scripts of each Race begin.
    - 3 folder Green Tea Main , Commander and Gamedata:
    + Gamedata : don't need to look at this folder.
    + Commander : this is where to store the scripst of each commander.
    + Green Tea Main: basic function of GT AI.

    * Now in the Green Tea Main folder:

    + GTZInformation.galaxy : This file will give the AI some basic function.
    + GTZCount.galaxy: Count unit, measure the strength of each player.
    + GTZAttack.galaxy : Various attack function.
    + GTZAuto.galaxy : Some common process : build worker, expand, build defense.
    + GTZBuildTrain.galaxy: The build and train functions of the AI
    + GTZCondition : Some criteria of the AI here, when it will attack ? when to retreat ?
    + GTZFunction: Timer / Harvest rate/ Chatting scripts
    + GTZPoint : Most common basic point of GT, include determine nearest units.

    * Here are some example of the most common used function in GT AI:

    + GTTrain (player, priority, town, unitype, number );
    - player: always be "player";
    - priority: from 0 - 10, the higher get more build priority.
    - town: 0 : First town, 1 : Next expand town...
    - unittype : these value can be found in RequirementAI.galaxy
    - number : A number unit should train
    + GTTrainA : Train after the Unittype 2 has that number: Train 2 zealot after 1 gateway build
    + GTTrainI : Train when the unittype 2 is in progress: Train 1 Hightemplar when the Psi-storm in research.

    + GTBuild (player, priority, town, buildtype, number, flags );
    - player: always be "player";
    - priority: from 0 - 10, the higher get more build priority.
    - town: 0 : First town, 1 : Next expand town...
    - buildtype : these value can be found in RequirementAI.galaxy
    - number : A number building should build
    - flags : These are location, can be found in BuildAI.galaxy file.
    + Same at Train function, there is some variant,
    ...I: when something in progess
    ...A: after something has build
    ...T: only build 1 in many town. ( Some tech building need it )

    + GTBuildP(player, buildingtype, number, point)
    It is different from the GTBuild method because it make the AI build at specific point.
    There are some prepared point from file GTZPoint.galaxy
    -GTCenterGroup => Return the center of group.
    -GTDO => Target the gather outside point ( near the choke point )
    -GTDI => Target the gather inside point.
    -GTDI 1,2,3 => Distance variance between the in and out side defense point

    + Some conditional function (bool)
    - GTFinishA (player, unittype, number) => Return True if there has enough number of these units on the map.
    - GTFinishIA (player, unit, number) => Return True if there has enough number of units, include the units in production.

    + Some counterfuntion :

    - GTCounterUnit2(player, build1, unit1, number1, build2, number2, unit2, number3);
    When the opponent build build1 building type , the AI will respond with build build2 (number 2 is the number of the building) to produce unit2, number 3 is the ratio between unit1 and unit 2.
    * Ex: GTCounterUnit2(player, c_PB_RoboticsBay, c_PU_Colossus, 1, c_ZB_InfestationPit, 1, c_ZU_Infestor, 1.5);

    => When it see the opponent build RoboticsBay, it will give the respond to build Infestation Pit, and produce Infestor 1.5 times the quantity number of Collosus

    * Ex2: GTCounterUnit2(player, c_TB_BarracksReactor, c_TU_Marine, 8, c_ZB_BanelingNest, 1, c_ZU_Baneling, 0.3);
    => It see the opponent build BarrackReactor but it won't build any Baneling Nest yet until it see 8 Marine, then this time it will get the signal to build baneling Nest. Product Baneling 0.3 Times Marine.

    * In summarize: It need 2 condition: It must have build1 and enough number of unit1 to meet criteria.
    Some times, when the number of unit1 too much, we need to build 2 building. Like:
    * Ex3: GTCounterUnit2(player, c_ZB_Spire_Alias, c_ZU_Multalisk, 12, c_PB_Stargate, 2, c_PU_Phoenix, 1);
    That mean when it see around 12 Multalisk, definitely need to build 2 stargate and generate more phoenix. 1 phoenix vs 1 multalisk.

    * In the Commander AI folder:
    . The Basic struct of one commander is like this:
    Beside the above function, there are some special scripts like:

    + Opening
    - GTShowTimer(player) : show the timer.
    - GTPreventScout(player) : stop enemy scouting probe/scv/drone.
    - techlevel: GTGetTech : assign tech level of the AI.

    + Economy Management
    - GTExpand(player) : The AI will automatically expand when it have enough money to build second base.
    - GTMineralGas(player): AI will auto balance between Mineral and Gas. The Gas is always has priority, but when it above 300, automatically transfer worker to harvest mineral
    - GTSupply(player, tech_level): It will increase build more supply generator when the tech level increase

    + Strategy:
    - GTDefend(player): Make AI defend when necessary
    - GTRock(player): AI will destroy the rock the the Gold Minerals or the closest rock
    - GTAttack(player): AI Attack
    - GTRetreat(player): AI Retreat.

    + BuildUnit/Building:
    - GTAutoBDefend(player, 0) => Auto build the defend at main and expand
    - GTAutoResearch(player) => Will research depend on the units of the AI.

    + Expand:
    - GTAutoBExpand(player, i) => Auto build the expand base.

    + Some special function for Zerg:
    - GTMoveQueen => Move the First Queen to second base
    - GTCreepTumor(player) => Auto generate creep tumor for Queens.

    So this is a basic frameworks of the AI. Hope this help :).

    To find a fault is easy; to do better may be difficult.
    GT Creator
    avatar
    Battle.net
    Name:
    Ptanhkhoa
    Realm:
    Europe
  • I think the part of script in GTZSpeacial.galaxy for early Gateway units chronoboost should be modified to this >>>

    else if (!AITechCount(player, c_PR_WarpGateResearch, c_techCountInProgressOnly ) > 0 && !AITechCount(player, c_PB_Gateway, c_techCountInProgressOnly ) > 0)
    { if ((AITechCount(player, c_PU_Zealot, c_techCountInProgressOnly ) > 0)
    ||(AITechCount(player, c_PU_Stalker, c_techCountInProgressOnly ) > 0)
    ||(AITechCount(player, c_PU_Sentry, c_techCountInProgressOnly ) > 0)
    ||(AITechCount(player, c_PU_DarkTemplar , c_techCountInProgressOnly ) > 0)
    ||(AITechCount(player, c_PU_HighTemplar, c_techCountInProgressOnly ) > 0) )
    { GTChronoBoost(player, j, c_PB_Gateway, "TimeWarpProduction"); }
    }

    Anonymous
    193.86.146.xxx
    avatar
  • ......when is the protoss going 2++ gate build , its not necessary to chronoboost gateway units. But for 1 gate build its good to do that. Im experimenting with 4 gate build all-in push(modified real player build) and its very deadly with warpgate research as soon as possible if going 3-4 gate.

    PS: in your tutorial, first example, put letter "G" to the beginning of the line because it could confuse a lot of people :) And maybe in in 3. example, replace c_TB_BarracksReactor with c_ZB_Spire_Alias

    Anonymous
    193.86.146.xxx
    avatar
  • @ArmageddonZ: Thanks for the correct :)

    To find a fault is easy; to do better may be difficult.
    GT Creator
    avatar
    Battle.net
    Name:
    Ptanhkhoa
    Realm:
    Europe
  • Hi, which values should I modify to force infestors use Fungal Growth even more than now, sometimes Infestors runs back and forward with 100+- energy and doesnt use fungal, enemy forces must be very very clustered to force infestor use fungal now.

    part of code in TactZergAI.Galaxy>>>>>>>

    loc = AIBestTargetPoint(
    AIEffectGroup(player, c_EF_FungalGrowthSearch, enemyGroup),
    5, // min hits
    30, // damage base
    3.5, // min score

    min hits = minimal number of targets for infestor ?
    min score and min score is what, explain it to me pls , thnx :)

    Anonymous
    193.86.146.xxx
    avatar
  • min score and damage base * (correction for my last sentence)

    Anonymous
    193.86.146.xxx
    avatar
  • This is the native list defenition

    point AIBestTargetPoint (
    unitgroup group,
    int minHits,
    int damageBase,
    fixed minScore,
    fixed radius,
    point from,
    fixed range,
    int bonusAttri)

    - minHits : the point action must guarantee at least these number of units.
    - damageBase : the point action must guarantee total damage caused from this action.
    - fixed minScrore: each unit representative for a value. ( Ex : Zergling value is very small while Ultralisk is larger ). So the total value of units hits by this action must over this number.
    - fixed radius : this is circle radius of the action. ( That include all the target units )
    - point from : start of the action. (Infestor position)
    - fixed range : range from the Infestor to the point.
    - int bonusAttri: not so sure, but maybe if enough, will add value for some kinds of unit.

    To find a fault is easy; to do better may be difficult.
    GT Creator
    avatar
    Battle.net
    Name:
    Ptanhkhoa
    Realm:
    Europe
  • After your correction in 0.6, Infestors Neural parasite works well, but there are still some problems with Fungal growth, Infestor uses it very rarely. sometimes he decides to die (goes to enemy units) even with enough energy to cast Fungal growth.

    Anonymous
    193.86.146.xxx
    avatar
  • Ok, i will fix it, but will hold on the next version. The patch 1.2.0 is out and needs to modify a lot.

    To find a fault is easy; to do better may be difficult.
    GT Creator
    avatar
    Battle.net
    Name:
    Ptanhkhoa
    Realm:
    Europe
  • Wait with changing to 1.2.0 , its only Public Test Region (PTR). So maybe not all changes will be contained in real 1.2.0 . Im now experimenting with fungal growth, im changing values so we will see how it will work :D (maybe I should go to bed now lol )

    Anonymous
    193.86.146.xxx
    avatar
  • Hi, Ptanhkhoa, I was testing your new GTAttackSiege function but didnt realized any changes. When terran attacked with siege tanks ( AI has sent marines to spine crawler defense and let siege tanks unprotected). How can AI know to use this function, I didnt find any starting line in commanders or other scripts. I tried to put GTAttackSiege(player); to Terran1.galaxy see some difference but it was the same (( AI has sent marines to spine crawler defense and let siege tanks unprotected) Could you pls explain me how this siege tank protection should look in game ? thnx

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • I'm still testing it :), not complete yet.

    To find a fault is easy; to do better may be difficult.
    GT Creator
    avatar
    Battle.net
    Name:
    Ptanhkhoa
    Realm:
    Europe
  • In some commanders ive found this >>>>>>
    if (GTOArmy(player) < GTEArmy(player))
    {AISetDifficulty(player, c_diffFleeDamage, false); }
    else
    {AISetDifficulty(player, c_diffFleeDamage, true); }

    What does c_diffFleeDamage exactly mean? To remove injured units from battle or what ? So when is AI army smaller than enemy army then AI doesnt remove injured units ?

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • GTBuildTI (player, 10, -1, c_ZB_Lair_Alias, 1, 0, c_ZB_RoachWarren, 1);
    What does "-1" parameter mean in this line ?

    And explain me pls this line >>>>>>>
    GTBuildTI (player, 10, -1, c_ZB_Lair_Alias, 1, 0, c_ZB_RoachWarren, 1);

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • In Zerg13.galaxy commander in startup build there is a mistake.
    if (!GTFinishA(player, c_ZU_Queen, 1 ) )
    {

    GTTrain(player, 2, 0, c_ZU_Drone, 10);
    GTTrainI(player, 2, 0, c_ZU_Overlord, 2, c_ZU_Drone, 10);
    GTTrainI(player, 2, 0, c_ZU_Drone, 22, c_ZU_Overlord, 2);
    GTTrainI(player, 2, 0, c_ZU_Overlord, 3, c_ZU_Drone, 19 );
    GTTrainA(player, 2, 0, c_ZU_Queen, 1, c_ZU_Drone, 14 );

    GTTrainA(player, 2, 0, c_ZU_Zergling, 4, c_ZB_SpawningPool, 1);
    GTTrainA(player, 2, 0, c_ZU_Roach, 5, c_ZB_RoachWarren, 1);

    GTBuildA(player, 10, 0, c_ZB_SpawningPool, 1, c_nearResource, c_ZU_Drone, 13);
    GTBuildI(player, 2, 0, c_ZB_Extractor, 1, c_onVespeneGas, c_ZU_Drone, 19);
    GTBuildPAA(player, c_ZB_RoachWarren, 1, GTPUnitNearest(player, c_ZB_SpawningPool, GTDI(player, 0)), c_ZB_SpawningPool, 1);

    if(GTCount(player,c_ZU_Drone) == 20 && AIHasRes(player,300,0)){GTExpand2(player);}

    AIEnableStock(player);
    return;
    }
    AI is forced to build 3. overlord when is 19. drone in production but he cant make it because of supply block. (2 overlords are made = 16 food +2 food from hatchery = 18, so 3. overlord needs to be built on 18. drone >>>> GTTrainI(player, 2, 0, c_ZU_Overlord, 3, c_ZU_Drone, 18 );
    Extractor should be repaired to 18. drone too, because AI is going roaches :)

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • this script line is bad for zerg >>>>>
    if(5*GTOArmy(player) > 4*GTEArmy(player)){GTCreateWorkers (player);}

    Because when zerg morphs drones to buildings, he doesnt retrain new workers if AI army is smaller than enemy army = dead zerg AI. Every new building weakens AIs economy with this condition.

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • *if(5*GTOArmy(player) > 4*GTEArmy(player)){GTCreateWorkers (player);}
    => I may add more condition for this. When the AI is weaker army, it will build drone or army depend more condition. ( Low harvest rate, number of larva )

    *GTBuildTI (player, 10, -1, c_ZB_Lair_Alias, 1, 0, c_ZB_RoachWarren, 1);
    It's in the AI.galaxy file, -1 mean c_maintown;

    *Zerg13.galaxy, it must be a mistake :D.

    To find a fault is easy; to do better may be difficult.
    GT Creator
    avatar
    Battle.net
    Name:
    Ptanhkhoa
    Realm:
    Europe
  • Explain me pls this line >>>>>
    GTTrainI ( player, 10, c_townMain, c_ZU_Roach, GTCount(player, c_ZU_Roach)+2, c_ZU_Roach, GTCount(player, c_ZU_Roach)/16 );

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • Thats it, sometimes when I use c_townMain to make Lair there and the expansion town is too close to main base (like lower left start location on Metalopolis) it will sometimes build lair in expansion town even there is c_townMain condition :D The same problems sometimes appear when I force AI to build spine crawlers on expansion but Ive solved this with point placement condition. One tip for Zerg, AI needs to place at least one spine crawler to expansion as soon as is the hatchery finished, its quite hard to force AI to do that because there is not enough creep yet and AI will place spine crawlers in main instead on exp. Im trying to make provisional fast spine crawler placeement for expasnion , its hard :)

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • Ptanhkhoa, remove Timer for higher difficulty than very easy, there is ingame StarCraft timer which can be turned on/off in game options. Big GT timer is quite annoying :D

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • All Commanders really need counter system. For example like in Zerg3.galaxy. Because if u go air and AI is still training only zealots , U see... :)

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • Ive found the 0,64 AI has problem with Dark tepmlar production. Ive tested it with this line >>>>> GTTrainA( player, 10, c_townMain, c_PU_DarkTemplar, 1, c_PB_DarkShrine, 1);

    When AI builds Dark Shrine it waits about 2-5 minutes , then he builds DT, I dont know why. I tried to put the same line in GT 0,57 for test , and AI produced 1 DT just after creating DArk Shrine . Ive deleted all other productions from script to do not affect DT build. Before DT production AI was only forced to make 4 zealots. REsult >> same commander in 0,57 - DT production ok, same commander in 0,64 - crippled DT production for unknown reasons.

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • Is there any build command to make the AI build at or near the enemy base (for proxy)?

    Also, can the AI be ordered to attack the back or side of the enemy base (transport drop or choke blocked by rocks) instead of always the main choke?

    Corporal
    avatar
    Battle.net
    Name:
    Not telling
    Realm:
    North America
  • MarauderMan, you can build for example proxy pylon with this line >>>>>> GTBuildP2(player, c_PB_Pylon, 1, GTAP1(player));
    To make this work well, its better to put there some conditions. For example >>>>>>
    if (PointPathingPassable(GTAP1(player)) && GTFinishA(player, c_TB_SupplyDepot, 1))
    { GTBuildP2(player, c_TB_Barracks, 1, GTAP1(player)); }

    So when is the first supply depot finished, GT AI will build Barracks near enemy base on pathing passable point. This was only example for proxy build , conditions can be much more extensive, GL in experimenting :)

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
  • Ive found strange strange GTSupply behaviour for zerg, sometimes around food 100+-, Zerg stops to produce overlords but all train overlord conditions in GTSupply function are met. It stops making overlords for about 2-3 minutes , then it works normal. Ive tested it with this >>>>>>

    if (GTFinishIA(player, c_ZU_Queen, 1) || GTFinishA(player, c_ZB_RoachWarren, 1))
    { GTSupply (player, 6 + tech_level); }

    Ive added roach warren condition (for roach zerg) because when u snipe queen early in the game (queen which moved to fast expansion, then AI get stuck. I dont know why the GTSupply function stops working, but maybe it appears when some of zergs overlords are sniped so food looks like this>>>105 limit used and 98 limit available. This issue affects only zerg AI , so it must be something with killing overlords. So ive added to commander additional help for overlord production and now it works great, no supply block. Ive tested it and its good, zerg units are quite supply expensive and spawn quickly so zerg can afford to build these overlords after each another>>>>>>>>>>>>
    if (GTCount(player, c_ZU_Overlord) >= 8 && GTCount(player, c_ZU_Overlord) <= 24 )
    { GTTrainI(player, 10, 0, c_ZU_Overlord, GTCount(player, c_ZU_Overlord)+1, c_ZU_Overlord, GTCount(player, c_ZU_Overlord)/1); }

    Sergeant
    avatar
    Battle.net
    Name:
    ArmageddonZ
    Realm:
    EU Beta
Page 1

New Reply

If you were logged in you would gain 3 XP for posting a reply.

Please respect our terms of use when participating in Nibbits.

Preview
Comment
We will show a masked version of your IP address as well as your name.

Support Nibbits by linking to us: