First Steps in Game AI: Your Own Bot
By ai-depot | June 30, 2002
Possible Approaches
As you may expect, there are multiple ways of getting your own bots into a game. Each has its advantages and disadvantages, which are listed below. Your first task should be to ascertain what exactly you want to do with your bots, and decide what approach to use.
Server Side
Some first person shooters include the ability to modify the game itself, allowing anyone to create their own “mod”. Often only the most polished multiplayer games allow you to do this, so don’t expect it from any game.
To allow you to modify the code, the company that developed the game usually releases a “Software Development Kit (SDK)”. This allows you to create your own game DLL - a standalone library that is loaded by the main engine. You need to modify the source code provided in order to insert your bots into the game. You’re going to have to wait a few pages before we tackle this issue in more detail, so keep your panties on!
Advantages
Since you’re actually recompiling an important part of the game, the sky is literally your limit!
- Power
You dispose of direct access to the main engine via the interface. - Flexibility
All aspects of the game behaviour can be tweaked at will.
Disadvantages
Since you’re actually recompiling an important part of the game, everything can go drastically wrong!
- Accessibility
Modifying existing code can be overwhelming at first. - Fault Tolerance
Any bug or mistake will usually cause the server to crash.
Game Interface
In some cases, the game is still controlled by a custom DLL, but the code may not be available to you. This implies that you cannot modify it at all, so you cannot tweak that to insert your bot into the game.
A solution involves having an intermediate DLL, which sits between the main engine (EXE) and the game mod (DLL). You’re code is the layer between the two, hence acting as an interface. When you’re DLL is loaded, it in turn loads the game DLL. During normal play, the engine calls to it are passed to the game DLL, and vice-versa. Only when it wants to perform bot AI related tasks does it intercept the calls, and execute its own code.
To do this, you either need to be extremely familiar with windows DLL loading and the game’s internal workings, or you can find someone that has already written a working skeleton. Your task will then be to recompile this skeleton, and insert code where necessary. This will be discussed in following pages.
Advantages
With this approach, you’re code sits in between the two main components of the game. There are many advantages to this:
- Power
Like for the server side solution, you still dispose of direct access to the main engine via the interface. - Simplicity
The skeleton code for the interface DLL is usually quite simple, and you only need to insert a minimal amount of code where needed.
Disadvantages
The interface approach also has its disadvantages.
- Limited Flexibility
You can still tweak the behaviour of the game code indirectly, but doing anything elaborate often gets very complex. - Fault Tolerance
Once again, since you’re an important component of the game, any fatal errors on your part will cause the server to crash. Obviously, since you’re coding a small interface, there are less opportunities for you to go wrong (unlike with a server side approach).
Client Side
The final option for inserting your bots into a game involves modelling the internet multiplayer approach: your bot is a stand-alone program that connects to the main server.
Achieving this involves being able to recognise the server commands, understand them, and reply to them. For some games, there already exist programs that let you do this. All you have to do is write the AI code, and you let the rest of the code handle the server dialogs. Obviously, this makes your task much easier than having to deal with that yourself.
Advantages
Here, your AI is completely independent from the server. This has many benefits:
- Fault Tolerance
If you’re bot crashes, that’s fine. The server will kick it out, and keep on going regardless. - Simplicity
If you base your code on existing libraries, you’ll have very little work to do to start writing AI code. - Independence
You can run your code in separate threads, so a multi-processor machine would benefit. You can also have the bot AI code running on a computer remotely over the network.
Disadvantages
The fact that your code is not directly involved with the game has its downfalls.
- Inflexibility
You cannot tweak the game in any way. The server just sends you facts about the game, and there’s very little you can do about them. - Limited Power
Unless you go through great lengths to find information yourself, you only dispose of data sent to you by the server. 3D queries about the structure of the level are thereby not directly possible.
In Summary
If you want to keep things simple and don’t mind not having limited information, use a client side approach.
If you like the power of being closely linked with the engine, but the code for the game DLL is not available, use the interface approach.
Finally, if there is no sample code available for a game interface and if the code for the game is available, use a fully server side approach.
Tags: none
Category: tutorial |