Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   -- Submit A Tutorial -- (http://www.wc3c.net/forumdisplay.php?f=431)
-   -   Competitive AI Step by Step with AI Editor (http://www.wc3c.net/showthread.php?t=104797)

Michael Peppers 03-01-2009 07:05 PM

Competitive AI Step by Step with AI Editor
 
4 Attachment(s)
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

Ranged:
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

---------------------------------------------

FINALLY! The End!

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.

Sunwarrior25 03-08-2009 03:21 AM

Isn't the .wai file automatically created (or imported. one of the two) when you import the .ai file?

Michael Peppers 03-08-2009 03:25 AM

No, the ".wai" file is created only by the AI Editor when you save your AI, it is the AI script + custom data. To have an ".ai" file you have to save first, then use the command "Export Script". (or some similar name)

Though, as I said above, both work, the ".ai" file is space saving... :)

EDIT: Found the best way to get rid of the "Hero Skills" bug, updated the main post!

FURTHER EDIT: Just found out that moyack already did a tutorial like this... :emote_sad:

Sunwarrior25 03-23-2009 09:34 PM

Good point, my bad, turns out the .ai file is imported/created if you import the .wai file. Sorry 'bout that. You were right.

Anyhoo, I made a Custom AI based on my entry for the contest. When I changed the object editor data to include a new spell for the hero (Kyrbi0's "Look Out, Sir!"), it keeps trying to reference the old spell (Howl of Terror). The actual strategy hasn't changed. Any ideas?

EDIT: You could change the tutorial to try to reference a custom race. As far as I know, the AI will automatically use any abilities it has (though I think it might have to be run a few times to get the hang of it). I've also noticed that even if you have 4 computer players with the same exact AI, each on different teams, they'll each behave a little differently.

Michael Peppers 03-23-2009 09:59 PM

Quote:

Originally Posted by Sunwarrior25
Anyhoo, I made a Custom AI based on my entry for the contest. When I changed the object editor data to include a new spell for the hero (Kyrbi0's "Look Out, Sir!"), it keeps trying to reference the old spell (Howl of Terror). The actual strategy hasn't changed. Any ideas?


Was the strategy this?

Quote:

Originally Posted by Recently Added In The Tutorial
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 you tried this and it didn't work, send me a PM with the map and the ".wai" file and I'll give it a check...

Quote:

Originally Posted by Sunwarrior25
EDIT: You could change the tutorial to try to reference a custom race. As far as I know, the AI will automatically use any abilities it has (though I think it might have to be run a few times to get the hang of it). I've also noticed that even if you have 4 computer players with the same exact AI, each on different teams, they'll each behave a little differently.


For the first point I think that referencing to a custom race could cause a little confusion, but maybe I could attach a map to make people see how does it work...

For the second one, the same AI acts differently depending on different in-game situations, creep positions, mines owned, number of units owned etc.
That's a good thing, because it means that the AI won't act always in the same way, so the map won't have a always-the-same boring AI...

Sunwarrior25 03-23-2009 10:38 PM

PM'd. The AI I sent you makes full use of it's race's siege engines, and ignores the caster side of it.

Michael Peppers 03-23-2009 10:45 PM

Quote:

Originally Posted by Sunwarrior25
PM'd. The AI I sent you makes full use of it's race's siege engines, and ignores the caster side of it.


Fixed, I'll send you the files soon on PM. Strangely I only tried the "strategy" and now it works. (I should add that if it doesn't work at the first time, re-trying can give results)

BTW Interesting AI... :emote_thumbup:

Sunwarrior25 03-23-2009 11:06 PM

Thanks :emote_thumbup:

Quote:

I didn't post any screen of the editor because my version is italian so it won't help you much, and it may cause effects like: confusion or learning some italian (both things to avoid XD).
Oh! I can take some screenies of my editor, if you need them. Just say what you'd need.

EDIT: Reppy button won't let me +rep you again

Michael Peppers 03-23-2009 11:10 PM

Quote:

Originally Posted by Sunwarrior25
Thanks :emote_thumbup:

Oh! I can take some screenies of my editor, if you need them. Just say what you'd need.

EDIT: Reppy button won't let me +rep you again


Maybe I could add screens for the first 4 windows, don't worry for the rep, if you do the screens I guess I should rep you XD

EDIT: So, tutorial updated and Reppy sent. :emote_thumbup:

kaime 03-26-2009 12:47 PM

Some handy hints:
1. putting number of unit = number of unit completed as a condition for all your units helps to make sure the building is producing that unit constantly instead of waiting endlessly for the piroties above to be finished

it's better then staggering your units i.e

peasent
footmen
peasent
footmen
peasent
footmen etc

cause what happens if one of your footment gets killed? the ai will try to replace your footmen and delay the production of the peasent.

2. having Creep Camp (0-9) as a first attack piroty will make the ai creap out ALL Creep Camp (0-9) on the map before it attacks the enemy even when you have 100 food. really bad if you face an AI which techs up first gets better units then you then attacks you in one wave wiping out your tier 1 units all in one. Baring in mind your AI doesn't kill it's own units so you end up with loads of footmen at 100 food

3. in the above AI, all uou have to do is make sure you kill enough to make it have less then 10 peasents and it won't build anything else until it replaces it's peasents. Blademaster wind walk haress combined with you're producing units and it's not

Michael Peppers 03-26-2009 01:43 PM

1. That doesn't matter because when the AI has got the barracks will train both peasants and footmen at the same time.
The priority list is not that strict, after the AI has issued the order with the highest priority, will issue all the other possible orders in the list at the same time.

2. For creep camps you're right, I'll probably add some conditions, but normally this AI loses all the footmen above even before arriving to have a Castle, thanks to attacks to creep camps or fights between other AIs, and if it doesn't, 5 Footmen (10 food) is not that great problem, believe me.

3. in this AI you're assuming that the AI can train only a unit at a time... if a Blademaster kills all the peasants, be sure that the AI will train both peasants and footmen/spellbreakers/knights at the same time, depending on existing buildings and on research values etc.

However, thanks for the tips, I'll see what to modify for the 2nd point.

Sunwarrior25 05-21-2009 02:29 AM

I just found out today, that you can add the AI to the map without doing most of the export stuff. Just click 'File > Add to map' and specify what path you want it to be. It'll add the AI to whatever map is open in the WE. Still, if all you need is the .ai file, then just delete the .wai file that appears as normal...

Just thought I'd post that bit of info. It's still a smart Idea to save the map, in case you need to change something later. (I dunno, is it possible to do what I just said in... say... 1.21?)

Michael Peppers 05-24-2009 01:52 PM

Quote:

Originally Posted by Sunwarrior25
I just found out today, that you can add the AI to the map without doing most of the export stuff. Just click 'File > Add to map' and specify what path you want it to be. It'll add the AI to whatever map is open in the WE. Still, if all you need is the .ai file, then just delete the .wai file that appears as normal...

Just thought I'd post that bit of info. It's still a smart Idea to save the map, in case you need to change something later. (I dunno, is it possible to do what I just said in... say... 1.21?)


Ha! I got so accustomed to "no new replies" for this thread that I didn't check it in a while, sorry...

And... funny, I never ever seen that command (yes, it works on 1.21b), but it seems it imports the AI Data (.wai file), so I won't suggest that. If someone wants to use it, it's in the AI Editor anyway. :P

BTW, thanks for the new! :)

Super Secret Message

Don't tell anyone... but I know nobody's gonna review this... xD


Captain Griffen 07-14-2009 12:28 PM

I cannot review this as I have zero knowledge of AI, so I'm going to find someone who does.

Pyrogasm 07-21-2009 02:04 AM

Moyack would know.

So would Archmage Owenalacaster.


All times are GMT. The time now is 05:13 PM.

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services