Have you ever had a dream to build a game AI? Real sophisticated one? Did you wish you had all the other stuff (graphics, sound and runtime) ready so you can focus solely on AI code? Now you can!
Warzone 2100 is a real-time strategy (RTS) game, originally written by Pumpkin software and later released as open source. The game contains c-like scripting language for programming the AI which is everything you could wish for (along with decent graphics and sounds). It is actively being enhanced all the time for better network gaming and other features.
Also, there are many AI people contributing their scripts in dedicated sites. The source code is Win32 VC solution file you can easily load and compile if you like so essentially you have all the control you need to change every aspect of the game.
The implementation of the AI language is using Lex and Yacc for parsing the script. Then, during runtime, every command is being mapped to its equivalent C function with the specific parameters so it will run blazingly fast. take a look at script_parser.y, script_parser.l and especially interpreter.cpp – it’s a real masterpiece!
As with every game, you need to split up your ubber sophisticated AI algorithm/heuristics into chunks that can be processed gradually during every frame processing. This, of course, makes things much more complicated and challenges the debugging of such code.
Take a look at the following event example:
I removed several lines from original code for brevity.
1. Whenever on tank observes dangerous situation, it notifies other tanks (dropBeacon call).
2. If alert is on, gather all tanks around (orderGroupScoutCMD).
3. If the enemy is visible start an attack, otherwise, gather around to defend.
As you can see, this event can be called several times per second and continuously adapt to the current situation and react correctly.
The AI essentially is list of such events – each one for different group of objects (attacking tanks, defending tanks etc.).
RAND is the game
Looking at existing scripts it stroke me how many RAND calls there are in order to avoid beating the computer AI by learning its moves. One example is deciding when you have enough tanks to attack the enemy: the AI rolls up a number between 4-8 and if the number of tanks near the enemy equals this number, the attack begins.
Suppose you get to do it as your day time job, I wonder how much does it take to get used of talking seriously about moving tanks, soldiers and building bases (“you will get a bonus this year for your excellent new heuristic that enables the computer player to find and destroy the player’s bases faster than ever”).
The official site. Get the game installation + code and everything else related to the game:
One of the best AI extensions:
AI Scripting manual