[AI] IA problems and Questions

JASS:
//============================================================================
//  Golden Order 
//============================================================================
globals
    player user = PlayerEx(21)  
    player orange = PlayerEx(6) 

    constant integer PURIFIER = 'H60K'
endglobals

//============================================================================
//  main
//============================================================================
function main takes nothing returns nothing
    call CampaignAI('h605', null)
    call SetReplacements(99,99,99)
    set campaign_wood_peons = 4
    call SetPeonsRepair( true )
    call GroupTimedLife(true)

    // BUILDS (no farms because town hall have 100 food.)
    call SetBuildUnitEx( 1, 1, 1, 'h60N' ) // Peasant
    call SetBuildUnitEx( 1, 1, 1, 'h605' ) // Golden Order Town Hall
    call SetBuildUnitEx( 1, 1, 1, 'h60A' ) // Golden Order Barracks
    call SetBuildUnitEx( 1, 1, 1, 'h60B' ) // Lumber Mill
    call SetBuildUnitEx( 1, 1, 1, 'h609' ) // Altar of Kings
    call SetBuildUnitEx( 1, 1, 1, 'h60C' ) // Blacksmith
    call SetBuildUnitEx( 1, 1, 1, 'h606' ) // Golden Order Keep
    call SetBuildUnitEx( 1, 1, 1, 'h60E' ) // Arcane Sanctum
    call SetBuildUnitEx( 1, 1, 1, 'h607' ) // Golden Order Castle
    call SetBuildUnitEx( 2, 2, 2, 'h60F' ) // Guard Tower
    call SetBuildUnitEx( 1, 1, 1, 'h60G' ) // Cannon Tower
    call SetBuildUnitEx( 1, 1, 1, 'h60H' ) // Arcane Tower
    call SetBuildUnitEx( 6, 6, 6, 'h60N' ) // Peasant (6)

    // DEFENSORES ()
    call CampaignDefenderEx( 2, 2, 2, 'h600' ) // Varkhazan Footman
    call CampaignDefenderEx( 1, 1, 1, 'h603' ) // Varkhazan Spearman
    call CampaignDefenderEx( 2, 2, 2, 'h602' ) // Varkhazan Bowman
    call CampaignDefenderEx( 1, 1, 1, 'h604' ) // Varkhazan Priest
    call CampaignDefenderEx( 1, 1, 1, PURIFIER ) // Purifier 

    //*** WAVE 1 () ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 3, 3, 3, 'h600' ) // Varkhazan Footman
    call CampaignAttackerEx( 2, 2, 2, 'h602' ) // Varkhazan Bowman
    call SuicideOnPlayerEx(M2,M2,M2,user)

    //*** WAVE 2 () ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 3, 3, 3, 'h600' ) // Varkhazan Footman
    call CampaignAttackerEx( 2, 2, 2, 'h603' ) // Varkhazan Spearman
    call CampaignAttackerEx( 1, 1, 1, 'h604' ) // Varkhazan Priest
    call CampaignAttackerEx( 1, 1, 1, PURIFIER ) // Purifier 
    call SuicideOnPlayerEx(M4,M4,M4,user)

    //*** WAVE 3 () ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 2, 2, 2, 'h601' ) // Varkhazan Knight
    call CampaignAttackerEx( 3, 3, 3, 'h603' ) // Varkhazan Spearman
    call CampaignAttackerEx( 2, 2, 2, 'h602' ) // Varkhazan Bowman
    call CampaignAttackerEx( 1, 1, 1, 'h604' ) // Varkhazan Priest
    call SuicideOnPlayerEx(M7,M7,M7,user)

    //*** WAVE 4 () ***
    loop
        call InitAssaultGroup()
        call CampaignAttackerEx( 3, 3, 3, 'h601' ) // Varkhazan Knight
        call CampaignAttackerEx( 4, 4, 4, 'h600' ) // Varkhazan Footman
        call CampaignAttackerEx( 3, 3, 3, 'h602' ) // Varkhazan Bowman
        call CampaignAttackerEx( 2, 2, 2, 'h603' ) // Varkhazan Spearman
        call CampaignAttackerEx( 2, 2, 2, 'h604' ) // Varkhazan Priest
        call CampaignAttackerEx( 1, 1, 1, PURIFIER ) // Purifier 
        call SuicideOnPlayerEx(M9,M9,M9,user)
    endloop
endfunction

Does this AI code work perfectly? Is the AI only meant for building and attacking, or can it be set up for some other system as well? Please, any tips involving AI are welcome!
 
You've got a solid foundation here for a campaign-style AI, but you are correct in feeling that it’s strictly a macro/production script.


To answer your question: Does the code work perfectly?

—}For a basic "build a base and send waves" scenario, yes.


The ⁠loop ... endloop⁠ on Wave 4 is standard practice for Campaign AI. Because ⁠SuicideOnPlayerEx⁠ has built-in delays based on your ⁠M9⁠ variable, it acts as an infinite repeating wave to pressure the player until they win.


One minor flaw: If your ⁠PURIFIER ('H60K')⁠ is a Hero unit, it will currently spawn and attack, but it will not learn any abilities.


⁠.ai⁠ scripts are meant for Macro-management. You can add a few extra systems directly into this text file to make the AI smarter at running its base:

Hero Skills: Use ⁠call SetSkillArray(1, 'AHbz')⁠ to tell the AI which spells to learn as it levels up.

Targeting Priorities: You can use ⁠call SetTargetHeroes(true)⁠ to make attack waves prioritize player heroes.


Regarding the addition to the script you can script the AI to build expansions at new gold mines when their main mine runs low.


Note that if you are hoping to use this script to make the AI ‘smart’ it won’t do because AI scripts run in their own isolated thread. They cannot easily talk to your map's normal triggers, hashtables, or custom systems.


If you want "smart micro" you will have to use triggers outside the Ai script.
 
Back
Top