Age of Empire II AI Expert System
This is an introduction to the AoE II DE AI Expert System. Most of the information is based on documentation that comes with the game located here:
<Install Location>\AoE2DE\Docs\All
AI Expert System
A rule based system that uses a LISP like script to define a series of rules which are tested to perform various actions by the AI player.
Rules
Rules are if-then-do statements. The predicate can be compounded and the action can be any number of things including a way to disable the rule itself from further processing.
(defrule
(predicate)
=>
(action)
)
- Game parses all rules and does a rule pass, several times a second.
- Rule pass evaluates and executes actions where rule was true
- All rules remain active unless disabled by self.
(defrule
(true)
=>
(disable-self)
)
Facts
The AI Expert systems call these predicates, Facts. There are a lot of in-built facts that can be used to make scripting easier.
Actions
Actions are limited in a sense what a player can do in the game. Most of the actions are predefined as well.
- build a building
- train a unit
- send a chat message
- command a unit
- game command
Defconst
This lets you define constants so the code is more readable instead of having random numbers and strings everywhere.
Load
Helps you modularize the code and include files in the main AI script file. It also lets you load files randomly to build a more versatile AI player.
Preprocessors
C/C++ like preprocessors to conditionally load rules and files.
Conditional loading recognizes four directives:
- #load-if-defined
- #load-if-not-defined
- #else,
- #end-if
system defined symbol list is present in the documentation
Predefined Stuff
- System Defined Constant: Player specific variables populated by the game based on player selection and game settings
- Fact List: predicates to check various aspects of the game
- Action List: actions to be performed by the AI player based on the rules.
- Parameter List: Lists of parameters used in facts and actions.
AI Location
Location where the AI files are kept
<Installed Location>\AoE2DE\resources\_common\ai
File Structure
- One ainame.ai file to make it show up in the game drop down
- One main ainame.per file that contains the main logic
- Optional multiple *.per file to be included in ainame.per for modularity
Continuous Development
- Open the game and select you ai from the drop down as one of the player
- Add more player and set game properties as per the AI development goal
- Start the game and monitor
- Tab out of the game. Do not stop the game!
- Use a text editor to edit script
- Tab back into the game.
- Use the game menu to restart the game.
Challenge
I am building an AI to play a custom scenario game that I myself play a lot just for fun. I call it Army Rush, 500 Pop, post-Imperial, all visible game with infinite resources played in Amazon Tunnel against five players. I have won with selected civs against Moderate AI. The goal is to see if I can create an AI which can handle Hard or Extreme AIs.