AI Problem

Zar

New Member
Reaction score
4
Hello everyone.
This is the blood elves AI for my campaign.
I test it but the AI only harvest ressource without building something
JASS:

globals
    player MyVictim = Player(2) // This is the player 3 (teal)
endglobals
function ConfigureAI takes nothing returns nothing
    call SetSlowChopping( false )
    call SetPeonsRepair( true )
endfunction
function hero_levels takes nothing returns integer
    local integer hero  = GetHeroId()
    local integer level = GetHeroLevelAI()
    local integer a = 0
    if hero == E600 then
        if level == 1 or level == 3 or level == 5 then
            set a = A604
        endif
        if level == 2 or level == 4 or level == 7 then
            set a = A605
        endif
        if level >= 8 then
            set a = A606
        endif
        if level == 6 then
            set a = A607
        endif
    if hero == E600 then
        if level == 1 or level == 3 or level == 5 then
            set a = H60A
        endif
        if level == 2 or level == 4 or level == 7 then
            set a = A608
        endif
        if level >= 8 then
            set a = A609
        endif
        if level == 6 then
            set a = A60A
        endif 
    endif
    return a
    endif
endfunction
function main takes nothing returns nothing
    call CampaignAI( h603, function hero_levels )  
    call ConfigureAI( )
    // **********************************
    // *      Building Strategy         *
    // **********************************
    call SetBuildUnitEx( 1, 1, 1, h604 )
    call SetBuildUnit( 15, n603 )
    call SetBuildUnitEx( 1, 2, 5, h603 )
    call SetBuildUnitEx( 1, 1, 2, n609 )
    call SetBuildUnit( 1, h606 )
    call SetBuildUnit( 1, h60A )
    call SetBuildUnitEx( 0, 1, 2, h609 )
    call CampaignDefenderEx( 2, 2, 3, h600 ) // <==(2)
    call CampaignDefenderEx( 1, 1, 2, n604 )
    call CampaignDefenderEx( 1, 1, 2, h62 )
    // **********************************
    // *    End Building Strategy       *
    // ********************************** 
    loop
    //*** WAVE 1 *** 
    call InitAssaultGroup() // <==(1)
    call CampaignAttackerEx( 1, 3, 5, h600 ) // <==(2)
    call CampaignAttackerEx( 0, 1, 2, n604 ) 
    call CampaignAttackerEx( 0, 1, 1, h602 ) 
    call SuicideOnPlayerEx( M2, M3, M3, MyVictim ) // <==(3)
    endloop
endfunction
 

Builder Bob

Live free or don't
Reaction score
249
I think the rawcodes must be written with ' on both sides. At least that is how I had to do it when writing melee AI's. The scripts seems very different from each other though, so I could be wrong.

Example for the main thread.
JASS:
function main takes nothing returns nothing
    call CampaignAI( 'h603', function hero_levels )  
    call ConfigureAI( )
    // **********************************
    // *      Building Strategy         *
    // **********************************
    call SetBuildUnitEx( 1, 1, 1, 'h604' )
    call SetBuildUnit( 15, 'n603' )
    call SetBuildUnitEx( 1, 2, 5, 'h603' )
    call SetBuildUnitEx( 1, 1, 2, 'n609' )
    call SetBuildUnit( 1, 'h606' )
    call SetBuildUnit( 1, 'h60A' )
    call SetBuildUnitEx( 0, 1, 2, 'h609' )
    call CampaignDefenderEx( 2, 2, 3, 'h600' ) // <==(2)
    call CampaignDefenderEx( 1, 1, 2, 'n604' )
    call CampaignDefenderEx( 1, 1, 2, h62 ) // <== what kind of rawcode has only 3 characters?
    // **********************************
    // *    End Building Strategy       *
    // ********************************** 
    loop
    //*** WAVE 1 *** 
    call InitAssaultGroup() // <==(1)
    call CampaignAttackerEx( 1, 3, 5, 'h600' ) // <==(2)
    call CampaignAttackerEx( 0, 1, 2, 'n604' ) 
    call CampaignAttackerEx( 0, 1, 1, 'h602' ) 
    call SuicideOnPlayerEx( M2, M3, M3, MyVictim ) // <==(3)
    endloop
endfunction
 

Builder Bob

Live free or don't
Reaction score
249
I guess I can't help you directly then.

My advice is to go back to the beginning to figure out where the problem occurred. What campaign AI did you derive this from? Would the computer build if you changed nothing?

Now, change only small portions of the code at a time and find out when it stops working. Chances are the problem as well as the solution will become clear for you.
 

Zar

New Member
Reaction score
4
Im not very good at JASS and I'm unable to know what mistakes I have done.
 

Builder Bob

Live free or don't
Reaction score
249
Well, how did it look before you started editing? Or where did you get it from? Do you have any code that you know allows the AI to build any units at all?

I can help you from there, but not from a piece of code which I don't know the origin of.
 

Builder Bob

Live free or don't
Reaction score
249
Good :)

Now I was able to test making the AI myself and found the problem. The reason they are only harvesting is because the computer does that even without any AI. The AI script you tried running would not run at all because the code does not compile.

First of all, the rawcodes must follow the 'XXXX' form. If any of them are not exactly like this, the script will not run.

Second, your function hero_levels will not compile because the if blocks are placed incorrectly, and it does not have a return at the very end of the function.

JASS:
function hero_levels takes nothing returns integer
    local integer hero  = GetHeroId()
    local integer level = GetHeroLevelAI()
    local integer a = 0
    if hero == 'E600' then //correct the rawcodes
        if level == 1 or level == 3 or level == 5 then
            set a = 'A604' //correct the rawcodes
        endif
        if level == 2 or level == 4 or level == 7 then
            set a = 'A605' //correct the rawcodes
        endif
        if level >= 8 then
            set a = 'A606' //correct the rawcodes
        endif
        if level == 6 then
            set a = 'A607' //correct the rawcodes
        endif
    endif //add this endif to close the
    if hero == 'E600' then //correct the rawcodes
        if level == 1 or level == 3 or level == 5 then
            set a = 'H60A' //correct the rawcodes
        endif
        if level == 2 or level == 4 or level == 7 then
            set a = 'A608' //correct the rawcodes
        endif
        if level >= 8 then
            set a = 'A609' //correct the rawcodes
        endif
        if level == 6 then
            set a = 'A60A' //correct the rawcodes
        endif 
    endif
    return a
    //endif //remove this endif. It's incorrectly placed.
endfunction


A lot can be improved in this hero_levels function by the use of elseif's but I'll let you do that yourself once you get the script working.


If you continue running into trouble, you can download this small test map which I set up with a very trimmed down working AI.
JASS:
globals
    player MyVictim = Player(0) // This is the player 3 (teal)
endglobals
function ConfigureAI takes nothing returns nothing
    call SetSlowChopping( false )
    call SetPeonsRepair( true )
endfunction
function hero_levels takes nothing returns integer
    local integer hero  = GetHeroId()
    local integer level = GetHeroLevelAI()
    local integer a = 0
    return a
endfunction
function main takes nothing returns nothing
    call CampaignAI( 'hhou', function hero_levels )  
    call ConfigureAI( )
    // **********************************
    // *      Building Strategy         *
    // **********************************
    call SetReplacements( 1, 2, 3 )
    call SetBuildUnitEx( 1, 1, 1, 'htow' )
    call SetBuildUnit( 15, 'hpea' )
    call SetBuildUnitEx( 1, 2, 5, 'hhou' )
    call SetBuildUnitEx( 1, 1, 2, 'hbar' )
    call CampaignDefenderEx( 2, 2, 3, 'hfoo' )
    // **********************************
    // *    End Building Strategy       *
    // ********************************** 
    loop
    //*** WAVE 1 *** 
    call InitAssaultGroup()
    call CampaignAttackerEx( 2, 2, 3, 'hfoo' )
    call SuicideOnPlayerEx( M2, M3, M3, MyVictim )
    endloop
endfunction


Edit: Uploaded the map
 

Attachments

  • CampaignAI.w3m
    15 KB · Views: 158

Zar

New Member
Reaction score
4
I test yours it work fine.But when I change the rawcodes to my custom unit rawcode it don't work.
 

Builder Bob

Live free or don't
Reaction score
249
I test yours it work fine.But when I change the rawcodes to my custom unit rawcode it don't work.

I see. Do you know that the units the computer player is given can build those buildings and units you want it to build? In addition, rawcodes are case sensitive.
 

Builder Bob

Live free or don't
Reaction score
249
Here's another map with only custom units. The computer builds.

JASS:
globals
    player MyVictim = Player(0) // This is the player 1 (red)
endglobals
function ConfigureAI takes nothing returns nothing
    call SetSlowChopping( false )
    call SetPeonsRepair( true )
endfunction
function hero_levels takes nothing returns integer
    local integer hero  = GetHeroId()
    local integer level = GetHeroLevelAI()
    local integer a = 0
    return a
endfunction
function main takes nothing returns nothing
    call CampaignAI( 'h001', function hero_levels )  
    call ConfigureAI( )
    // **********************************
    // *      Building Strategy         *
    // **********************************
    call SetBuildUnitEx( 1, 1, 1, 'h000' )
    call SetBuildUnit( 15, 'h003' )
    call SetBuildUnitEx( 1, 2, 5, 'h001' )
    call SetBuildUnitEx( 1, 1, 2, 'h002' )
    call CampaignDefenderEx( 2, 2, 3, 'h004' )
    // **********************************
    // *    End Building Strategy       *
    // ********************************** 
    loop
    //*** WAVE 1 *** 
    call InitAssaultGroup()
    call CampaignAttackerEx( 2, 2, 3, 'h004' )
    call SuicideOnPlayerEx( M2, M3, M3, MyVictim )
    endloop
endfunction


Note: I've made the Melee Initialization trigger create custom units instead of default melee ones. It leaks, but that's another issue.

Edit: If you want I can take a look at your map. It's hard to correct problems just by guessing.
 

Attachments

  • CampaignAI.w3x
    15.6 KB · Views: 163

Zar

New Member
Reaction score
4
It work now :).Thank you.
Just a question can I make the AI more ...Random?
I mean at the beginning he alway build 15 workers and 3 houses and 8 workers go mine gold in the same mine.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top