View Single Post
Old 03-01-2009, 06:05 PM   #1
Michael Peppers
Michael Peppers's Avatar
Join Date: Jan 2009
Posts: 1,308

Michael Peppers is a jewel in the rough (188)Michael Peppers is a jewel in the rough (188)Michael Peppers is a jewel in the rough (188)

Idea Competitive AI Step by Step with AI Editor

Competitive AI Step by Step
with AI Editor

In this tutorial I'm gonna show you how to make a good melee AI using the AI Editor, I'm not gonna talk about how the editor works since there are other good tutorials made for that purpose, like Av3n's "The AI Editor".

What you must know to understand and use correctly this tutorial?

1. How does the AI Editor work, if you don't know that, see Av3n's tutorial then come back here later.
2. How do conditions work in GUI Triggering

Another thing: I didn't post any screen of the editor because I have the italian version so it won't help you much, and it may cause side effects like: confusion or learning some italian (both things to avoid xD).
However Sunwarrior25 provided me some screens that will do the job...

I'm gonna base this tutorial on making an AI for a normal Human Race, if it's not what you want (very probably) then adapt this explaination to your needings.

Ok, let's start. We're gonna use the AI Editor page by page, the first page is General,
Zoom (requires log in)
here we set:
  • Name: Write the name of the AI here only if you want it to have a different name from the normal "Player 2, Player 10, Player X"

  • Race: we'll set it to Human (That's Important! if you create a custom race you have to set it to Custom, because with another value you can't change the settings for: Base Building (Hall), Mine Building (Needed only for Haunted Mines), Gold Worker and Lumber Worker in the Building page.)

  • Set Player Name: Check this only if you wrote a custom name.

  • Defend Users: This will cause this AI to help its allies when they have enough military units, I suggest you to check it only if you want to have the "United Squads" feature of your map always activated, or if you want this AI to do kamikaze attacks to creeps.

  • Allow Home Changes: Check this only if you want them to have another chance to stay in the game after their base has been destroyed.

  • Then I suggest you to check all the other fields, except for "Random Paths" and "Slow Harvesting".

Custom Data: IMPORTANT! The race you're gonna use is a normal race or it has been made modifying the object data? In the first case skip this zone, in the second case, you have to import in the AI editor the .w3o file containing the custom Object Data.

Conditions: Here you set the conditions you're gonna use more that one time in the next pages (except Heroes page), I suggest you to set at least these two conditions:

Attack Possible: (((Total number of Footman units completed) Bigger or Equal to 4) And ((Total number of Rifleman units completed) Bigger or Equal to 3) Or ((Total number of Spellbreaker units completed) Bigger or Equal to 3) And ((Total number of Rifleman units completed) Bigger or Equal to 3))

It's a sequence of "Integer", "And" and "Or" conditions. Why do we have to write all of this? We're gonna set this as the main parameter the AI must use to know when it can attack. Change the underlined fields of this trigger to match it with your race:

(((Total number of T1 Melee units completed) Bigger or equal to X) And ((Total numer of Ranged units completed) Bigger or equal to Y) Or (((Total number of T2 Melee units completed) Bigger or equal to Z) And ((Total numer of Ranged units completed) Bigger or equal to Y)

T1 Melee:
Footman, Ghoul: X = 4
Grunt, Huntress: X = 3

Archer, Headhunter: Y = 4
Rifleman, Crypt Spider: Y = 3

T2 Melee:
Spellbreaker, Raider: Z = 3

Night-Elves and Undead don't have a T2 Melee unit, so skip the second part of the condition if you use them, or set at its place the T3 Melee unit.

Hall: (Food Produced) Minor of 60

(60 is the number of food you have after having upgraded the hall to Tier 2 in my example)
(That's not an important condition normally, but if you use Orcs or Humans, expecially Humans (they have Spellbreakers, that are better than Footmen, while Grunts and Raiders have pretty similar statistics), you can write down this condition and use it later to disable the training of T1 Melee units when the food is more than 59, in this way the AI will have more food to train stronger units (10 in this example))

(However, in the case of Undead and Night-Elves, this trigger could need to be adapted (to the number of food produced after upgrading the hall to Tier 3) or removed, due to conflicts that could happen with the "Attack Possible" condition, so remember that if you use these two conditions, they are strictly linked, so if you change the first, you probably should change also the second and vice-versa)

Another condition that is essential, if you use units that are upgraded to others: (like Siege Machines (Humans) or Troll Headhunters)

This example will be on Siege Machines:

Siege: (Upgrade level of Scatter Rockets) Equal to 0

If that's not clear, here is the example with the Headhunter:

Headhunter: (Upgrade level of Berserker) Equal to 0

(You must set this condition to all the units that are affected by that power-up then, after making the AI use that power-up, set the building queue of all the units of the new type that should be trained)

(If you don't set this, at the moment of the upgrade the AI won't find the non-upgraded unit to be trainable, thus blocking all the AI unit training)

Ok, we finished with the first page, and we can go to the second one, Heroes:
Zoom (requires log in)

Used heroes: Here you set the number and the kind of heroes.

Normal values in Training Order in each field per hero number:
  1. 1 Hero: 100% (5 fields disabled)
  2. 2 Heroes: 50%, 50% (4 fields disabled)
  3. 3 Heroes: 17%, 17%, 16%, 17%, 17%, 16% (all fields activated)
In the case of 3 heroes, write the values this way, for each field the AI Editor will try to set them in another way, so you have to correct the wrong fields until the result is what you see above.

Skill selection: There's not much to say, here you choose how will AI's heroes learn each skil.

Another thing, if your hero has custom abilities and are not shown in this zone, open the object editor, copy the "Hero Skills" field, return the field to its default values, then paste the "Hero Skills" field and export the Object Data again and import it again in your AI editor.
If this method doesn't work, retry a couple of times and it should, if it doesn't work even after 3 attempts, feel free to PM me the map and the ".wai" file and I'll try to fix it...

Third page (CAUTION! This is the hardest part, some wrong inputs in this page and you'll face a high number of bugs), Building:
Zoom (requires log in)

First parameters:
  • Base Building: Put here the Tier 1 Building of your race

  • Mine Building: Usually this is set to nothing, change it only if you use a Haunted Gold Mine or a Mine based on the Haunted Gold Mine (no, Entagled Gold Mines don't have to be set)

  • Gold Worker: Simple, harvests gold

  • Lumber Worker: Usually it's the same value of the Gold Worker but, if you (example) use Undead, here you'll set "Ghoul"

Harvest Priorities (this is how I set them):

HTML Code:
Harvest Workers Town Conditions Gold 5 Actual Mine 1 None Lumber 5 Any None

(Lumber Worker numbers should be changed depending on how many lumber they can harvest in one trip)

Faerie Fire (5 Lumber, no trip) : 6 Workers
Peon (10, with trip) : 5-6 Workers
Peasant (10 (Improveable), with trip) : 4-5 Workers
Ghoul (20, with trip) : 3-4 Workers

Build Priorities (The MOST important thing in a whole AI, this is an example step by step (and provided with comments) using Humans):

HTML Code:
Build Total Food Town Conditions Town Hall 1 0/12 Any None* Peasant 1 (1) 1/12 Mine 1 None Peasant 2 (2) 2/12 Mine 1 None Peasant 3 (3) 3/12 Mine 1 None Peasant 4 (4) 4/12 Mine 1 None Peasant 5 (5) 5/12 Mine 1 None** Farm 1 5/18 Any None Peasant 6 6/18 Any None Peasant 7 7/18 Any None Altar Of Kings 1 - Any None Barracks 1 - Any None Peasant 8 8/18 Any None Peasant 9 9/18 Any None Peasant 10 10/18 Any None Hero - First 1 15/18 Any None Farm 2 15/24 Any None Footman 1 17/24 Any Hall*** Footman 2 19/24 Any Hall Farm 3 19/30 Any None Footman 3 21/30 Any Hall Footman 4 23/30 Any Hall Blacksmith 1 - Any None Footman 5 25/30 Any Hall Farm 4 25/36 Any None Rifleman 1 28/36 Any None Rifleman 2 31/36 Any None Farm 5 31/42 Any None Rifleman 3 34/42 Any None Rifleman 4 37/42 Any None Rifleman 5 40/42 Any None Lumber Mill 1 - Any None Farm 6 40/48 Any None Arcane Vault 1 - Any None (Here put all (or some, if you prefer) T1 upgrades) Fortress 1 - Any None**** Home Expansion 2 40/60 Any None Hero - Second 1 45/60 Any None Arcane Sanctum 1 - Any None Spellbreaker 1 48/60 Any None Spellbreaker 2 51/60 Any None Spellbreaker 3 54/60 Any None Farm 7 54/66 Any None Spellbreaker 4 57/66 Any None Spellbreaker 5 60/66 Any None Farm 8 60/72 Any None Spellbreaker 6 63/72 Any None Farm 9 63/78 Any None Priest 1 65/78 Any None Sorceress 1 67/78 Any None Workshop 1 - Any None Farm 10 67/84 Any None Mortar Team 1 70/84 Any None (Here put all (or some, if you prefer) T2 upgrades) Castle 1 - Any None Knight 1 74/84 Any None Farm 11 74/90 Any None Knight 2 78/90 Any None Knight 3 82/90 Any None Farm 12 82/96 Any None Knight 4 86/96 Any None Farm 13 86/102 Any None Knight 5 90/102 Any None Knight 6 94/102 Any None***** Gryphon Aviary 1 - Any None Hero - Third 1 99/102 Any None Gryphon Rider 1 103/102 Any None****** Dragon-Hawk 1 106/102 Any None Dragon-Hawk 2 109/102 Any None (Here put all (or some, if you prefer) T3 upgrades)

*In the case of a custom hall, maybe it's better to add a condition: (unless you want them to have a bunch of unused T1 Halls in their base)

((Total number of T2 Hall units) equal to 0) And (Total number of T3 Hall units) equal to 0)

Obviously, set T2 Hall and T3 Hall with the buildings you have for Tier 2 Hall and Tier 3 Hall.

** These are the starting units for the AI, so change them with EXACTLY the same units this AI must have at the map init. And, this way, if those workers are killed, they'll be trained by the hall with an active mine, in this way the AI is more efficient.

*** Remember, this only if you don't want them to continue training Footmen when they have Spellbreakers and then Knights

**** In the case of a custom hall, maybe it's better to add a condition: (unless you want them to have a T2 Hall and a T3 in their base at the same time)

(Total number of T3 Hall units) equal to 0)

***** Here you may think: "What the hell can I do with 6 food?" You're wrong, if you used the Hall condition, you have 16 food avaiable now, also if AI Editor tells you the opposite.

****** When The food needed for the queue exceeds the food created by the AI the lines are written in red, but don't worry since, as I explained before, the AI Editor is wrong now.


Finally the third page (and the most difficult) is ended, now the fourth, Attacking:
Zoom (requires log in)

The first thing to do is to set Attack Groups, 2 attack groups are needed:

Minimum Attack:
This is the minimum of army that the AI will use, I'd base it this way:

HTML Code:
Unit Type Quantity Conditions Footman 4 - All (Total number of Spellbreaker units completed) minor of 3 Hero - First All None Knight 3 - All (Food produced) Bigger or Equal to 90 Rifleman 4 - All None Spellbreaker 3 - All (Food produced) Bigger or Equal to 60

All Units:
In this group you'll put all the units avaiable for the race

Attack Waves:
Put as a first wave "Minimum Attack", with a delay of 2, then put "All Units" as a second wave, with a delay of 0.

Minimum Forces:
Set the "Minimum Attack" attack group in this field.

Target Priorities:
Set them this way:
HTML Code:
Target Conditions Common Alliance Target None New Expansion Location ((Food Produced) Bigger or equal to 60) and ((Town with a gold mine) Minor or equal to 1)* Enemy - Major Assault Attack Possible Enemy - Expansion Attack Possible Enemy - Any Town Attack Possible Creep Camp (0-9) None Creep Camp (10-100, flyers) None Buy a Goblin Zeppelin (Total number of Goblin Zeppelin units) minor than 1**

* "Why this?" Because this way the AI will always have at least 1 mine and, if you're gonna play as an ally of this AI, won't try to steal every mine YOU clear.

** Not an important priority, if you want, you can also kick it out



After this, this AI Step-by-Step is completed, feel free to use it as a base for your custom AI.

Only one thing: remember to save this AI and then export the ".ai" script, never import the ".wai" file in your map, it works but it contains also the custom object data you used for your AI, so the 90% of its size is useless to the map, import the ".ai" file instead.

Thanks to Sunwarrior25 for the screenshots of the AI Editor.

Edited because: 28-02-10: Fixed a typo and modified the Target Priorities in order to be... better.
Attached Images
File Type: jpg AITut00.JPG (54.6 KB, 376 views)
File Type: jpg AITut01.JPG (77.7 KB, 331 views)
File Type: jpg AITut02.JPG (60.7 KB, 334 views)
File Type: jpg AITut03.JPG (77.0 KB, 341 views)
Projects:Tutorials: Competitive AI Step by Step with AI Editor (Pending)
Resources: [AI Script] Michael Peppers's Melee AI template (Pending)
Michael Peppers is offline   Reply With Quote
Sponsored Links - Login to hide this ad!