AI:Hughs global AI tutorial
This is a work in progress.
This page goes step by step through how to create your own global AI.
We'll be writing the AI in C#, because C# is powerful and easy to debug. You'll need a Windows platform with Visual Studio Express 2005 installed.
Note that the C++/C# interface is made available under the GPL licence, so your AI will need to be available under the GPL licence.
Setting up your own AI Project
We're going to use the C# loader dlls from CSAI. We'll get these to run our own AI dll.
- Download CSAI from AI:CSAI, unzip it, and run setup.exe to install it.
In what follows, TASpring in a directory path means the Spring application directory, the one that contains spring.exe.
First, we need to create a loader dll "myailoader.dll", that will load our AI dll.
- Copy TASpring\AI\Bot-libs\csailoader.dll to TASpring\AI\Bot-libs\myailoader.dll
- Copy TASpring\AI\Bot-libs\csailoader.xml to TASpring\AI\Bot-libs\myailoader.xml
- Open TASpring\AI\Bot-libs\myailoader.xml in notepad, and change the value csaidirectory to "AI/myai", then save the file
- Create a new directory TASpring\AI\myai
- For now, copy TASpring\AI\CSAI\csai.dll and TASpring\AI\CSAI\csai.pdb into the TASpring\AI\myai directory.
AI\myai is where we'll be placing our own AI dll. For now we've copied the csai dll into it to check that the loader xml is configured correctly.
Check this is working ok:
- Create a new multiplayer game
- Do "add bot". Click "reload". You should see "myailoader.dll"
- Select "myaialoader.dll" and do ok
- Do "add bot" and add "emptyai.dll". This gives you a dummy opponent so you can spectate
- Click "Spectate" and launch the game
- Check that the game starts and that the commanders appear
If the game started and the commander appeared, everything is working so far. If you get an error message about a global AI exception, and spring shuts down, recheck the steps above.
Now that we've set up the myailoader.dll , we can create our own AI project.
- Download and unzip template.zip (note to self: add link here)
- Start Visual C# 2005 Express
- Create a new project of type "Class library", called "csai" (note: the name is important)
- Delete the default file "Class1.cs"
- Add the file CSAI.cs and LogFile.cs from the template.zip file
- In the solution explorer, right-click "References", do "Add Reference...", select the "Browse" tab, and add TASpring\CSAIInterfaces.dll
- We want to build as Debug, because this gives better error messages. By default it may build as Release, so:
- Go to "Tools" | "Options..." Navigate to "Projects and Solutions", "General". Select "Show Advanced build configurations", then click "ok"
- Go to "Build" | "Configuration Manager..."
- Set Active solution configuration to "Release", then close the dialog
- Build the solution. It should build with no errors, otherwise check the last few steps
You've created an empty AI dll. We need to check that it build ok.
- Locate the bin\Debug directory in your project directory
- You should see csai.dll, csai.pdb, CSAIInterfaces.dll and CSAIInterfaces.pdb
- Copy csai.dll and csai.pdb into the TASpring\AI\myai directory, overwriting the existing csai.dll and csai.pdb
Create a multiplayer game, add the myailoader.dll and emptyai.dll bots as before, click Spectate and Start
- The game should start and the commander should appear
If the game starts and the commander appears, with no error messages about "Global AI Exception" then everything is working so far. You've created a basic empty AI.