Game AI experiments

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.

Code

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.yscript_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:

Tank defense event code

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.

Seriously?

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”).

Links

The official site. Get the game installation + code and everything else related to the game:

http://wz2100.net/

One of the best AI extensions:

http://sourceforge.net/projects/dydo-ai/

AI Scripting manual

http://developer.wz2100.net/wiki/ScriptingIntroduction http://members.shaw.ca/kgmetcalfe4/artificial%20intelligence/scriptlanguage.html

Advertisements
This entry was posted in AI and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s