AI:CSAIInterface
CSAI Interface
CSAI Interface makes it possible to build Global AIs for Spring using C# .Net 1.1.
C# runs fast and is easy to debug. In addition, using CSAI Interface makes it possible to dynamically recompile and reload your AI dll in the middle of a game.
You can get CSAI Interface from:
http://manageddreams.com/csai/CSharpAI_20061024.zip
CSAI Interface was written by Hugh Perkins
How to use
- AI:CSAI Please see the CSAI installation instructions for installation instructions; for now these are integrated and identical
- CSAI Build Instructions For now, the build instructions for CSAI and CSAI Interface are integrated and identical
Dynamic dll recompilation and reloading
To dynamically recompile and reload your AI dll in the middle of a game:
- recompile your dll
- in the game say ".reloadai"
You can do this whilst paused if you want.
Note that this only applies to the C# AI dll itself. CSAIInterfaces.dll and CSAILoader.dll require the game to be shut down during recompilation.
dll loading, CSAILoader.dll configuration
CSAILoader.dll searches for a configuration file with the same name (ie CSAILoader.xml), in the same directory. This configuration file defines the C# AI dll to reload. If you want you can name your C# dll mysuperai.dll , as long as you change the name of the dll in the configuration file. You can also change the name of the directory and the name of the main C# dll class.
Be really careful to double-check the name of the dll, directory and class if you change them. Your only warning that something is wrong will be an AI exception when you start the game ;-)
You can rename CSAILoader.dll to anything you like. The dll will look for a configuration file with the same name.
All this means that it is very easy for you to create your own C# AI dlls with your own name, and that it wont conflict with other people's C# AIs.
Note that CSAIInterfaces.dll is immutable, never needs to be renamed.
C# AI base class
Your C# AI needs to have a class that derives from CSharpAI.IGlobalAI
You can see the definition of this interfaces in CSAIInterfaces\IGlobalAI.cs
You will need to ensure that the name of the class specified in your CSAILoader.xml configuration file matches the name and namespace of this class.
If you're unsure, just call this class CSAI, in namespace CSharpAI. Then you won't need to change the configuration file
Creating a C# dll using Visual Studio
- Create a new project of type "class library"
- Add a reference to CSAIInterfaces\CSAIInterfaces.dll
This will automatically configure your project to build as a dll, and make the types from CSAIInterfaces.dll available to your project.