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
 
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
 
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.
 
Im not very good at JASS and I'm unable to know what mistakes I have done.
 
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.
 
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: 159
I test yours it work fine.But when I change the rawcodes to my custom unit rawcode it don't work.
 
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.
 
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: 165
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 The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top