Username
Password
bool CountUnit(string UCheck, int Complete, int Progressing, int Queued, int Tplayer);bool RCountUnit(string UCheck, int MinComplete, int MaxComplete, int MinProgressing, int MaxProgressing, int MinQueued, int MaxQueued, int Tplayer);void FCountUnit(string UCheck, int MinComplete, int MaxComplete, int MinProgressing, int MaxProgressing, int MinQueued, int MaxQueued, bool CFeedback, bool PFeedback, bool QFeedback, int Tplayer);int TotalUnit(string UCheck, int Tplayer);void ZEnsureFood(int FoodLvL, int TPriority, int TownWhere, int Tplayer);void ZEnsureWorker(int UCount, int TPriority, int TownWhere, int Tplayer); //, string PreConUnit, int PreConCount);void ZEnsureTech(int UCount, string UTech, int TPriority, int TownWhere, int BFlag, int Tplayer);void ZEnsureUnit(int UCount, string UTech, int TPriority, int TownWhere, int Tplayer);string WeAreThrough(int Tplayer, string ThroughState);string WeAreAt(int Tplayer);
//--------------------------------------------------------------------------------------------------// Checks and returns true if it is so. Within range this time.//--------------------------------------------------------------------------------------------------bool RCountUnit(string UCheck, int MinComplete, int MaxComplete, int MinProgressing, int MaxProgressing, int MinQueued, int MaxQueued, int Tplayer){ if( (AITechCount(Tplayer, UCheck, c_techCountCompleteOnly) >= MinComplete) && (AITechCount(Tplayer, UCheck, c_techCountCompleteOnly) <= MaxComplete) && (AITechCount(Tplayer, UCheck, c_techCountInProgressOnly) >= MinProgressing) && (AITechCount(Tplayer, UCheck, c_techCountInProgressOnly) <= MaxProgressing) && (AITechCount(Tplayer, UCheck, c_techCountQueuedOnly) >= MinQueued) && (AITechCount(Tplayer, UCheck, c_techCountQueuedOnly) <= MaxQueued) ){ return true; } else { return false; }}//--------------------------------------------------------------------------------------------------// Checks and returns true if it is so. Range Specific bool setting.//--------------------------------------------------------------------------------------------------void FCountUnit(string UCheck, int MinComplete, int MaxComplete, int MinProgressing, int MaxProgressing, int MinQueued, int MaxQueued, bool CFeedback, bool PFeedback, bool QFeedback, int Tplayer){ if( (AITechCount(Tplayer, UCheck, c_techCountCompleteOnly) >= MinComplete) && (AITechCount(Tplayer, UCheck, c_techCountCompleteOnly) <= MaxComplete) ){ CFeedback = true; } else { CFeedback = false; } if( (AITechCount(Tplayer, UCheck, c_techCountInProgressOnly) >= MinProgressing) && (AITechCount(Tplayer, UCheck, c_techCountInProgressOnly) <= MaxProgressing) ){ PFeedback = true; } else { PFeedback = false; } if( (AITechCount(Tplayer, UCheck, c_techCountQueuedOnly) >= MinQueued) && (AITechCount(Tplayer, UCheck, c_techCountQueuedOnly) <= MaxQueued) ){ QFeedback = true; } else { QFeedback = false; } }//--------------------------------------------------------------------------------------------------// Counts the specified unit all including in progress and queued//--------------------------------------------------------------------------------------------------int TotalUnit(string UCheck, int Tplayer){ int a = 0; a = (AITechCount(Tplayer, UCheck, c_techCountInProgressOnly) + AITechCount(Tplayer, UCheck, c_techCountQueuedOnly) + AITechCount(Tplayer, UCheck, c_techCountCompleteOnly)); return a;}//--------------------------------------------------------------------------------------------------// Checks the total number of food if low, add one Ovie//--------------------------------------------------------------------------------------------------void ZEnsureFood(int FoodLvL, int TPriority, int TownWhere, int Tplayer){int TotalFood = 0; TotalFood = (( AITechCount(Tplayer, c_ZU_Overlord, c_techCountInProgressOnly) + AITechCount(Tplayer, c_ZU_Overlord, c_techCountQueuedOnly) + AITechCount(Tplayer, c_ZU_Overlord, c_techCountCompleteOnly) ) * 8 ); // adds hatchery count TotalFood = TotalFood + (( AITechCount(Tplayer, c_ZB_Hatchery, c_techCountInProgressOnly) + AITechCount(Tplayer, c_ZB_Hatchery, c_techCountQueuedOnly) + AITechCount(Tplayer, c_ZB_Hatchery, c_techCountCompleteOnly) ) * 2); // add lair count TotalFood = TotalFood + (( AITechCount(Tplayer, c_ZB_Lair, c_techCountInProgressOnly) + AITechCount(Tplayer, c_ZB_Lair, c_techCountQueuedOnly) + AITechCount(Tplayer, c_ZB_Lair, c_techCountCompleteOnly) ) * 2); // add hive count TotalFood = TotalFood + (( AITechCount(Tplayer, c_ZB_Hive, c_techCountInProgressOnly) + AITechCount(Tplayer, c_ZB_Hive, c_techCountQueuedOnly) + AITechCount(Tplayer, c_ZB_Hive, c_techCountCompleteOnly) ) * 2); // add overseers TotalFood = TotalFood + (( AITechCount(Tplayer, c_ZU_Overseer, c_techCountInProgressOnly) + AITechCount(Tplayer, c_ZU_Overseer, c_techCountQueuedOnly) + AITechCount(Tplayer, c_ZU_Overseer, c_techCountCompleteOnly) ) * 8 ); if ( TotalFood < FoodLvL ){ AITrain (Tplayer, TPriority, TownWhere, c_ZU_Overlord, 1); }}//--------------------------------------------------------------------------------------------------// Checks the total number of worker and trains one if less//--------------------------------------------------------------------------------------------------void ZEnsureWorker(int UCount, int TPriority, int TownWhere, int Tplayer){ //, string PreConUnit, int PreConCount){int TotalWorker = 0; TotalWorker = ( AITechCount(Tplayer, c_ZU_Drone, c_techCountInProgressOnly) + AITechCount(Tplayer, c_ZU_Drone, c_techCountQueuedOnly) + AITechCount(Tplayer, c_ZU_Drone, c_techCountCompleteOnly) ); // blocked, since even if AI queues pool first, it morphs drones. It must be: cheaper goes first// if (PreConUnit != "None") {// if ( ( TotalWorker < UCount ) && (TotalUnit(PreConUnit, Tplayer)==PreConCount) ){// AITrain (Tplayer, TPriority, TownWhere, c_ZU_Drone, 1);// }// }// else { if ( TotalWorker < UCount ) { AITrain (Tplayer, TPriority, TownWhere, c_ZU_Drone, 1); }// }}//--------------------------------------------------------------------------------------------------// Checks the total number of a certain tech and build 1 of it if low//--------------------------------------------------------------------------------------------------void ZEnsureTech(int UCount, string UTech, int TPriority, int TownWhere, int BFlag, int Tplayer){int TotalTech = 0; TotalTech = ( AITechCount(Tplayer, UTech, c_techCountInProgressOnly) + AITechCount(Tplayer, UTech, c_techCountQueuedOnly) + AITechCount(Tplayer, UTech, c_techCountCompleteOnly) ); if ( TotalTech < UCount ){ AIBuild (Tplayer, TPriority, TownWhere, UTech, 1, BFlag); }}void ZEnsureUnit(int UCount, string UTech, int TPriority, int TownWhere, int Tplayer){int TotalTech = 0; TotalTech = ( AITechCount(Tplayer, UTech, c_techCountInProgressOnly) + AITechCount(Tplayer, UTech, c_techCountQueuedOnly) + AITechCount(Tplayer, UTech, c_techCountCompleteOnly) ); if ( TotalTech < UCount ){ AITrain (Tplayer, TPriority, TownWhere, UTech, UCount); }}//---returns strings that describe statesstring WeAreThrough(int Tplayer, string ThroughState){ if( ThroughState == "GameStart") { if( (TotalUnit(c_ZB_Hatchery, Tplayer) == 1) && ((TotalUnit(c_ZU_Overlord, Tplayer) >= 1) && (TotalUnit(c_ZU_Overlord, Tplayer) <= 2)) && ((TotalUnit(c_ZU_Drone, Tplayer) >= 10) && (TotalUnit(c_ZU_Drone, Tplayer) <= 13)) && (TotalUnit(c_ZB_SpawningPool, Tplayer) < 1) ) { return "DoneGameStart"; } else { return "NotDoneGameStart"; } } else if( ThroughState == "Block1") { if( (TotalUnit(c_ZB_Hatchery, Tplayer) == 1) && ((TotalUnit(c_ZU_Overlord, Tplayer) >= 2) && (TotalUnit(c_ZU_Overlord, Tplayer) <= 3)) && ((TotalUnit(c_ZU_Drone, Tplayer) >= 13) && (TotalUnit(c_ZU_Drone, Tplayer) <= 16)) && (TotalUnit(c_ZB_SpawningPool, Tplayer) == 1) ) { return "DoneBlock1"; } else { return "NotDoneBlock1"; } } else { return "Error"; }}//---returns strings that describe statesstring WeAreAt(int Tplayer){ if( (TotalUnit(c_ZB_Hatchery, Tplayer) == 1) && (TotalUnit(c_ZU_Overlord, Tplayer) <= 1) && (TotalUnit(c_ZU_Drone, Tplayer) <= 10) && (TotalUnit(c_ZB_SpawningPool, Tplayer) < 1) ) { return "GameStart"; } if( (TotalUnit(c_ZB_Hatchery, Tplayer) == 1) && (TotalUnit(c_ZU_Overlord, Tplayer) == 2) && (TotalUnit(c_ZU_Drone, Tplayer) == 13) && (TotalUnit(c_ZB_SpawningPool, Tplayer) == 1) ) { return "Block1"; } else { return "NoWhere"; }}
AISetDifficulty(player, c_diffNormalVision, false);AIClearStock(player);//this makes AI automate resourcing like gas structsAIDefaultEconomy(player, c_ZB_Hatchery_Alias, null, c_ZU_Overlord_Alias, c_ZU_Drone, 45, c_stockIdle); //debug WeAreAt------------------------------------------------- UIDisplayMessage(PlayerGroupAll(), 1, StringToText(WeAreAt(player))); //queue debug:-------------------------------------------------- IQU = AITechCount(player, c_ZU_Drone, c_techCountQueuedOnly); SQU = IntToString(IQU); UIDisplayMessage(PlayerGroupAll(), 3, StringToText(SQU + " Drones")); IQU = AITechCount(player, c_ZB_SpawningPool, c_techCountQueuedOnly); SQU = IntToString(IQU); UIDisplayMessage(PlayerGroupAll(), 3, StringToText(SQU + " Pool")); //-------------------------------------------------------------- if ( (WeAreAt(player) == "GameStart") && (WeAreThrough(player, "GameStart") == "NotDoneGameStart") ){ //note: this thing works by queueing things. Train that is. //ZEnsureWorker(10, 10, c_townOne, player); AISetStock( player, 10, c_ZU_Drone ); } if( WeAreThrough(player, "GameStart") == "DoneGameStart" ) { //choose next block here } // >>> BLOCK 1: [OVIE.2, +3 DRONES, +POOL] process start ______________________________ // drones: complete 9-10, inprogress 0-1, queued 0-1 if (RCountUnit(c_ZU_Drone, 9, 10, 0, 1, 0, 1, player) == true) { ZEnsureFood(18, 9, c_townOne, player); ZEnsureTech(1, c_ZB_SpawningPool, 10, c_townOne, c_nearCloseDropoff, player); ZEnsureWorker(13, 10, c_townOne, player); } // >>> OVIE.2, +3 DRONES, +POOL process end __________________________________________ // we have 0 pool built, 1 inprogress, 0 queued //note: setstock doesn't come up in queue if (RCountUnit(c_ZB_SpawningPool, 0, 0, 1, 1, 0, 0, player) == true) { //ZEnsureWorker(13, 3, c_townOne, player); AISetStock( player, 16, c_ZU_Drone ); ZEnsureTech(1, c_ZB_Extractor, 10, c_townOne, c_onVespeneGas, player); //AISetStock( player, 1, c_ZB_Extractor ); } if (RCountUnit(c_ZU_Drone, 15, 16, 0, 1, 0, 1, player) == true) { //AISetStock( player, 16, c_ZU_Drone ); ZEnsureUnit(1, c_ZU_Queen, 10, c_townOne, player); ZEnsureFood(26, 1, c_townOne, player); } // >>> BLOCK (undefined): [OVIE.2, +POOL, +3 DRONES] process start ______________________________ // drones: complete 9-10, inprogress 0-1, queued 0-1 // if (RCountUnit(c_ZU_Drone, 9, 10, 0, 1, 0, 1, player) == true) { // ZEnsureFood(18, 9, c_townOne, player); // ZEnsureTech(1, c_ZB_SpawningPool, 10, c_townOne, c_nearCloseDropoff, player); // } // if (RCountUnit(c_ZB_SpawningPool, 0, 1, 1, 1, 0, 0, player) == true) { // ZEnsureWorker(13, 3, c_townOne, player); // } // >>> OVIE.2, +POOL, +3 DRONES process end __________________________________________ if (AIEnableVeryEasyStockOpen(player, c_ZU_Drone)) { return; }
if (RCountUnit(c_ZU_Drone, 9, 10, 0, 1, 0, 1, player) == true) { ZEnsureFood(18, 9, c_townOne, player); ZEnsureWorker(13, 10, c_townOne, player); ZEnsureTech(1, c_ZB_SpawningPool, 10, c_townOne, c_nearCloseDropoff, player); }
if (RCountUnit(c_ZU_Drone, 9, 10, 0, 1, 0, 1, player) == true) { ZEnsureFood(18, 9, c_townOne, player); ZEnsureTech(1, c_ZB_SpawningPool, 10, c_townOne, c_nearCloseDropoff, player); if (RCountUnit(c_ZB_SpawningPool, 0, 1, 1, 1, 0, 0, player) == true) { ZEnsureWorker(13, 3, c_townOne, player); } }
if (AITechCount(player, c_ZU_Drone, c_techCountInProgressOrBetter) >= 10){ AISetStock(player, 2, c_ZU_Overlord);}if (AITechCount(player, c_ZU_Overlord, c_techCountInProgressOrBetter) >= 2){ AISetStock(player, 1, c_ZB_SpawningPool);}if (AITechCount(player, c_ZB_SpawningPool, c_techCountInProgressOrBetter) >= 1){ AISetStock(player, 13, c_ZU_Drone);}if (AITechCount(player, c_ZU_Drone, c_techCountInProgressOrBetter) >= 13){ ASetStock(player, x, whatever);}
Hd, it gets really complicated once you've tried a lot. But you're right, there should be a way to reduce the lines and have the variations isolated somewhere and all other similar ones kept.But then again, different cases proved that certain sets of ordered lines are necessary. You're example is where it all starts. Once variations are discovered, I began to notice that blocks of the such as your example shows are called for.For example,after the exact order: 2nd ovie, +3drones, pool... you can go:a) +4 drones (16/18 food) i.) fast expo followed by: 1. Queen (17/18), Ovie3,... then choose: I. +2 lings II. +1 drone (16 drones total) 2. (...more lings)b) +2 drones, extractor1, +2 drones i.) Ovie3 (16/18 food), queen 1 (18/18) 1. R.Warren1 (17/18) I. +2lings and drone (20/26) II. +drones III. +4 lings 2. Ovie 4, +spam Roaches to 8 etc.Now, this may seem trivial, but imagine in the mid-game? If the AI is not coached to maintain a certain block, or discard, or put it on hold for an emergency, it will go All-in. And that's a bad strat.I'm looking to make the AI respond to apparent changes in the opponent's strat, unit compo, base, and respond properly that it can even make the enemy say, "I was rolled over because I had no robo for immortals. Those roaches burn."And for example, the AI will discard that and go tech to Hydra instead, if it discovers, while it was morphing lair, that the Protoss had not started 2nd assimilator and instead had 3 gates and etc etc.But, yes, I'd love it if someone can implement these concepts properly and much more efficiently. I'm taking the route that I know now. I will post them up when it's playable.As of the moment, I'm working on a function that turns on and off processing of a block, suspending it to activate another block for execution, or discarding the current block altogether for a new one.
I think initially HD's approach is going to provide fast improvement for the next version of the AI. I think ultimately a truly good AI will take Kernel64's approach, and I'm very interested in thinking about that framework. Having the AI continue with a build when it's being countered hard isn't the kind of thing player would do - a player will turtle and change tech, or try to get an economic advantage, expand to an island, something. Anything other than throwing more of the same units to their deaths.A really simple reactive change is the anti-air one that's in the current version. Another would be to escort troops with detection when the AI is getting mauled by Dark Templars. A further more complex iteration of that is that if your detection is overlords then you need to be able to protect them from anti-air. Is it complicated? Sure. And I think reactive AI is going to be really bad at first, but writing true artificial intelligence is what excites me about this project, and it will get better over time.Kernel64 please post stuff as you work on it if you are willing because that stimulates ideas.
ZEnsureWorker(10, 10, c_townOne, player); if ((RCountUnit(c_ZU_Drone, 8, 9, 0, 1, 0, 1, player) == true) && (CBlockStatus != "InProgress")){ //randomize for next block here NextBlock = RandomInt(1,100); if (NextBlock <=50) { CBlock = "Block1"; CBlockStatus = "NotStarted"; EmergencyState = "Inactive"; } else { CBlock = "Block2"; CBlockStatus = "NotStarted"; EmergencyState = "Inactive"; } } if(CBlockStatus == "NotStarted") { //we've not started the Block //check if there are emergencies //check if we need to change block, if not: CBlockStatus = "InProgress"; }//end not started if(CBlockStatus == "InProgress") { //we're currently in progress //we don't have an emergency, if ( EmergencyState == "Inactive") { //and CBlock is not Done (it could be in progress) if (CBlockStatus != "Done") { //...enter the specified block and call it if (CBlock == "Block1") { CBlockStatus = BlockOne(player); } if (CBlock == "Block2") { CBlockStatus = BlockTwo(player); } } //Q: Do we need to check if there's an emergency here? //Q: Do we need to check if we need to change block here? } //we have an emergency if ( EmergencyState == "Active") { //do the same as above here } }// end InProgress
string BlockOne(int player) {if (RCountUnit(c_ZU_Overlord, 0, 1, 0, 0, 0, 0, player) == true) { //we have 1 ovie, 0 inprogres, 0 queued ZEnsureFood(18, 9, c_townOne, player); //queue 1 ovie, or compensate if ovie is dead return "InProgress"; }if (RCountUnit(c_ZU_Overlord, 1, 2, 1, 1, 0, 0, player) == true) { //we have 1 done, 1 in progress, 0 in queue ZEnsureUnit(13, 3, c_ZU_Drone, 10, c_townOne, player); //this will not be true when the ovie is done already return "InProgress"; }if (RCountUnit(c_ZU_Drone, 10, 13, 2, 3, 0, 0, player) == true) { //we have drones: 10-13 done, 3 in progres, 0 in queue ZEnsureTech(1, 1, c_ZB_SpawningPool, 10, c_townOne, c_nearCloseDropoff, player); //all these looks like while now: we queue, while... return "InProgress"; }if (RCountUnit(c_ZB_SpawningPool, 0, 1, 1, 1, 0, 0, player) == true) { ZEnsureUnit(13, 1, c_ZU_Drone, 10, c_townOne, player); return "InProgress"; }if (RCountUnit(c_ZU_Overlord, 1, 2, 0, 0, 0, 1, player) == true) { return "InProgress";}if ((TotalUnit(c_ZB_SpawningPool, player) == 1)&& (TotalUnit(c_ZU_Drone, player) == 13) && (TotalUnit(c_ZU_Overlord, player) == 2) && (TotalUnit(c_ZB_Hatchery, player) == 1) ){ return "Done"; }else { return "NotDone"; }}string BlockTwo(int player) { //pool, ovie, +3dronesif (RCountUnit(c_ZB_SpawningPool, 0, 0, 0, 0, 0, 0, player) == true) { ZEnsureTech(1, 1, c_ZB_SpawningPool, 10, c_townOne, c_nearCloseDropoff, player); //all these looks like while now: we queue, while... ZEnsureUnit(10, 1, c_ZU_Drone, 10, c_townOne, player); return "InProgress"; }if ((RCountUnit(c_ZB_SpawningPool, 0, 1, 0, 0, 1, 1, player) == true) && (RCountUnit(c_ZU_Overlord, 1, 2, 0, 0, 0, 1, player) == true)) { return "InProgress"; }if ((RCountUnit(c_ZB_SpawningPool, 0, 0, 1, 1, 0, 0, player) == true) && (RCountUnit(c_ZU_Overlord, 1, 1, 0, 0, 0, 1, player) == true)){ ZEnsureFood(18, 9, c_townOne, player); return "InProgress"; } //for block 2, this +3drone is not automatic. Threat must be checked first.if (RCountUnit(c_ZU_Overlord, 1, 2, 1, 1, 0, 0, player) == true) { //we have 1 done, 1 in progress, 0 in queue ZEnsureUnit(13, 3, c_ZU_Drone, 10, c_townOne, player); //this will not be true when the ovie is done already return "InProgress"; }if ((TotalUnit(c_ZB_SpawningPool, player) == 1)&& (TotalUnit(c_ZU_Drone, player) == 13) && (TotalUnit(c_ZU_Overlord, player) == 2) && (TotalUnit(c_ZB_Hatchery, player) == 1) ){ return "Done"; }else { return "NotDone"; }}