• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Anyone to help with AI?

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
737
Hi

For my hero map I've been trying to make an AI system for it and have been fine with it till today where I decided that they really needed to decide whether the risk is worth it and things.

However I'm not gunna like but I am totally confused! :/

What I had thought would be logical is that the a periodic timer would go and then there would be 2 unit groups where one would collect nearby allies and another collect enemies. Then I thought it logical to have it collect the health the units within the groups and collect their levels. Originally I thought that I would need some form of average after that but that backfired.

After that I have no idea what I'm doing anymore. The numbers are just massive as I made the game times all the health/levels together and then look at which is higher and stuff. I just dunno tbh :/ Anyone up to help? :/

  • AI Threat Detection
    • Events
    • Conditions
    • Actions
      • Set AIMoveAllyGroup = (Units within 1200.00 of TempPoint matching ((((Matching unit) belongs to an ally of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in AIMoveAllyGroup and do (Actions)
        • Loop - Actions
          • Set TempUnit = (Picked unit)
          • Set AIMoveAllyHP = (AIMoveAllyHP + (Life of TempUnit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (TempUnit is A Hero) Equal to True
            • Then - Actions
              • Set AIMoveAllyLevel = (AIMoveAllyLevel + (4 + (Hero level of TempUnit)))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
                • Then - Actions
                  • Set AIMoveAllyLevel = (AIMoveAllyLevel + 12)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
                    • Then - Actions
                      • Set AIMoveAllyLevel = (AIMoveAllyLevel + 20)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
                        • Then - Actions
                          • Set AIMoveAllyLevel = (AIMoveAllyLevel + 30)
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (TempUnit is A structure) Equal to False
                            • Then - Actions
                              • Set AIMoveAllyLevel = (AIMoveAllyLevel + (Level of TempUnit))
                            • Else - Actions
      • Set AIMoveAllyAverage = (AIMoveAllyHP x (Real(AIMoveAllyLevel)))
      • Set AIMoveAllyAverage = (AIMoveAllyAverage / (Real((Number of units in AIMoveAllyGroup))))
      • Set AIMoveEnemyGroup = (Units within 1200.00 of TempPoint matching ((((Matching unit) belongs to an enemy of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in AIMoveEnemyGroup and do (Actions)
        • Loop - Actions
          • Set TempUnit = (Picked unit)
          • Set AIMoveEnemyHP = (AIMoveEnemyHP + (Life of TempUnit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (TempUnit is A Hero) Equal to True
            • Then - Actions
              • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (4 + (Hero level of TempUnit)))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
                • Then - Actions
                  • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 12)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
                    • Then - Actions
                      • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 20)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
                        • Then - Actions
                          • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 30)
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (TempUnit is A structure) Equal to False
                            • Then - Actions
                              • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (Level of TempUnit))
                            • Else - Actions
      • Set AIMoveEnemyAverage = (AIMoveEnemyHP x (Real(AIMoveEnemyLevel)))
      • Set AIMoveEnemyAverage = (AIMoveEnemyAverage / (Real((Number of units in AIMoveEnemyGroup))))
 
Level 10
Joined
Apr 18, 2009
Messages
601
What do you want your AI system to do? Please explain in theory as clearly and as detailed as possible the behaviour that you want to achive. What should the computer controlled units do, how should they behave, when the AI system works?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
He wants the AI to be able to make an informed decision whether or not launching an attack may work.

From a human perspective, this behaviour is...
If I own 10 units and the enemy owns 100 units of about equal power, I will lose massively. My only choice is to keep defending while I try and build up.
If I own 100 units and the enemy owns 100 units of about equal power, odds of me winning are about 50:50. I could attack now and stand a good chance of winning if I want to be aggressive.
If I own 100 units and the enemy owns 10 units of about equal power, it is impossible for me to lose. I must attack now and finish it. I maybe should have attacked earlier but possibly lacked knowledge to make this decision.

RTS games use this often. Supreme Commander 1/2 is one of the best examples after that one AI guy re-wrote it all. It will not even try and attack if it knows you have a huge army compared to it since that will always fail.

The basic idea is to compute a point value of all known enemy units and compare it to the point value of your units. The difference then directly relates to the difference in army strength and thus can be used to derive some probability of an outcome. If the outcome is not favourable (enemy with greatly more points than you) then attacking is futile. If the enemy has considerably less points than you then attacking will likely succeed.

Computing this is not always an easy task. I will come back later and explain a possible method.
 
Level 13
Joined
Oct 16, 2010
Messages
737
Hi

Dr Super Good got what I wanted in a nutshell really. Just so that they would calculate whether attacking would end well or not. As this is a hero map where the only units owned by the player is a single hero and any summonable units that may have (and the odd bonus unit available in the map) they mainly needed to decide on how many creeps they had on their team at the time (the map is a lane-ing style of map but there's only one "lane", however there are 2 spawners per team which cover each side of the lane and they can pass eachother without attacking).

For now I've got this trigger:

  • AI Threat Detection
    • Events
    • Conditions
    • Actions
      • Set AIMoveAllyGroup = (Units within 800.00 of TempPoint matching ((((Matching unit) belongs to an ally of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in AIMoveAllyGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of TempUnit) Not equal to Neutral Passive
            • Then - Actions
              • Set TempUnit = (Picked unit)
              • Set AIMoveAllyHP = (AIMoveAllyHP + (Life of TempUnit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (TempUnit is A Hero) Equal to True
                • Then - Actions
                  • Set AIMoveAllyLevel = (AIMoveAllyLevel + (4 + (Hero level of TempUnit)))
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
                    • Then - Actions
                      • Set AIMoveAllyLevel = (AIMoveAllyLevel + 12)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
                        • Then - Actions
                          • Set AIMoveAllyLevel = (AIMoveAllyLevel + 20)
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
                            • Then - Actions
                              • Set AIMoveAllyLevel = (AIMoveAllyLevel + 30)
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (TempUnit is A structure) Equal to False
                                • Then - Actions
                                  • Set AIMoveAllyLevel = (AIMoveAllyLevel + (Level of TempUnit))
                                • Else - Actions
            • Else - Actions
      • Set AIMoveAllyAverage = (AIMoveAllyHP x (Real(AIMoveAllyLevel)))
      • Set AIMoveEnemyGroup = (Units within 800.00 of TempPoint matching ((((Matching unit) belongs to an enemy of AITempPlayer) Equal to True) and (((Matching unit) is alive) Equal to True)))
      • Unit Group - Pick every unit in AIMoveEnemyGroup and do (Actions)
        • Loop - Actions
          • Set TempUnit = (Picked unit)
          • Set AIMoveEnemyHP = (AIMoveEnemyHP + (Life of TempUnit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of TempUnit) Not equal to Neutral Passive
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (TempUnit is A Hero) Equal to True
                • Then - Actions
                  • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (4 + (Hero level of TempUnit)))
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 1)
                    • Then - Actions
                      • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 12)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 2)
                        • Then - Actions
                          • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 20)
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Unit-type of TempUnit) Equal to Tidal Guardian (Level 3)
                            • Then - Actions
                              • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + 30)
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (TempUnit is A structure) Equal to False
                                • Then - Actions
                                  • Set AIMoveEnemyLevel = (AIMoveEnemyLevel + (Level of TempUnit))
                                • Else - Actions
            • Else - Actions
      • Set AIMoveEnemyAverage = (AIMoveEnemyHP x (Real(AIMoveEnemyLevel)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AIMoveAllyAverage Less than (AIMoveEnemyAverage x 0.65)
        • Then - Actions
          • Unit - Order AIHeroUnit to Move To AIMovePoint
          • Unit Group - Add AIHeroUnit to AIMoveGroup
        • Else - Actions
          • Unit Group - Pick every unit in AIMoveEnemyGroup and do (Actions)
            • Loop - Actions
              • Set TempUnit = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (TempUnit is A structure) Equal to False
                  • (TempUnit is A Hero) Equal to False
                  • (Percentage life of TempUnit) Less than 15.00
                • Then - Actions
                  • Unit - Order AIHeroUnit to Move To AIMovePoint
                  • Unit Group - Add AIHeroUnit to AIMoveGroup
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (TempUnit is A Hero) Equal to True
                      • (Percentage life of TempUnit) Less than 40.00
                    • Then - Actions
                      • Unit - Order AIHeroUnit to Move To AIMovePoint
                      • Unit Group - Add AIHeroUnit to AIMoveGroup
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (TempUnit is A structure) Equal to True
                          • (Percentage life of TempUnit) Less than 20.00
                        • Then - Actions
                          • Unit - Order AIHeroUnit to Move To AIMovePoint
                          • Unit Group - Add AIHeroUnit to AIMoveGroup
                        • Else - Actions
                          • Unit Group - Remove AIHeroUnit from AIMoveGroup
          • Unit Group - Remove AIHeroUnit from AIMoveGroup
      • Set AIMoveAllyHP = 0.00
      • Set AIMoveAllyLevel = 0
      • Set AIMoveEnemyHP = 0.00
      • Set AIMoveEnemyLevel = 0
This does work in making them flee from battles however I have not managed to get them to prioritize their targets and help allies yet.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
That sort of AI is not really suited for lane mechanics. In lane mechanics your hero should be in the front line as much as possible unless there is a high chance of an ambush you cannot escape from or you are wounded.

If the hero is to play aggressively depends on what he is up against and his own power. You can kind of use this for it as if a lane has 2 heroes that are about your power then playing aggressive is suicide but if you are much stronger than the hero of a lane with a single hero on it then aggressive will work. Otherwise it should play defensive as then you can always run if stuff gets ugly. Actual lane mobs can be mostly ignored, especially at high levels.

Do not use life as an indicator as tanky heroes might not kill stuff well. Use hero level and a per hero type defined constant and level multiplier. Assign support heroes less than heroes with assassination roles for example. Factor in current life percentage as a percentage of the point value each unit is worth (since it is more meaningful since something with half life is usually half as dangerous). This is very rough but should allow your AI to decide if playing aggressively is safe or not.

To kill block it all comes down to timing. If your AI can accurately estimate when a unit will die it can attack it before the enemy does and deny them the kill with good success. To kill steal you use the same mechanics but on enemy units so you know when to attack them before the enemy can kill block. Only really applies to range units and melee units need to move which may not be convenient.

To assassinate heroes look for heroes that stand out. An enemy running by himself for example is a good target. If he has already engaged another hero is even better. If he has low life, even better yet. If your hero type has assassination type moves (usually single target DPS and debuffs) then prioritise assassination kills over normal pushing.
 
Status
Not open for further replies.
Top