[Solved] Footman Frenzy AI

Level 14
Joined
May 9, 2021
Messages
263
Hello.

I'm trying to figure out how to make an AI for my Footman Frenzy map, but I've no idea where to even begin...

Basically I want the AI to:

  • Choose a Hero from the Tavern and revive it if it dies.
  • Choose a Race and upgrade its Barracks and Towers when it has the resources.
  • Attack intelligently.
  • Hire from Taverns (if possible).

Can anyone help me figure this out?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,860
I'm no AI expert and I've never made TRUE Warcraft AI before, but what you're describing could be handled with a few triggers:
  • Events
    • Time - Every 0.25 seconds
  • Conditions
  • Actions
    • Player Group - Pick every player in AI_Players and do (Actions)
      • Loop - Actions
        • Set Variable AI_Player = (Picked player)
        • Set Variable AI_PN = (Player number of AI_Player)
        • Set Variable AI_Ticks[AI_PN] = (AI_Ticks[AI_PN] + 1)
        • If all conditions are true then do actions
          • If - Conditions
            • AI_Ticks[AI_PN] Equal to 4
          • Then - Actions
            • Trigger - Run AI Do Something A (ignoring conditions)
          • Else - Actions
        • If all conditions are true then do actions
          • If - Conditions
            • AI_Ticks[AI_PN] Equal to 8
          • Then - Actions
            • Trigger - Run AI Do Something B (ignoring conditions)
          • Else - Actions
        • If all conditions are true then do actions
          • If - Conditions
            • AI_Ticks[AI_PN] Equal to 12
          • Then - Actions
            • Trigger - Run AI Do Something C (ignoring conditions)
            • Set Variable AI_Ticks[AI_PN] = 0
          • Else - Actions
^ This runs 3 separate triggers, A every 1 second, B every 2 seconds, and C every 3 seconds. You can control/lock the AI_Ticks[] variable to change their behavior. This is just an example of course, the concept is what's important not the exact execution.

For picking heroes, Run a trigger like this when the hero selection phase begins:
  • Actions
    • Unit - Create 1 Beastmaster for Player 2 (Blue) at (Center of (Playable map area)) facing Default building facing degrees
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Player - Limit training of Beastmaster to 0 for (Picked player)
^ This will remove the hero from the tavern.

You can track picked heroes in a Unit-Type Array variable to get one at random:
  • Set Variable RNG = (Random number between 1 and Hero_Count_Remaining)
  • Set Variable Random_Hero_Type = Hero_Types[RNG]
  • Unit - Create 1 Random_Hero_Type...
  • Set Variable Hero_Count_Remaining = (Hero_Count_Remaining - 1)
  • -------- Remove Random_Hero_Type from the array --------

For reviving there's an Event that runs when a hero becomes revivable:
  • Events
    • Unit - A unit Becomes revivable
  • Conditions
    • (Owner is an AI) Equal to True
  • Actions
    • Unit - Revive (Triggering unit)
^ You can add the AI Player to say the AI_Revive_Group when this Event runs and periodically attempt to Revive the Hero. Then Remove them from the Player Group once the revive is successful. This could help avoid issues related to insufficient food/gold/lumber or a timing issue.

So basically:
  • Add AI Players to different Player Groups which Periodically control their behavior.
  • Detect when certain Events occur to manage these Player Groups. Add/Remove as needed.
  • Store important information in Arrays. A Hashtable would be even better (Parent Keys = Race, Child Keys = Data).
  • Track army in a Unit Group array. Track army size in an Integer array. Use Events like "Enters map" and "Dies" to manage this data.
  • Order army to Attack-Move once a certain Condition is met -> Army size is > 20, an Ally is attacking, etc.
I would have an Ability Code array for all of the Hero ability types and a Unit-Type array for all hero types. Better yet use the Hashtable equivalents.
 
Last edited:
Level 14
Joined
May 9, 2021
Messages
263
I'm no AI expert and I've never made TRUE Warcraft AI before, but what you're describing could be handled with a few triggers:
  • Events
    • Time - Every 0.25 seconds
  • Conditions
  • Actions
    • Player Group - Pick every player in AI_Players and do (Actions)
      • Loop - Actions
        • Set Variable AI_Player = (Picked player)
        • Set Variable AI_PN = (Player number of AI_Player)
        • Set Variable AI_Ticks[AI_PN] = (AI_Ticks[AI_PN] + 1)
        • If all conditions are true then do actions
          • If - Conditions
            • AI_Ticks[AI_PN] Equal to 4
          • Then - Actions
            • Trigger - Run AI Do Something A (ignoring conditions)
          • Else - Actions
        • If all conditions are true then do actions
          • If - Conditions
            • AI_Ticks[AI_PN] Equal to 8
          • Then - Actions
            • Trigger - Run AI Do Something B (ignoring conditions)
          • Else - Actions
        • If all conditions are true then do actions
          • If - Conditions
            • AI_Ticks[AI_PN] Equal to 12
          • Then - Actions
            • Trigger - Run AI Do Something C (ignoring conditions)
            • Set Variable AI_Ticks[AI_PN] = 0
          • Else - Actions
^ This runs 3 separate triggers, A every 1 second, B every 2 seconds, and C every 3 seconds. You can control/lock the AI_Ticks[] variable to change their behavior.

For picking heroes, Run a trigger like this when the hero selection phase begins:
  • Actions
    • Unit - Create 1 Beastmaster for Player 2 (Blue) at (Center of (Playable map area)) facing Default building facing degrees
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • Player - Limit training of Beastmaster to 0 for (Picked player)
This will remove the hero from the tavern. You can track picked heroes in a Unit-Type Array variable to get one at random.
  • Set Variable RNG = (Random number between 1 and Hero_Count_Remaining)
  • Set Variable Random_Hero_Type = Hero_Types[RNG]
  • Unit - Create 1 Random_Hero_Type...
  • Set Variable Hero_Count_Remaining = (Hero_Count_Remaining - 1)
  • -------- Remove Random_Hero_Type from the array --------

For reviving there's an Event that runs when a hero becomes revivable:
  • Events
    • Unit - A unit Becomes revivable
  • Conditions
    • (Owner is an AI) Equal to True
  • Actions
    • Unit - Revive (Triggering unit)
^ You can add the AI Player to say the AI_Revive_Group when this Event runs and periodically attempt to Revive the Hero. Then Remove them from the Player Group once the revive is successful. This could help avoid issues related to insufficient food/gold/lumber or a timing issue.

So basically:
  • Add AI Players to different Player Groups which Periodically control their behavior.
  • Detect when certain Events occur to manage these Player Groups. Add/Remove as needed.
  • Store important information in Arrays. A Hashtable would be even better (Parent Keys = Race, Child Keys = Data).
  • Track army in a Unit Group array. Track army size in an Integer array. Use Events like "Enters map" and "Dies" to manage this data.
  • Order army to Attack-Move once a certain Condition is met -> Army size is > 20, an Ally is attacking, etc.
I would have an Ability Code array for all of the Hero ability types and a Unit-Type array for all hero types. Better yet use the Hashtable equivalents.
This looks good! I'll give it a go. Thanks!
 
Level 21
Joined
Mar 16, 2008
Messages
952
Mostly I think to use ai scripts to make cpu players build and attack. Anything besides that maybe just trigger it. Not saying it's impossible to do with ai scripts but it just seems like a huge unknown for most map editors. If you want to make it do anything complicated like buy specific items either just swap it and order the unit with triggers or just "fake" it buying an item by reducing gold and giving the unit the item.

  • Choose a Hero from the Tavern and revive it if it dies.
I would trigger this. Not 100% sure if they will use taverns even if those heroes are one of its listed heroes in the script. Might get too confusing trying to get all the heroes and their abilities in the ai script. On that note you would also need to trigger their ability learning.

  • Choose a Race and upgrade its Barracks and Towers when it has the resources.
Would probably trigger even if you are running an ai script.

  • Attack intelligently.
Probably have a basic GUI AI script running, with all the possible heroes and units listed in the attack group. Then the AI will use all of those unit types when attacking. You will also need to make it attack using the periodic timer setting. All of this is GUI in the AI Editor. Also mess around with the settings like to retreat or not.

  • Hire from Taverns (if possible).
Again, I'm not sure if ai scripts would do this even if you have the tavern hero listed on the build priority. But I never tested.
 
Top