You must be logged in to post messages.
Please login or register

The University

Hop to:    
loginhomeregisterhelprules
Bottom
Topic Subject: AI Scripting Guide: The World of AI Scripting (Approved)
« Previous Page  1 2  Next Page »
posted 11-06-09 07:44 PM CT (US)   
This article has been approved and can also be read at the University. - Luke

I am writing a comprehensive guide for AI scripting to encourage people to start AI scripting. This is only the first section. I will be adding to it periodically, so the actual guide will probably be much longer. I may split it up into separate guides if you all think it will be too long for one guide. It is aimed at an audience who is completely new to AI scripting or has only downloaded AI's.

Luke, If this gets submitted to the University on the main page (hopefully), please title it "The World of AI Scripting". Also, this guide is written to help others gain interest in AI scripting, so if you could help publicize this that would help out a lot. AI scripting needs to be revived! So now, onto the guide.

Here's the guide:



The World of AI Scripting:
By Leif Ericson


Chapter 1:


Prologue (Purpose):

In my opinion, far too few people know the power and enjoyment of AI scripting. Many of us have had the experience of playing against a powerful AI, but often we don’t even think of making our own. This guide is written to encourage you to throw away your misconceptions about AI and to reveal the true wonders of the world of AI scripting. I invite you to get your feet wet, to explore the wonders that AI can do for you, as a gamer, as a scenario designer, and as an Age of Kings enthusiast, so that your experience of Age of Empires II may be complete and fully enjoyable. The rest of us AI invite you to join us. Welcome to the world of AI scripting.

Introduction:

Welcome. You are about to join the thousands of people throughout the years who have experienced the joy of AI scripting. Those of you still out there who are unlucky enough to have not discovered this world, now is the time! The satisfaction of writing your own AI is far greater than designing your own scenarios. Now, let us jump in and I will show you all you need to get started with your first AI!

What are AI’s???

AI stands for Artificial Intelligence. The computer player uses AI files to tell it how to play the game. Now, before you get discouraged, let me dispel one common myth: AI scripting is not hard to understand. For many of us, the words “artificial intelligence” conjures up the image of thousands of lines of complex code that no one except a computer geek understands. AI scripting for The Conquerors is actually quite simple once you learn how. That is why I am here to teach you.

________________________________________________End of Section_____________________________________________

Section 1: What Do I Need?

First, we need to create our AI scripting toolbox. Here are the tools you need:

  • The CPSB (Computer Player Strategy Builder Guide) – you can find this by going to My Computer, right-clicking on The Conquerors icon, clicking open on the right-click menu, and opening the DOCS folder. This was the AI scripting guide that came with the game. Use it as a reference if you ever get stuck.


  • Notepad or WordPad - (Microsoft Word or other similar programs that have spell-check will think the codes in your AI are misspelled words and put an annoying squiggly line under your entire code, so I prefer to use Notepad or Wordpad). There is another text editor called AI Edit that is more geared towards AI scripting.


  • The SAMPLEAI – you can find this by going to My Computer, right clicking on The Conquerors icon, clicking open on the right-click menu, and opening the Goodies folder. This is a small AI that shows you the real basics, so I don’t encourage you to use it as a base for your AI, although you can look at it to get ideas.


  • So, now that our toolbox is ready, let’s put our hard hats on and head to work!

    ________________________________________________End of Section_____________________________________________

    Section 2: Your first rule (finally!):

    This guide is organized into sections. From now on, any code in bold print, except for headings, is code that you should put into your AI. Also, at the end of each section I will put a tip or note to wrap up the section. Now, onto AI scripting!

    First, let's talk about rules. Rules form the basis for every AI. The basic logic for rules is as follows: “if this is true, then do this”.

    Most rules follow this format:

    (defrule ;This starts the rule. Defrule is short for “define rule”.
    (fact 1) ;This is the “if” part of the rule. The AI checks if these facts
    (fact 2) ;are true. If all the facts are true then the AI continues onto the
    (fact 3) ;actions. Not all rules have 3 facts, but all have at least one.

    => ;This is the “then” part of the rule.
    (action 1)
    (action 2) ;If all the facts are true then these actions occur. Not all
    (action 3) ;rules have three actions, but all have at least one.

    ) ;this parenthesis ends the rule

    ……

    Now, let’s write our first rule. First open Notepad or whatever you’re typing up your AI with and type this rule:

    (defrule
    (unit-type-count villager => 0)
    =>
    (chat-local-to-self "I just made my first rule!!!!")
    )


    So, this rule checks to see if the AI has greater than 0 villagers. If it does then it sends a message to itself saying “I just made my first rule!!!!”.

    So, now that you know what rules, defrule commands, facts, and actions are, let me tell you a little bit more about rules. First, you can have more than one fact and/or more than one action in a rule, though you must have at least one of each in a rule.

    Also, you may have noticed that I used parentheses. In AI’s, almost everything is enclosed in parentheses, including facts, actions, and even the rules themselves. If you forget a parenthesis around one of your facts, actions, or rules you will get an error and the AI will not work. So watch for those parentheses.

    Also, many commands will use hyphens between words. I will explain this later.


    ________________________________________________End of Section_____________________________________________

    Section 3: Testing your AI

    Now, you’re probably eager to test out your rule. First, you need to save your AI. When you’ve chosen a name, type in the name and put a .per extension on the end of it. All AI’s are saved in the AI folder (go to My Computer/Local Disk (C)/Program Files/Microsoft Games/Age of Empires II/AI), so make sure you navigate to this folder before you save it.

    Next open up a new document and this blank document with the same name as your AI but with an .ai extension instead of a .per extension.

    So, the names of your two files could be:
  • My First AI.per
  • My First AI.ai

    The .per file includes all the code that the game reads. However, the game needs the .ai file to be able to open the AI file. So, every AI file you create will need two files, one with a .per extension and one with an .ai extension.

    Now, to see your AI at work, open up Age of Empires and get ready to start a random map game. To get your AI to play in the random map game, click on the arrow box to the left of your player file, and select the name of your AI.

    Screenshot

    Then, start the game, and watch the AI yell its message out.


    My AI isn't working!

    If your AI has an error in it a window will come up that looks like this. If no window pops up that means your AI is error free (horray!).

    The first line says which player has the error. Since player 1 has the error, something is wrong with the AI for player 1.

    The second line says what the AI file is that has the error (in this case My First Ai.per).

    The third line is the most useful. It will tell you which line the error is on, what type of error it is (more on that later), and it will show the words or symbols that are giving you the error.

    In this case, I put pillager in my AI in line 2 instead of villager, so I can edit my AI, save it, and restart the game and see if that fixed it.

    If you can't find your error go through these steps:

    1. Make sure your AI looks exactly like this: (copy it if you need to, but I would rather you typed it)

    (defrule
    (unit-type-count villager > 0)
    =>
    (chat-to-all "I just made my first rule!!!!")
    )

    2. Make sure you saved both a .per and an .ai file under the same name, and make sure they are saved in the AI folder.

    3. When setting up the random map game, choose all the game settings before you select the AI from the list.



    If you're using AI Edit, anything that is misspelled will show up in a green color. This allows you to see errors quickly, although it won't change colors if it's missing parentheses.

    ……

    You just made your first rule. Congratulations!


    The disable-self action

    Now, one thing that probably bugged you was that your message kept displaying over and over and over and over and over… To stop this rule from repeating you can add a disable-self action at the end of your rule before the last parenthesis. Whenever you place a disable-self action at the end of a rule, the rule will only run once.

    Your rule will look like this with the disable-self command:

    ;The use of the disable-self action

    (defrule
    (unit-type-count villager > 0)
    =>
    (chat-to-all "I just made my first rule!!!!")
    (disable-self)
    ;<~~~the disable-self action
    )

    Now, you can save your .per file and test your AI, and it will only send the message once. (Hooray!).

    Note:

    One thing to note is that anything following a semi-colon will not be read by the computer when it runs the AI. This allows scripters to write comments in their AI, for the benefit of the reader. The semi-colon can be placed either at the beginning of a line or in the middle of a line, as shown above.

    Tip:

    Rules cannot consist of more than 16 lines of code; otherwise you will get an error. Now 16 lines of code in one rule may seem a huge amount right now, but some of the rules in more complex AI’s will have at least 12 lines in each of them!

    Also, you can have a maximum of 999 rules in an AI, a number you will not likely reach at this point, but it’s a good thing to know.:)

    ________________________________________________End of Section_____________________________________________

    Section 4: Your first AI script

    Now the ability for an AI to chat is great, but your AI needs to be able to do more than just chat. These next rules will guide your AI through the Dark Age, the first step to making a great AI. Add these rules to the AI you made in Section 2.

    Before this, I want you to think of your own playing style. Your first AI should try to implement your style of play. How many villagers do you make in the Dark Age? Do you rush in the Feudal Age or boom to the Castle Age? What armies do you use? These are some example questions to think about when writing your AI. The rules I will give you will only form the base of your AI. Once you become comfortable with AI scripting feel free to make any changes to your AI or add new rules to it. My playing style will be different from yours, so my AI will not be the same as yours.

    First Rule: Building Houses

    However, I believe you and I will both agree that the first thing you do is build a house, unless you’re Huns. You could use this rule below to build a house:

    (defrule
    (can-build house)
    =>
    (build house)
    )

    However, this rule would be inefficient because the AI would build a house whenever it could, causing the AI to have an excess of houses and wasting labor and resources. Often in rules you will add more criteria (facts) to make your AI more efficient. Here is a better rule to use: (add this rule to your AI)

    (defrule
    (can-build house)
    (housing-headroom < 4)
    ;the difference between the current population and supportable population (not the
    ;amount of population houses support)
    (population-headroom > 3) ;the difference between the current population and the population limit
    =>
    (build house)
    )


    Housing-headroom and population-headroom make the AI more efficient. Checking to see if the housing headroom is less than 4 will make sure that the AI is running out of population room before it builds a house. Checking the population headroom will make sure that the AI won’t keep building houses when the AI is very close to the population limit. You don’t want your AI ending up with 100 houses because you forgot to check the population headroom!

    Next Rule: Training Villagers

    The next thing you want your AI to do is train villagers. You always want to train villagers constantly in the Dark Age. Here is a good rule to train villagers:

    (defrule
    (current-age == dark-age)
    (unit-type-count-total villager < 30)
    (can-train villager)
    =>
    (train villager)
    )


    You can change the number of villagers you want to make to any number. However, the best number of Dark Age villagers for AI’s is usually between 25 and 32, depending on its feudal age strategy.

    Building the Mill:

    After you train your villagers, the next step is to build your mill. In AI, there is a nifty fact called “resource-found”, which will detect whether a specified resource is found. This fact is especially useful when building drop-off buildings. Here is a good rule to build mills.

    By the way, this rule will not work if the AI is Huns. Why? This is because it tries to make sure a house is built before it builds its mill. Obviously, Huns will never have a house, therefore this rule will not run. As you get more experienced in scripting, you have to think about things like this.

    (defrule
    (building-type-count-total house > 0) ; We want to build a house before a mill
    (building-type-count-total mill == 0) ; Prevents the construction of multiple mills
    (resource-found food) ; Builds a mill only if forage bushes or deer is found
    (can-build mill)
    =>
    (build mill)
    )


    Building the Lumber Camp:

    The rule for building lumber camps is similar to those for building mills. We use the resource-found rule again, this time for wood. Usually we want our lumber camp built after the mill, so we add a fact to make sure a mill is built first.

    (defrule
    (building-type-count-total mill > 0)
    (building-type-count-total lumber-camp == 0)
    (resource-found wood)
    (can-build lumber-camp)
    =>
    (build lumber-camp)
    )


    Building Farms:

    Farms are a very important building for AI’s. AI’s cannot hunt boar and they have difficulties hunting deer, so an AI will want to make farms sooner. It will want to have enough farms so that almost all their foragers will be able to transfer to farms when the forage bushes are exhausted. One handy fact for building farms is the “idle-farm-count” fact, which checks how many farms are idle (pretty much self-explanatory). It’s useful to make sure the AI doesn’t build too many farms that don’t have any farmers on them.

    (defrule
    (current-age == dark-age)
    (building-type-count-total lumber-camp > 0) ; We want a lumber camp before farms
    (unit-type-count-total villager > 15)
    (building-type-count-total farm < 15)
    (idle-farm-count < 4) ; Only build farms if there are less than 4 idle farms
    (build farm)
    )


    Advancing to the Feudal Age!

    Our first AI is ready to advance to the Feudal Age! We want the AI to advance when it is done training villagers, and we want to make sure it has the buildings it needs.

    (defrule
    (current-age == dark-age)
    (building-type-count-total mill > 0)
    (building-type-count-total lumber-camp > 0)
    (unit-type-count-total villager >= 30) ; If you changed the number of villagers it trains, modify this number
    (can-research feudal-age)
    =>
    (research feudal-age)
    (chat-local-to-self "Feudal Age, here we come!")
    )




    Strategic Numbers:

    However, before we test the AI, there is something we have to add to the AI: strategic numbers (sometimes abbreviated SN’s). I’ll explain strategic numbers in more detail later, but for now it will suffice to say that strategic numbers affect the behavior of the AI. For example, without these strategic numbers, some villagers will explore instead of gathering resources or constructing buildings. I'll explain them briefly for now.

    (defrule
    (true)
    =>
    (set-strategic-number sn-percent-civilian-gatherers 50)
    (set-strategic-number sn-percent-civilian-explorers 0)
    (set-strategic-number sn-percent-civilian-builders 50)
    )


    These strategic numbers specify what percentage of your villagers are gatherers, explorers, or builders. So, ideally, 50 percent of our villagers will gather resources and 50 percent of our villagers will build buildings. Usually, we don’t want villagers to explore because they wouldn’t be gathering resources. There are times when we want villagers to explore - for example, if the AI can’t find its forage bushes - but we’ll take care of that later.

    One thing to note is that while 50 percent of our villagers are specified as builders, there won’t always be half of the villagers constructing buildings. If there aren’t any buildings to be built, the AI is smart enough to tell those builders to gather resources.

    However, when the time comes to construct many buildings we want to have a large number of builders, because AI’s are slow at constructing buildings. AI’s only use one villager per building, and they will only build one of each type of building at a time. For example, the AI will only build one farm at a time instead of three, though it can send another villager to build a mining camp while the farm is being built.

    Here’s some more useful strategic numbers:

    (defrule
    (true)
    =>
    (set-strategic-number sn-minimum-civilian-explorers 0)
    (set-strategic-number sn-cap-civilian-explorers 0)
    (set-strategic-number sn-total-number-explorers 1)
    (set-strategic-number sn-number-explore-groups 1)
    (set-strategic-number sn-initial-exploration-required 0)
    (disable-self)
    )


    These strategic numbers tell the AI how to explore. The first strategic number (SN) tells the AI the smallest amount of civilians (villagers, trade carts, etc.) the AI can use for exploring. Right now we want 0 villagers exploring. The second SN gives the cap or the maximum of civilian explorers the AI can use. We’ll set this to 0. The third SN gives the total number of explorers (both civilians and military units) the AI can use We only want one unit - the scout cavalry or eagle warrior - to explore, so we’ll set this to 1.

    The third SN gives the number of groups for explorers. This needs to be set to the total number of explorers. Originally, I believe Ensemble Studios intended the AI to be able to have two or more soldiers to be able to explore in a group, but they must have scrapped the idea for practical reasons. So now, AI’s will only use one soldier per exploring group, so matter what value you give this SN.

    The last SN tells the percentage of the map that the AI has to explore before it builds buildings. We can set this to zero to allow it to build buildings immediately.

    ;(Last Rule!!!)

    (defrule
    (current-age == dark-age)
    =>
    (set-strategic-number sn-food-gatherer-percentage 60)
    (set-strategic-number sn-wood-gatherer-percentage 40)
    (set-strategic-number sn-gold-gatherer-percentage 0)
    (set-strategic-number sn-stone-gatherer-percentage 0)
    )


    These strategic numbers set how many villagers are assigned to each resource. So, 60 percent of villagers will gather food and 40 percent will gather wood. We don’t want the AI to gather gold or stone until later. These percentages will usually get an AI through the Dark Age pretty well, but most AI’s will tweak them throughout the Dark Age. I’ll show you how to do this in my next guide.


    Dark Age is finished!

    Congratulations! You just made your first AI gather resources, construct buildings, and advance to the Feudal Age. You’re well on your way to becoming an AI scripter. In later sections, we will modify this code to make it faster or more efficient.

    I encourage you to experiment with different numbers and test out your AI. Add some new rules, change some numbers, add more facts to the rules, and just have fun and experiment. This is a great way to learn how to make your AI more efficient and also it gives your AI more of a personality. If you have time, you can read the CPSB and learn more facts and actions that you can use.

    When editing your AI, there is a shortcut so you don't have to close out of the game to edit your AI. You can press alt-tab or the start menu key to minimize the game, then make changes to your AI, then maximize the game, and restart the random map game you were previously testing your AI on. This is much faster and easier than opening and exiting the game every time!

    Extra Challenge:

    Try creating code to make the AI to build a barracks. Hint: remember the “can-build” fact and the “build” action. Also, to make it more efficient, add facts to check if it has built a lumber camp before it builds the barracks.

    Note:

    In AI scripting, symbols such as > (greater-than), < (less-than), or == (equal) are called relative operators ("rel-op" for short). Other symbols you can use are >= (greater-or-equal), <= (less-or-equal), or != (not-equal). This will be important when I teach you syntax of facts and actions. However, make sure you use two equals signs (==) when you want to say “equal”. Using one equals sign (=) will give you an error)!

    Tip:

    The AI runs the code from top to bottom. So, the first rule it looks at in our AI is the rule that chats “I just made my first rule.” Sometimes, if a rule is deeply buried in an AI, the AI won’t be able get down that far and the rule might not run, or it might run after a delay. In the future, the rules that are the most important should go at the top of your AI. So, try moving the advance to Feudal Age rule to the top of your AI, so that this rule will run quicker.

    ________________________________________________End of Chapter_____________________________________________

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´

    [This message has been edited by Leif Ericson (edited 10-16-2010 @ 01:26 AM).]

  • Replies:
    posted 11-06-09 08:04 PM CT (US)     1 / 70  
    Good stuff mate keep it up

    Finally got Skype! rubber-man-1
    posted 11-06-09 09:07 PM CT (US)     2 / 70  
    Hey, good stuff. I'm guessing you want this spread over several pages?

    "Some scientists claim that hydrogen, because it is so plentiful, is the basic building block of the universe. I dispute that.
    I say there is more stupidity than hydrogen, and that is the basic building block of the universe." - Frank Zappa

    Age of Kings Heaven · Outside Discussions
    posted 11-06-09 09:40 PM CT (US)     3 / 70  
    Yes, whatever makes it display the best. Try making the page changes when it says "End of Section". This guide (Chapter 1) is the first of many guides that I will be making, so there will be more of these in the future. It would be great if people were told about this so that we can get some more interest in AI scripting.

    By the way, take out the first few paragraphs. Start it when it says:
    The World of AI Scripting


    Glad you like it. Happy Playing.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´

    [This message has been edited by Leif Ericson (edited 11-07-2009 @ 12:03 PM).]

    posted 11-18-09 02:36 AM CT (US)     4 / 70  
    Hey Luke, it seems like it's been a while since you've looked at it. I was wondering if you we're still considering adding it to the official University. I don't want to press you for time, but I just wanted to know what your plans were for this.

    By the way, I'm going to make some changes to this in a few days, so that'll give you some extra time I suppose.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 11-19-09 00:48 AM CT (US)     5 / 70  
    Oh yeah, it's definately still on the list.

    Can you drop an "updated" somewhere in the main post so I'll know you're done with your changes?

    "Some scientists claim that hydrogen, because it is so plentiful, is the basic building block of the universe. I dispute that.
    I say there is more stupidity than hydrogen, and that is the basic building block of the universe." - Frank Zappa

    Age of Kings Heaven · Outside Discussions
    posted 11-19-09 03:10 AM CT (US)     6 / 70  
    Updated!

    Thanks for letting me know that this is on your list. If you add this to the official University erase everything until the title. Also, just use "The World of AI Scripting" as the name of the guide, not "AI Scripting Guide: The World of AI Scripting".

    By the way, I just wanted to remind you that I plan for this to be the first of a series of guides, so if you have any questions about it all just ask me.

    P.S.: Great job with the University. It's a great place to learn new things.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 11-21-09 11:03 PM CT (US)     7 / 70  
    Hey Leif, it's up. A few notes from me:

    - I couldn't retrieve the first linked image in your article. Mind uploading that one again?
    - I kept the entire article on one page for now. Is that okay with you, or do you really want it spread over multiple pages?
    - Can you run through the article and check the formatting? If there's stuff you want changed, just leave your notes here.
    - Would it be an idea to link to Stoyan Ratchev's AI Editor? Since it has error checking, it might be useful for beginners.

    "Some scientists claim that hydrogen, because it is so plentiful, is the basic building block of the universe. I dispute that.
    I say there is more stupidity than hydrogen, and that is the basic building block of the universe." - Frank Zappa

    Age of Kings Heaven · Outside Discussions
    posted 11-22-09 02:50 AM CT (US)     8 / 70  
    Here's the link. I also fixed it in the guide.

    I think it looks pretty good on one page, so don't feel like you have to make an effort to put it on multiple pages.

    I think it would be better if you put in the section numbers, such as "Section 1: What Do I Need?" instead of just "What Do I Need". This guide and the ones I'm coming up with next are organized into Chapters and Sections, so I think this would make it easier to read. If it is possible to do this that would be great.



    There is one section where the lines word wrap and it makes it hard to read:
    Most rules follow this format:

    (defrule ;This starts the rule. Defrule is short for "define rule".
    (fact 1) ;This is the "if" part of the rule. The AI checks to see if these
    facts
    (fact 2) ;are true. If all the facts are true then the AI continues onto the
    (fact 3) ;actions. Not all rules have 3 facts, but all have at least one.
    ...
    => ;This is the "then" part of the rule.
    (action 1)
    (action 2) ;If all the facts are true then these actions occur. Not all rules
    have
    (action 3) ;three actions, but all have at least one.
    ...
    ) ;this parenthesis ends the rule
    ...
    I've shortened up the comments in the article a little bit so they shouldn't word wrap like this.

    I added a link to AI Edit in the "What Do I Need?" section. I also made some comments on it in "Testing Your AI".

    Otherwise it looks great! Thanks for posting it in the University.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´

    [This message has been edited by Leif Ericson (edited 11-22-2009 @ 03:18 AM).]

    posted 11-22-09 04:00 AM CT (US)     9 / 70  
    There is one section where the lines word wrap and it makes it hard to read:
    Hrm, yeah. I think I might have to come up with a better way to display AI code anyway, so I'll look into that.

    As for the section numbers, sure.

    "Some scientists claim that hydrogen, because it is so plentiful, is the basic building block of the universe. I dispute that.
    I say there is more stupidity than hydrogen, and that is the basic building block of the universe." - Frank Zappa

    Age of Kings Heaven · Outside Discussions
    posted 11-23-09 09:18 AM CT (US)     10 / 70  
    posted 11-23-09 07:31 PM CT (US)     11 / 70  
    Found an error in the houses section:

    (defrule
    (can-build house)
    (housing-headroom < 4) ;the difference between the current population and supportable population (not the
    ;amount of population houses support)
    (population-headroom < 3) ;the difference between the current population and the population limit
    =>
    (build house)
    )



    I changed the less than sign to a greater than sign.

    (defrule
    (can-build house)
    (housing-headroom < 4) ;the difference between the current population and supportable population (not the
    ;amount of population houses support)
    (population-headroom > 3) ;the difference between the current population and the population limit
    =>
    (build house)
    )

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 12-07-09 02:42 AM CT (US)     12 / 70  
    Luke, it has been some time since I last updated this guide. Just kindly checking if you're still working on it. If you're busy with other stuff I understand.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 12-17-09 04:21 AM CT (US)     13 / 70  
    Another week has sailed by. Luke! Where are you?

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 12-23-09 07:59 PM CT (US)     14 / 70  
    hey leif, nice guide , i'm actually thinking of trying to script cause of this.

    i could be wrong, but you might be missing a => for the build farm script.

    anyways, good luck continuing this.
    posted 12-24-09 01:41 AM CT (US)     15 / 70  
    Thanks for the catch White Champion. And thanks for the compliment. I have many things on my plate, but I'm planning on writing chapter 2 in the near future.

    By the way, if you have time, check out the AI Scripting Forum. There's many people who can help you get started with AI scripting.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´

    [This message has been edited by Leif Ericson (edited 12-24-2009 @ 01:42 AM).]

    posted 02-02-10 00:27 AM CT (US)     16 / 70  
    This is a question for the AOKH staff or Luke if he's reading this, but I was wondering why Luke hasn't been very active lately with the University stuff. While it isn't that important, I've been waiting for about three months for an update on this article. I guess either Luke thought it was done, or he hasn't been involved with this site for a while.

    So, if any of you know where Luke is, that would be great!

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 02-02-10 00:58 AM CT (US)     17 / 70  
    Ha, no he is definitely still around. Pretty active, actually. I'll let him know his work here isn't done when I can.

    Signed,
    DaVe.
    posted 02-02-10 01:22 AM CT (US)     18 / 70  
    Thanks, DaVe. I guess he just hasn't been active in this particular forum or he didn't know that he had a project waiting for him.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 02-06-10 10:10 AM CT (US)     19 / 70  
    Apologies for the terribly late reply, but it'll likely be a while before this gets updated - he's got a lot of stuff going on in real life at the moment.

    Hang tight, and it'll get updated eventually.

    - ک

    Ladies and Gentlemen, wear sunscreen. If I could offer you only one tip for the future, sunscreen would be IT. The long term benefits of sunscreen have been proved by scientists, whereas the rest of my advice has no basis more reliable than my own meandering experience.

    This message has been brought to you by procrastination and the letters K and V.
    posted 02-06-10 03:12 PM CT (US)     20 / 70  
    Okay, I'll wait. If he's having problems with real life that is understandable.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 05-18-10 07:45 PM CT (US)     21 / 70  
    My first AI is currently ~400 lines long. It can start smoothly on land maps, even when wood is too far away or berries are absent, as long as there is wood. It is about to enter Feudal.

    I have a ton of questions that tutorials and guide can't answer me clearly. TSA, goals, exploiting civ bonuses, making units choose targets independently and many more. Where can I find answers?
    posted 05-19-10 01:15 AM CT (US)     22 / 70  
    marathon - check out the AI forum here - I'm sure the folks could help you there.

    The University is for submitting and discussing articles.

    Olaf the Tardy ~ ~ ~ ~ T he Laughing Mule
                  (\__/)
                  |^^|-,___,-._,<
                  (o o),|___| \
               _V_v_||_||_||_||_v_v_V
    .sig by Dark_Reign
    posted 05-19-10 05:56 PM CT (US)     23 / 70  
    I'm intending to continue making guides like this, but I have been involved with other things. I'll probably make some more this summer. Until then, feel free to come over to the AI & RMS Scripting forum and ask your questions. We should be able to answer them.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 10-11-10 01:49 PM CT (US)     24 / 70  
    Great guide!! This really got me interested in AI scripting. Can't wait to see the rest of the chapters!

    [This message has been edited by DC20 (edited 10-11-2010 @ 01:49 PM).]

    posted 10-11-10 08:08 PM CT (US)     25 / 70  
    It's been a while since I've written this, and I haven't finished the next chapters, but I do want to finish this. I just can't find time.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 10-14-10 04:50 PM CT (US)     26 / 70  
    Damn, double post I'm really sorry, my internet was weird /:

    ____¯¯ Crusader_7 ¯¯____
    - Proud member of Valkyrie Designs -
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Css stats: http://hlx.vrod.dk/sig.php?player_id=29891&background=random

    [This message has been edited by Crusader_7 (edited 10-14-2010 @ 04:52 PM).]

    posted 10-14-10 04:51 PM CT (US)     27 / 70  
    Hey Leif, great work! It really made me want to give AI scripting a chance I was going to download the AI editor, but I think the host you've used to upload the file has closed or something, because it's not there for download. I might be wrong and I'm really sorry if that's the case, but if you maybe could take a look at it and see if it's true, it would be great! Thanks in advance!

    ____¯¯ Crusader_7 ¯¯____
    - Proud member of Valkyrie Designs -
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Css stats: http://hlx.vrod.dk/sig.php?player_id=29891&background=random
    posted 10-14-10 05:32 PM CT (US)     28 / 70  
    Hey Leif great thread.

    Hopefully ill have the chance to go through it all and learn Ai as its the only thing I havn't really looked at yet.

    Man, one day, I hope...to understand everything about modding, data editing, ai, rms and triggers inside out.

    Oh ps. if u wish to put my modding guide on the university by all means do so. I will update it soon too, busy atmo with other things tho.

    [This message has been edited by Sebastien (edited 10-14-2010 @ 05:34 PM).]

    posted 10-14-10 07:47 PM CT (US)     29 / 70  
    Thanks guys. Feel free to come to the AI and RM Scripting forum if you have questions. Unfortunately, I probably won't be able to work on the next chapter for a while. My free time has nearly been non-existent lately.
    I was going to download the AI editor, but I think the host you've used to upload the file has closed or something, because it's not there for download. I might be wrong and I'm really sorry if that's the case, but if you maybe could take a look at it and see if it's true, it would be great! Thanks in advance!
    I think the link to the AI editor was provided by RubberMan's website, but he had to switch servers. This would explain why the link doesn't work. For now, Notepad could probably work for you. I actually use Notepad myself, not the AI editor. I should probably remove it from the thread.
    Oh ps. if u wish to put my modding guide on the university by all means do so. I will update it soon too, busy atmo with other things tho.
    Okay. Thanks.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 10-15-10 08:42 AM CT (US)     30 / 70  
    Alright, thanks for the quick reply Leif!

    ____¯¯ Crusader_7 ¯¯____
    - Proud member of Valkyrie Designs -
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Css stats: http://hlx.vrod.dk/sig.php?player_id=29891&background=random
    posted 02-04-11 06:29 AM CT (US)     31 / 70  
    This is an amazing guide!
    I started to make my own AI. Since there is no chapter 2 of this guide? I'll learn scripting by reading AllianceThundaEmpire, The Duke-AI version 1.6 and Zycat AI files.

    Advanced Genie Editor
    Follow coding here and here.
    posted 02-05-11 02:59 AM CT (US)     32 / 70  
    Yeah, I'm sorry I never finished Chapter 2. Another really good guide is BearTheGreat's Training AI. You can find it at the Blacksmith.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 06-17-11 09:33 PM CT (US)     33 / 70  
    Making an AI is fairly easy.
    But making a great AI is not so easy.
    And making an AI that can defeat AI's like The Horde and IS_Machine is pretty much impossible! For me anyway...
    I found the SAMPLEAI in the goodies section of the AOE 2 disk really helpful as well as the CPSD document in the Docs folder. In case that's any help.
    posted 08-29-11 10:03 PM CT (US)     34 / 70  
    (defrule
    (current-age == dark-age)
    (building-type-count-total lumber-camp > 0) ; We want a lumber camp before farms
    (unit-type-count-total villager > 15)
    (building-type-count-total farm < 15)
    (idle-farm-count < 4) ; Only build farms if there are less than 4 idle farms
    (build farm)
    )

    should be (defrule
    (current-age == dark-age)
    (building-type-count-total lumber-camp > 0) ; We want a lumber camp before farms
    (unit-type-count-total villager > 15)
    (building-type-count-total farm < 15)
    (idle-farm-count < 4) ; Only build farms if there are less than 4 idle farms
    =>
    (build farm)
    )

    Just saying..
    confused the crap out of me cause I'm a noob took me like 5 mins to figure out lol
    posted 11-28-11 00:06 AM CT (US)     35 / 70  
    This got me into AI scripting, will you ever write more?

    Man, Dann, you sure did wipe the... flor... with him on that one! BAM! OOO! ~ Aro
    posted 11-28-11 01:21 AM CT (US)     36 / 70  
    Yes, although I have numerous projects I'm working on. However, I really mean to expand on these and provide a good set of scripting guides. I just have to find time.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 11-30-11 11:19 PM CT (US)     37 / 70  
    I am having trouble when trying to test my AI. It comes up with an error that says it has trouble opening the .per file. I think it's because it's saved as a .per.txt. How can I get it to be saved as just a .per file?

    Man, Dann, you sure did wipe the... flor... with him on that one! BAM! OOO! ~ Aro
    posted 12-01-11 00:06 AM CT (US)     38 / 70  
    I occasionally had issues with Notepad on this. I can't remember why, but I think it was often because I goofed up the saving process. You can try changing the document save type to All Files instead of text documents and see if that works. If not, just copy the file's AI code into a fresh Notepad document. When you save it, I think saving it as a text document should work, so don't bother changing it. Just save it as filename.per.

    Basically, try all the different combinations, using a fresh Notepad document each time, until it works. I use Notepad++ now, so I haven't used Notepad recently.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 04-05-12 09:13 AM CT (US)     39 / 70  
    When i tried typing in the rules for training militia and researching loom. An error message came up saying it couldn't identify 'militia' and 'loom'.
    posted 04-05-12 11:43 AM CT (US)     40 / 70  
    Militia needs to be militiaman. I know it's weird, but that's what it is.

    All technologies and researches have to have an ri- prefix. So you should use (research ri-loom) instead of (research loom). The prefix is used to make a difference between units and technologies so the engine doesn't get confused, such as long swordsmen and the long swordsmen upgrade.

    I'd recommend you take a read through the CPSB document I talked about if you have time. It can help you know what all these commands have to be.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 04-05-12 03:12 PM CT (US)     41 / 70  
    i can't find it

    which folder is it in?

    can't find the GOODIES or the DOCS folders either

    "you can find this by going to My Computer, right-clicking on The Conquerors icon, clicking open on the right-click menu, and opening the DOCS folder."
    Where is the conquerors icon in my computer?
    Or do you mean the conquerors folder?

    [This message has been edited by Slave25000 (edited 04-05-2012 @ 03:19 PM).]

    posted 04-05-12 09:48 PM CT (US)     42 / 70  
    The file is on the CD itself, not the Age of Empires II folder on your hard drive. So, you have to find it just like a file on a data CD or flash drive. If you have the game CD in your CD drive, you can open the files on the CD as I mentioned in the guide.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 04-06-12 03:23 AM CT (US)     43 / 70  
    thanks
    posted 04-06-12 03:28 AM CT (US)     44 / 70  
    No problem.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 04-06-12 06:13 AM CT (US)     45 / 70  
    one more thing though:
    How do i stop military units wander around aimlessly like headless chickens when created? They aren't exploring just walking, then they stop, then again, the stop, and so on. Until they arrive at an enemy town and just start attacking villagers for no reason (<- i don't have a problem with that) BUT then they follow the villagers to the enemy TC full of villagers and try to destroy it single handedly.
    posted 04-06-12 02:34 PM CT (US)     46 / 70  
    In the strategic numbers section add this line:

    (set-strategic-number sn-task-ungrouped-soldiers 0)

    The default is set to one, which enables the weird exploring behavior.

    I invite you to come to the AI Scripting Forum. That section of the site is devoted to discussing scripting, and there's a lot more people who can help you out as well.

    ~`o´~|\  Join the fresh and exciting AI Ladder for its fourth season!
    ´ `  |_\
           |    Learn the joy of AI scripting in my guide: The World of AI Scripting
    ______|______
     \        /
       .....Hinga Dinga Durgen! - SpongeBob
      `-=<.__.>=-´
    posted 03-19-13 10:15 PM CT (US)     47 / 70  
    Don't know if anyone still looks at this forum anymore, but when I try to save my AIs in the correct folder (I can say with absolute certainty it's the right one) I get a message saying that I need permission from "the administrator" to save in that folder.

    Can someone tell me what I need to do to save my AIs?
    posted 03-20-13 01:17 AM CT (US)     48 / 70  
    Looks like you are trying to save from within Notepad or your text editor, which was launched without administrator rights.

    That's a new Windows feature. If you do have administrator privileges, you can save your AI file on your Desktop, then copy the file from there to the AI folder. It will ask for your permission and then save it.

    Of course, if your user account does not have administrator rights, you can't do much about it except ask the administrator. Alternatively, you can install/copy AoK into another place (e.g. the Desktop, your Documents folder, or another drive), which will give you full access rights to all folders.

    Hope this helps.

    Tales of Middle-Earth | Don't miss it
    posted 04-01-13 11:05 AM CT (US)     49 / 70  
    Hello, very good guide, but I have a question. So, I'm making Lithuania now and I don't really care if the computer player plays it too well, so I decided to copy-paste the AI from someone else (possibly Vikings or Celts). All I need is making the AI build the 2 unique units I made (a lancer in the stable and an axeman in the castle) and sending them to battle. Thanks in advance.

    Also, once my mod is finished, I'll publish it It's a mod for AoFE that adds Lithuanians, I tried to keep the quality as high as possible, and everything balanced.
    posted 05-02-13 10:08 PM CT (US)     50 / 70  
    Hi everyone! This is going to sound like an absolutely awful question but I am totally confused on something. Your first screenshot of you selecting the ai player file from under your player name, I don't have that on my game? I have the conqueror's expansion. I'm not sure what's different on my game. Everything on the screen looks the same as that screenshot except i do not have the option of selecting a different player file for me or for the computer players. Thank you in advance. And sorry, I'm a noob:P
    « Previous Page  1 2  Next Page »
    Age of Kings Heaven » Forums » The University » AI Scripting Guide: The World of AI Scripting (Approved)
    Top
    You must be logged in to post messages.
    Please login or register
    Hop to:    
    Age of Kings Heaven | HeavenGames